Skip to contents

Contexts

with_mock_api()
Serve a mock API from files
use_mock_api()
Turn on API mocking
with_mock_dir()
Use or create mock files depending on their existence
without_internet()
Make all HTTP requests raise an error
block_requests()
Block HTTP requests
with_fake_http()
Make all HTTP requests return a fake response
stop_mocking()
Turn off request mocking

Expectations

expect_GET() expect_POST() expect_PATCH() expect_PUT() expect_DELETE() expect_no_request()
Expectations for mocked HTTP requests
expect_header()
Test that an HTTP request is made with a header
expect_json_equivalent()
Test that objects would generate equivalent JSON

Recording and redacting responses

capture_requests() start_capturing() stop_capturing()
Record API responses as mock files
redact_cookies() redact_headers() within_body_text() redact_auth()
Remove sensitive content from HTTP responses
gsub_response() gsub_request()
Find and replace within a 'response' or 'request'
set_redactor()
Set a response redactor

Loading mock (recorded) fixtures

.mockPaths()
Set an alternate directory for mock API fixtures
set_requester()
Set a request preprocessor
build_mock_url()
Convert a request to a mock file path
fake_response()
Return something that looks like a 'response'

Vignettes

start_vignette() end_vignette()
Set mocking/capturing state for a vignette
change_state()
Handle a change of server state

Other testing tools

httptest
httptest: A Test Environment for HTTP Requests
use_httptest()
Use 'httptest' in your tests
public()
Test that functions are exported
skip_if_disconnected()
Skip tests that need an internet connection if you don't have one