Last Updated: February 25, 2016
·
1.905K
· stuliston

Silence VCR Macro Deprecation Warning

Hopefully this one will save someone 10mins of digging around.

We use the VCR gem on every project at Hooroo and we're very grateful for it.

Recently, the contributors decided to deprecate the 'Macro' syntax for VCR'ing an example in favour of using RSpec's metadata instead.

I read the lengthy issue thread on the matter and, whilst I agree with the author's overall sentiment, it represents a significant API change. One that would take a lot of refactoring on our part to fix all affected specs.

The result is that our spec output is now littered with literally hundreds of messages saying:

WARNING: VCR::RSpec::Macros is deprecated. Use RSpec metadata options instead `:vcr => vcr_options` 

So, if like me you can't yet spare the time to alter every test to use the new API, putting this into your spec_helper.rb file will at least silence the warnings for now:

# add this:
module VCR::RSpec::Macros
  def self.extended(base)
  end
end

# right above the existing:
config.extend(VCR::RSpec::Macros)

This patches the Macros.extended class method which is responsible only for logging the warning. Although monkey-patching like this generally not advisable, it should be safe given the macros are no longer in active development.

If your suite uses the macro syntax as often as ours does, I'm sure you'll find out when they're removed fully!

~ Stu