Search code examples
ruby-on-railsrubyvcr

uninitialized constant VCR when app run in development environment


I'm using VCR to speed up my tests in my rails app and it works like a charm in the test environments

But when I physically navigate the site in the developement environment I get the error uninitialised constant VCR when ever I get to a

VCR.use_cassette("name") do 
  # http request
end

I can resolve the issue by requiring VCR in my config/application.rb

require 'vcr'

But this does not feel like the correct solution...

Will this not force the app to use cassette's in all my RAILS_ENV's?

I only want to use my VCR cassettes in my test environments not in any of the other environments my app gets run in.

What is the best solution for this?


Solution

  • VCR is intended to only be used in your test environment (though you can, of course, use it in any kind of program as it's not coupled to a test framework in any way). If you use VCR as intended, you should only reference the VCR constant in files loaded in your test environment. You would only get this error if you are loading files in another environment that reference the VCR constant.