The mock contexts in httptest can raise errors or messages when requests are made, and those (error) messages have three elements, separated by space: (1) the request method (e.g. "GET"); (2) the request URL; and (3) the request body, if present. These verb-expectation functions look for this message shape. expect_PUT, for instance, looks for a request message that starts with "PUT".

expect_GET(object, url = "", ...)

expect_POST(object, url = "", ...)

expect_PATCH(object, url = "", ...)

expect_PUT(object, url = "", ...)

expect_DELETE(object, url = "")

expect_no_request(object, ...)



Code to execute that may cause an HTTP request


character: the URL you expect a request to be made to. Default is an empty string, meaning that you can just assert that a request is made with a certain method without asserting anything further.


character segments of a request payload you expect to be included in the request body, to be joined together by paste0


A testthat 'expectation'.


library(httr) without_internet({ expect_GET(GET(""), "") expect_PUT(PUT("", body='{"a":1}'), '', '{"a":1}') expect_PUT(PUT("", body='{"a":1}')) expect_no_request(rnorm(5)) })
#> [1] -1.400043517 0.255317055 -2.437263611 -0.005571287 0.621552721