Same requests are recorded only once in vcr Show archive.org snapshot . Replaying a test fails, if you trigger the same request multiple times. The error message is somehow confusing, as your cassette contains the request:
An HTTP request has been made that VCR does not know how to handle
If you want to allow to match a request multiple times, you need to configure this explicit with allow_playback_repeats: true. Some example configurations:
# specific cassette only
VCR.use_cassette('example', :allow_playback_repeats => true) do
puts response_body_for(:get, 'http://example.com/foo')
puts response_body_for(:get, 'http://example.com/foo')
puts response_body_for(:get, 'http://example.com/foo')
end
# cucumber only
VCR.cucumber_tags do |t|
t.tag '@vcr',
use_scenario_name: true,
allow_playback_repeats: true
end
# globally
VCR.configure do |config|
config.default_casette_options = { allow_playback_repeats: true }
end
Use this option with caution, as there are many scenarios where the response changes for the same request!
Further reading
If this doesn't help, you might find these topics useful:
Matchers
VCR has different matchers Show archive.org snapshot (:method (default enabled), :uri (default enabled), :body, :headers, :host, :path, :query). If e.g. your params have a different order, this might fail in the comparison of equality:
- VCR: An OAuth-compatible request matcher
- Body with ignored order Show archive.org snapshot
- URI ignoring query parameter ordering 1 Show archive.org snapshot
- URI ignoring query parameter ordering 2 Show archive.org snapshot
Tests with AJAX
Using javascript in integration tests might cause issues that AJAX requests are not recorded or bleed in other scenarios:
Debugging
- Write the debug log of VCR Show archive.org snapshot to a file and check the matches manually. Depending on the number of request made for a cassette this can be quite stressful.
- Compare the cassette with the invalid request Debugging VCR errors caused by randomness