I want to be able to record specific requests and have ALL the requests/responses be logged to the SAME file if the URL host is dev1-pb1. See my code below. This code definitely ignores all requests that do NOT have dev1-pb1 as the URI.host. When I make the first RESTful call
, it creates the pb_mock_data file with this request and response in it which I expect. When I make a subsequent request where the model id changes such as
, it throws the error below. I can get it to work creating unique mock files. Please advise! Thanks!
NOTE: Ideally, I would like to have a regex in the mock yaml file where ALL requests matching a pattern the URL. I tried putting a path_regex entry in the mock yaml file, but that didn't resolve the issue. Can this be done?
In an initializer that loads when my ruby app starts, I have the following code:
if FullSite::Application.config.mock_pb_requests == true
VCR.configure do |c|
c.ignore_request do |request|
URI(request.uri).host != 'dev1-pb1'
end
c.allow_http_connections_when_no_cassette = true
c.cassette_library_dir = 'test/mocked_data/pb-client-wrapper'
c.hook_into :webmock
c.around_http_request do |request|
VCR.use_cassette("pb_mock_data", &request)
end
end
end
Error on second request where the model id changes:
An HTTP request has been made that VCR does not know how to handle:
There is currently no cassette in use. There are a few ways
you can configure VCR to handle this request:
* If you're surprised VCR is raising this error
and want insight about how VCR attempted to handle the request,
you can use the debug_logger configuration option to log more details [1].
* If you want VCR to record this request and play it back during future test
runs, you should wrap your test (or this portion of your test) in a
`VCR.use_cassette` block [2].
* If you only want VCR to handle requests made while a cassette is in use,
configure `allow_http_connections_when_no_cassette = true`. VCR will
ignore this request since it is made when there is no cassette [3].
* If you want VCR to ignore this request (and others like it), you can
set an `ignore_request` callback [4].
================================================================================