Multiple requests in one cassette

2,086 views
Skip to first unread message

aldo sarmiento

unread,
Apr 23, 2012, 4:42:57 AM4/23/12
to VCR Rubygem
Hello,

I'm writing a test for my subscription UI. The process includes 2
requests, one for authorization and one for charging the card.

This is my test using RSpec: http://pastie.org/3837967

Inside of the 'authorize_net_idx_premium_success.yml' there is only 1
request (for charging the card). The first request made in the
process, authorizing the card, is not stored in any cassette. As a
result, my tests keep making requests for the authorization.

Is this because both requests are hitting the same URI? --
https://apitest.authorize.net/xml/v1/request.api

Myron Marston

unread,
Apr 23, 2012, 11:07:02 AM4/23/12
to VCR Rubygem
That generally shouldn't matter, although I can think of an obscure
situation you could get yourself into if you configured VCR a
particular way and you had originally recorded the cassette when the
code-under-test made only 1 request. You can delete the cassette and
re-run the test; if you were in this situation it would record both
requests this time.

It's hard for me to guess what the problem might be, but two other
ideas that come to mind...

* If the authorization request is made using a different HTTP client
and VCR hasn't been configured to hook into that client, then it would
make sense that it wouldn't record or playback that request.
* In the test it looks like you're using capybara. Are you using the
rack-test drivers or one of the javascript drivers? I ask because the
rack-test driver is synchronous but the rest of the drivers (at least
the ones I've tried) are not. Your app runs in a separate thread, and
"action" methods like `click_link` or `click_button` do not wait for a
response from the app before returning. So...you can get in
situations where in your test a cassette is wrapping a call to
`click_link`, which should trigger a code path in your application
that makes an HTTP request, but the cassette may be ejected before the
request is made since it's asynchronous.

If you can come up with a reproducible example I can take a look at
it. You may also want to try the debug_logger[1] option--it will
likely give you some insight into what's going on.

HTH,
Myron

[1] https://www.relishapp.com/myronmarston/vcr/v/2-1-0/docs/configuration/debug-logging

Zubin Henner

unread,
Sep 21, 2012, 5:19:51 AM9/21/12
to vcr-...@googlegroups.com, sarm...@gmail.com
Hi,

I'm having a similar problem involving two requests.

The first request is a SOAP API call which posts some data and the second is a GET request to download a PDF (using information from the first request).

The problem is the first request isn't being recorded (only the second one is). Using the debug_logger option, I've observed that VCR doesn't register the first request, only the second one.

My setup is a rails 2.3.14 app, where the first request is executed from inside another gem which uses savon. The second request is from application code and uses open-uri. 

Any pointers on how to capture the first request?

--
Zubin

Zubin Henner

unread,
Sep 21, 2012, 5:58:00 AM9/21/12
to vcr-...@googlegroups.com, sarm...@gmail.com
Cancel that, switching to webmock solved the problem.

Myron Marston

unread,
Sep 21, 2012, 10:55:00 AM9/21/12
to VCR Rubygem
On Sep 21, 2:58 am, Zubin Henner <zubin.hen...@gmail.com> wrote:
> Cancel that, switching to webmock solved the problem.

Thanks for following up!

That suggests that a different HTTP library was being used for the
first and second requests--is that the case?
Reply all
Reply to author
Forward
0 new messages