dnesteryuk / whisperer

Gem for generating dynamically VCR cassettes with Ruby
MIT License
23 stars 1 forks source link

Generate multiple request/response pairs in one VCR cassette #2

Open jeanlange opened 7 years ago

jeanlange commented 7 years ago

I'm using Whisperer to generate cassettes for an API that doesn't exist yet. We're using the cassettes in development to write the UI, and (optionally) when testing to switch our tests back and forth between unit and integration tests.

In my current (manually created) setup, for my 'environment' resource, I have one environments.yml cassette that contains the responses for GET environments as well as GET environments/id_one, GET environments/id_two, etc...

So far, I haven't been able to replicate this with whisperer:

Is what I'm trying to do possible with Whisperer, or should I just be writing a lot of different cassettes and changing my code to talk to different cassettes instead of all calls going through the single environments cassette?

dnesteryuk commented 7 years ago

@jeanlange To be honest, I considered one cassette contains one request/response stub. Doing this way it is easy to swap cassettes:

VCR.use_cassette 'valid_user' do
  VCR.use_cassette 'items' do
    # make a request here
  end
end

# now we want to simulate an invalid user response
VCR.use_cassette 'invalid_valid_user' do
  VCR.use_cassette 'items' do
    # make a request here
  end
end

But, your case is interesting. VCR supports it, hence, the whisperer might support it as well...

A project I worked on contained 10-15 external requests per page, therefore, we decided to split request/response into multiple files in order to swap cassettes when we needed to simulate different test cases. But, we used it with site_prism.vcr, therefore, we didn't have crazy chains with VCR.use_cassette. In your case, it might be harder.

jeanlange commented 7 years ago

But, your case is interesting. VCR supports it, hence, the whisperer might support it as well... - How can we make this happen?

We are using VCR both during development of the UI and in tests, so the .use_cassette calls are in the code, not the tests - so we surround the call for a specific environment with the environments cassette file and get whichever environment we asked for, and are able to test different behavior without having the real API or changing the code. We have shimmed in switches for changing cassettes from our tests to simulate error cases, and I'm going to try to use that framework to get it to work with Whisperer-generated cassettes, but it would be nice if it just did what I wanted ^_^