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

Do not record requests based on response #739

Closed
jlsherrill opened this issue Mar 6, 2019 · 2 comments
Closed

Do not record requests based on response #739

jlsherrill opened this issue Mar 6, 2019 · 2 comments

Comments

@jlsherrill
Copy link

I currently work on an application that starts task in a 2nd application and polls them until completion. It would be very nice if we could record only the successful task polls. I imagine:

  • Test run with recording on
  • Test makes http call to start async task in 2nd app - recorded in VCR
  • Polls 2nd app to get task status - NOT recorded in VCR
  • Last poll will result in task complete - recorded in VCR

Today our cassettes might have dozens of task reports from polling events that really aren't needed when we run our tests.

The benefits are:

  • Smaller vcr cassettes
  • The tests will run faster without having to code your application to be aware of the testing environment (waiting before polling again).

Describe the solution you'd like
something very similar to the 'ignore_request' feature, where i could define a lambda that takes the response and returns true or false, something like:

c.skip_recording{|request, response|  
    request.uri.path  =~ /.*tasks.*/ &&  JSON.parse(response.body)[:status] != 'complete'   
}

Additional context
Somewhat related to: #287, but their situation seemed somewhat different.

In that issue, the recommendation is that their test decide when to record, but in my case my test is calling app code that is doing the polling. It wouldn't be proper to modify that code to be aware of vcr (that we only use for testing).

@jlsherrill
Copy link
Author

jlsherrill commented Mar 6, 2019

I'm happy to take a stab at an implementation of this, but wanted to open the issue to determine:

  1. how feasible it is
  2. if its a welcome change
  3. I didn't miss something obvious, and you can already do this.

@myronmarston
Copy link
Member

You can already do this by using a before_record hook, and calling ignore! on the HTTP interaction object passed to the hook:

https://relishapp.com/vcr/vcr/v/3-0-3/docs/hooks/before-record-hook#prevent-recording-by-ignoring-interaction-in-before-record-hook

I think this is already sufficiently flexible, and I don't think VCR needs additional functionality for this.

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