Response to: http://blog.alexative.com/blog/2013/10/03/turn-vcr-off-for-rspec-example-or-group/
Metadata is inherited. So instances can override a setting from a parent. Ideally, this should work:
RSpec.configure do |c|
# RSpec 3: c.before :example, :vcr do
c.before :each, :vcr do
puts "\n in vcr before each"
# Stuff here
end
end
describe 'Showing metadata behavior', :vcr do
it "inheriting metadata" do
end
it "explicit true", vcr: true do
end
it "explicit false", vcr: false do
end
end
I would normally expect the vcr: false
spec to not run the before
block. However, it does. 😦 This happened for me on 2.14.8 and the current master
branch.
As a workaround, you can check the metadata in the before
block:
RSpec.configure do |c|
# RSpec 3: c.before :example, :vcr do |example|
c.before :each, :vcr do
if example.metadata[:vcr]
puts "\n in vcr before each"
# Stuff here
end
end
end
If you prefer something more explicit, you can use a symbol too:
RSpec.configure do |c|
# RSpec 3: c.before :example, :vcr do |example|
c.before :each, :vcr do
unless example.metadata[:vcr] == :off
puts "\n in vcr before each"
# Stuff here
end
end
end
describe 'Showing metadata behavior', :vcr do
it "explicit off", vcr: :off do
end
end