Closed robertdj closed 3 years ago
Just so I understand: you want to make real API requests and then compare the responses with your previously recorded response mocks?
You could do capture_requests()
with the real requests and compare the directory contents to your mock dir. with_mock_dir()
might be convenient here as it uses mocks if they exist and records them if they do not. Something like:
with_mock_dir("existing_api", {
do_stuff()
})
new_api <- tempfile()
with_mock_dir("new_api", {
skip_on_cran() # Since this will make actual HTTP requests
do_stuff()
})
test_that("the API has not changed", {
for (f in dir(test_path("existing_api")) {
# compare `f` with `file.path(new_api, f)`
}
})
Yes, you are spot on :-)
That looks like a good solution -- thanks!
Hi
First: I'm really enjoying this package!
Second: I have question about how I can use the captured requests as part of integration tests. My situation is that I use {httptest} to run fast unit tests with mocked HTTP calls. But (sometimes) I also want to actually make the call and compare the result with the captured request. This has saved at least one regression in the API.
I can see something like this working:
This would some extra lines of code in each integration test, but it seems to me that
save_response
does most of this already. Have I overlooked a feature in {httptest} to do this? If not, would you be interested in such a function?