Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use multiple cassettes or merge cassettes #306

Closed
rweng opened this issue Jun 17, 2013 · 6 comments
Closed

use multiple cassettes or merge cassettes #306

rweng opened this issue Jun 17, 2013 · 6 comments

Comments

@rweng
Copy link

rweng commented Jun 17, 2013

Hi,

is there a way to use multiple cassettes at the same time? If not, that would be a feature request.

Thanks,
Robin

@myronmarston
Copy link
Member

You can nest cassettes:

VCR.use_cassette("outer") do
  make_some_http_request

  VCR.use_cassette("inner_1") do
    make_some_other_http_request

    VCR.use_cassette("inner_2") do
      make_yet_another_request
    end
  end
end

When a request is made VCR will search the cassette stack starting at the innermost cassette to find a matching HTTP interaction to replay. It'll record new requests to the innermost cassette.

Does that meet your needs?

@rweng
Copy link
Author

rweng commented Jun 17, 2013

yes, that definitely fits my needs. I would still prefere using rspec metadata for this, like vcr: {cassette_names: %w(fb-login linkedin-login)}.

Anyhow, the issue is resolved for me. Thanks!

@rweng rweng closed this as completed Jun 17, 2013
@myronmarston
Copy link
Member

I would still prefere using rspec metadata for this, like vcr: {cassette_names: %w(fb-login linkedin-login)}.

I can see the appeal of that API, but when a new HTTP request is made, how would it know which cassette to record it to?

@rweng
Copy link
Author

rweng commented Jun 17, 2013

could be the last by convention. Just like nesting use_cassette uses the most inner one by convention. I'd understand it as VCR.use_cassette calls around your test.

@myronmarston
Copy link
Member

could be the last by convention. Just like nesting use_cassette uses the most inner one by convention. I'd understand it as VCR.use_cassette calls around your test.

But then how would the first cassette ever get anything recorded to it?

Explicit nesting is supported because you can make requests at points where only the outer one is inserted (and thus have it get recorded to that cassette):

VCR.use_cassette("outer") do
  # <- requests here get recorded to outer

  VCR.use_cassette("inner") do
    # <- requests here get recorded to inner
  end

  # <- requests here get recorded to outer as well  
end

If VCR automatically inserted two cassettes, w/o giving you a chance to make any requests while just the first one is inserted...then nothing would ever get recorded to it and it would never be used.

@rweng
Copy link
Author

rweng commented Jun 29, 2013

fair enough. I guess that comes down to user behavior. Since I usually use record: :none to ensure that I know what I am recording, this wouldn't be a problem for me. However, I understand there are other ways to use vcr which would be more problematic. Thanks for taking the time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants