How can I tell VCR that I want it to completely ignore a spec file?
I've read a post on Google Groups that suggests either allowing real HTTP requests, or turning VCR off explicitly.
What would be much more usable in my opinion would be for VCR to not stick its nose in unless a spec has the :vcr
metadata tag. I don't want to turn VCR off and back on again in before
/after
, as I don't know if it was on beforehand. I don't want to allow real HTTP requests across all specs, just some particular ones.
Is there any way to make VCR more selective?
This isn't the most elegant solution, but you can use an instance variable to return the configuration to it's original setting
describe "A group of specs where you want to allow http requests" do
before do
VCR.configure do |c|
@previous_allow_http_connections = c.allow_http_connections_when_no_cassette?
c.allow_http_connections_when_no_cassette = true
end
end
after do
VCR.configure do |c|
c.allow_http_connections_when_no_cassette = @previous_allow_http_connections
end
end
# Specs in this block will now allow http requests to be made
end
I've found this helpful for while I'm working to initially get an API up and running, and want to be able to debug the requests that I'm making. Once I've got the API working correctly, I can remove the before and after blocks, and use VCR as normal.
Sure, in your config block add:
VCR.configure do |c|
c.allow_http_connections_when_no_cassette = true
end
This is AFAIK the only option VCR has regarding your test suite. See the docs.
Most likely though you should really be considering the record modes for behavior like this so it's actionable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With