Skip to contents

stub registry to keep track of StubbedRequest stubs

See also

Public fields

request_stubs

(list) list of request stubs

global_stubs

(list) list of global stubs

Methods


Method print()

print method for the StubRegistry class

Usage

StubRegistry$print(x, ...)

Arguments

x

self

...

ignored


Method register_stub()

Register a stub

Usage

StubRegistry$register_stub(stub)

Arguments

stub

an object of type StubbedRequest

Returns

nothing returned; registers the stub


Method find_stubbed_request()

Find a stubbed request

Usage

StubRegistry$find_stubbed_request(req)

Arguments

req

an object of class RequestSignature

Returns

an object of type StubbedRequest, if matched


Method request_stub_for()

Find a stubbed request

Usage

StubRegistry$request_stub_for(request_signature, count = TRUE)

Arguments

request_signature

an object of class RequestSignature

count

(bool) iterate counter or not. default: TRUE

Returns

logical, 1 or more


Method remove_request_stub()

Remove a stubbed request by matching request signature

Usage

StubRegistry$remove_request_stub(stub)

Arguments

stub

an object of type StubbedRequest

Returns

nothing returned; removes the stub from the registry


Method remove_all_request_stubs()

Remove all request stubs

Usage

StubRegistry$remove_all_request_stubs()

Returns

nothing returned; removes all request stubs


Method is_registered()

Find a stubbed request

Usage

StubRegistry$is_registered(x)

Arguments

x

an object of class RequestSignature

Returns

nothing returned; registers the stub


Method clone()

The objects of this class are cloneable with this method.

Usage

StubRegistry$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) { # \dontrun{
# Make a stub
stub1 <- StubbedRequest$new(method = "get", uri = "api.crossref.org")
stub1$with(headers = list('User-Agent' = 'R'))
stub1$to_return(status = 200, body = "foobar", 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
} # }