A Test Environment for HTTP Requests
Wrap a redacting expression as a proper function
Block HTTP requests
Convert a request to a mock file path
Record API responses as mock files
Handle a change of server state
Test that an HTTP request is made with a header
Test that objects would generate equivalent JSON
Expectations for mocked HTTP requests
Return something that looks like a 'response'
Go through mock paths to find the local mock file location
Fetch the active redacting function
Fetch the active requesting function
Find and replace within a 'response' or 'request'
httptest
: A Test Environment for HTTP Requests
Set an alternate directory for mock API fixtures
Test that functions are exported
Remove sensitive content from HTTP responses
Write out a captured response
Set a response redactor
Set a request preprocessor
Skip tests that need an internet connection if you don't have one
Set mocking/capturing state for a vignette
Turn off request mocking
Use 'httptest' in your tests
Turn on API mocking
Make all HTTP requests return a fake response
Serve a mock API from files
Use or create mock files depending on their existence
Wrapper around 'trace' to untrace when finished
Make all HTTP requests raise an error
Testing and documenting code that communicates with remote servers can be painful. Dealing with authentication, server state, and other complications can make testing seem too costly to bother with. But it doesn't need to be that hard. This package enables one to test all of the logic on the R sides of the API in your package without requiring access to the remote service. Importantly, it provides three contexts that mock the network connection in different ways, as well as testing functions to assert that HTTP requests were---or were not---made. It also allows one to safely record real API responses to use as test fixtures. The ability to save responses and load them offline also enables one to write vignettes and other dynamic documents that can be distributed without access to a live server.
Useful links