Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cupakromer/69d3f33d0eb008293406 to your computer and use it in GitHub Desktop.
Save cupakromer/69d3f33d0eb008293406 to your computer and use it in GitHub Desktop.
Turn VCR off

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment