View source: R/without-internet.R
without_internet | R Documentation |
without_internet
simulates the situation when any network request will
fail, as in when you are without an internet connection. Any HTTP request
through the verb functions in httr
will raise an error.
without_internet(expr)
expr |
Code to run inside the mock context |
The error message raised has a well-defined shape, made of three
elements, separated by space: (1) the request
method (e.g. "GET"); (2) the request URL; and
(3) the request body, if present. The verb-expectation functions,
such as expect_GET()
and expect_POST()
, look for this shape.
The result of expr
block_requests()
to enable mocking on its own (not in a context)
without_internet({
expect_error(
httr::GET("http://httpbin.org/get"),
"GET http://httpbin.org/get"
)
expect_error(httr::PUT("http://httpbin.org/put",
body = '{"a":1}'
),
'PUT http://httpbin.org/put {"a":1}',
fixed = TRUE
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.