Get a diff of a stub request body and a request body from an http request
Source:R/stub_body_diff.R
stub_body_diff.Rd
Get a diff of a stub request body and a request body from an http request
Usage
stub_body_diff(stub = last_stub(), request = last_request())
Arguments
- stub
object of class
StubbedRequest
. required. default is to calllast_stub()
, which gets the last stub created- request
object of class
RequestSignature
. required. default is to calllast_request()
, which gets the last stub created
Details
If either stub
or request
are NULL
, this function will
return an error message. You may not intentionally pass in a NULL
, but
the return value of last_stub()
and last_request()
when there's
nothing found is NULL
.
Examples
if (FALSE) { # interactive()
# stops with error if no stub and request
request_registry_clear()
stub_registry_clear()
stub_body_diff()
# Gives diff when there's a stub and request found - however, no request body
stub_request("get", "https://hb.opencpu.org/get")
enable()
library(crul)
HttpClient$new("https://hb.opencpu.org")$get(path = "get")
stub_body_diff()
# Gives diff when there's a stub and request found - with request body
stub_request("post", "https://hb.opencpu.org/post") %>%
wi_th(body = list(apple = "green"))
enable()
library(crul)
HttpClient$new("https://hb.opencpu.org")$post(
path = "post", body = list(apple = "red"))
stub_body_diff()
# Gives diff when there's a stub and request found - with request body
stub_request("post", "https://hb.opencpu.org/post") %>%
wi_th(body = "the quick brown fox")
HttpClient$new("https://hb.opencpu.org")$post(
path = "post", body = "the quick black fox")
stub_body_diff()
}