I am looking for the easiest way to mock response of rest API within testthat framework.
Example of usage would be similar to this:
with_mock_api(
request,
response,
{
call_to_function_with_api_call()
# expectations check
}
)
As a result, tests will pass without calling the real API.
requestrefers to the definition of http request that will be done inside of the api wrapper function;responserefers to the response object that has been cached for the purpose of mocking.