httptest4.2.2 package

A Test Environment for HTTP Requests

as-redactor

Wrap a redacting expression as a proper function

block_requests

Block HTTP requests

build_mock_url

Convert a request to a mock file path

capture_requests

Record API responses as mock files

change_state

Handle a change of server state

expect_header

Test that an HTTP request is made with a header

expect_json_equivalent

Test that objects would generate equivalent JSON

expect_verb

Expectations for mocked HTTP requests

fake_response

Return something that looks like a 'response'

find_mock_file

Go through mock paths to find the local mock file location

get_current_redactor

Fetch the active redacting function

get_current_requester

Fetch the active requesting function

gsub_response

Find and replace within a 'response' or 'request'

httptest

httptest: A Test Environment for HTTP Requests

mockPaths

Set an alternate directory for mock API fixtures

public

Test that functions are exported

redact

Remove sensitive content from HTTP responses

save_response

Write out a captured response

set_redactor

Set a response redactor

set_requester

Set a request preprocessor

skip_if_disconnected

Skip tests that need an internet connection if you don't have one

start_vignette

Set mocking/capturing state for a vignette

stop_mocking

Turn off request mocking

use_httptest

Use 'httptest' in your tests

use_mock_api

Turn on API mocking

with_fake_http

Make all HTTP requests return a fake response

with_mock_api

Serve a mock API from files

with_mock_dir

Use or create mock files depending on their existence

with_trace

Wrapper around 'trace' to untrace when finished

without_internet

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.

  • Maintainer: Neal Richardson
  • License: MIT + file LICENSE
  • Last published: 2024-01-23