Learn R Programming

webmockr (version 0.1.0)

StubRegistry: Stub registry

Description

Stub registry

Arguments

Details

Methods
register_stub(stub)
Register a stub - stub: an object of class StubbedRequest
find_stubbed_request(req)
Find a stubbed request - req: an object of class RequestSignature
response_for_request(request_signature)
Find a stubbed request - request_signature: an object of class RequestSignature
request_stub_for(request_signature)
Find a stubbed request - request_signature: an object of class RequestSignature
remove_request_stub(stub)
Remove a stubbed request by matching request signature - stub: an object of class StubbedRequest
remove_all_request_stubs()
Remove all request stubs
is_registered(x)
Find a stubbed request - x: an object of class RequestSignature

See Also

Other stub-registry: remove_request_stub, stub_registry_clear, stub_registry

Examples

Run this code
## Not run: ------------------------------------
# # Make a stub
# stub1 <- StubbedRequest$new(method = "get", uri = "api.crossref.org")
# stub1$with(request_headers = list('User-Agent' = 'R'))
# stub1$to_return(status = 200, body = "foobar", response_headers = list())
# stub1
# 
# # Make another stub
# stub2 <- StubbedRequest$new(method = "get", uri = "api.crossref.org")
# stub2
# 
# # Put both stubs in the stub registry
# reg <- StubRegistry$new()
# reg$register_stub(stub = stub1)
# reg$register_stub(stub = stub2)
# reg
# reg$request_stubs
## ---------------------------------------------

Run the code above in your browser using DataLab