3

I have a ~ 2.5GB collection of VCR cassettes https://github.com/vcr/vcr. I am using version 3.0.1.

I need to re-record the cassettes from time to time. But, since running the tests takes considerably longer than just firing the requests and recording the answer in a cassette, I am searching for a way to only fire the requests that are already recorded and get them re-recorded.

Ideally I would have a rake task that would do this, e.g.:

rake vcr:cassettes:refresh

How should I go about this?

johannesch
  • 125
  • 1
  • 5

1 Answers1

0

What I'm about to suggest won't work for every possible setup (for instance, those wrapping each connection in VCR.use_cassette, or those using VCR middleware with Faraday). But if you happened to set up VCR using configure_rspec_metadata!, like so:

https://www.relishapp.com/vcr/vcr/v/3-0-1/docs/test-frameworks/usage-with-rspec-metadata

...in other words, if every example or example group requiring VCR has :vcr or vcr: true as metadata, then you can run just the VCR-tagged specs on the command line using, for example:

$ rspec ./spec --tag @vcr

The --tag option is documented here.

If you're not using the metadata setup, and there's nothing preventing you from using it, switching to it will likely be faster than coming up with some other way to filter the specs, assuming they're thoroughly mixed in there. It's also makes it more convenient to add new VCR specs. One possible downside is that the cassette names might need to change, but since you're planning to re-record them, that shouldn't matter much.

johncip
  • 2,087
  • 18
  • 24
  • Thanks, but I was looking for a possibility to just fire the requests in the cassettes again and record the responses - without running the actual examples that produced them in the first place. This is to reduce running time. – johannesch Aug 17 '16 at 11:50
  • Ah, sorry. I misread and thought you were talking about the time to run the full suite vs. only the networked specs. For just running VCR without RSpec, you could potentially make your own script to do that, provided you know all of the URLs up front, and don't mind having them in a second place. Something like the one here: https://relishapp.com/vcr/vcr/v/3-0-3/docs/cassettes/automatic-re-recording – johncip Aug 18 '16 at 07:01