Search code examples
rubycucumberintegration-testingvcr

How to allow web requests when using VCR / WebMock?


I'm currently using RSpec2, Cucumber and VCR (via WebMock), and everything's working great.

With VCR normally all requests are recorded and then replayed against the recorded cassettes.

Now I want to allow real web requests in some scenarios:

  • In Cucumber, I've setup a "live" profile which runs any test tagged with @live. For these tests – and these tests only – I'd like to allow real web requests.
  • I want from time to time run the tests against the real api and ignore the recordings

Solution

  • You can do this with cucumber's Before and After hooks. Just disable VCR using something like this:

    Before('@live') do
      VCR.eject_cassette
      VCR.turn_off!
    end
    

    This may be dependent on exactly how you are integrating VCR with your cucumber tests though.