Hi Myron,
Thanks for all your help so far ;). I really appreciete it.
My situation is as follows:
I do a lot of different HTTP requests to a specific site; i.e. I test
a lot of different pages on the same site. If I do too much requests
in a certain time, the site will block me forever. To prevent that I
let my application (AND RSpec tests) sleep for 5 seconds between each
HTTP request. The sleep of 5 seconds is only necessarry on a real HTTP
request. You can imagine that this slows down my RSpec tests
dramatically. To speed up my RSpec tests I want to skip the sleep when
the tape is played(i.e. when the HTTP request is stubbed).
So to know if I can skip the sleep I think I have to know for each
request if it is playing a tape or actually recording.
Because the URLs of the actual tested pages changes a lot I can do two
things:
1. Use different tapes for each group of URLs with record_mode 'once'
2. Use one tape with record_mode 'new_episodes' as I do now.
The problem with option 1 is that I need for every Rspec file about 20
different tapes and I have more then 10 RSpec files. So that gonna
cost me a lot of work and I think it's gonna be confusing if I use
over 200 different tapes.
In short my problem is that I want to let my application sleep for 5
seconds on an HTTP request, but when the HTTP request is stubbed I
want to skip the sleep.
Do you have an idea how to do that? Am I thinking in the right
direction with trying to find out whether the tape is played or
recorded?
Regards,
Jeroen
On Sep 27, 12:50 am, Myron Marston <
myron.mars...@gmail.com> wrote:
> > This do the trick, but It's a little ugly IMHO. Did I ran into a bug,
> > or am I doing something else wrong?
>
> I agree that that looks like an ugly hack. However, it's hard for me to
> answer your question because it's not clear to me what it is you're trying
> to achieve. Why do you feel the need to set the defaults one way, and then
> change the defaults in a before/after hooks?
>
> In general, I would recommend using the `:once` record mode as the default,
> and use a different cassette for each different group/sequence of HTTP
> requests. This will appropriately disable HTTP connections when playing
> back, and, in most cases, is what you'll want.
>
> Can you explain how VCR decides to play the tape or records the tape?
>
> It's based on the record mode. Basically, the record mode determines
> whether or not FakeWeb/WebMock/Typhoeus/Excon are stubbed with the requests
> in the cassette or not. It also determines whether or not real HTTP
> connections are allowed. Anytime a real request is made, it is recorded to
> the current cassette. Here is how the individual record modes work:
>
> - :all - Allows real HTTP connections (so that they get recorded). Does
> not stub the requests in the cassette (i.e. no playback).
> - :none - Doesn't allow real HTTP connections. Stubs all requests in the
> cassette (i.e. plays them back).
> - :new_episodes - Allows real HTTP connection (so that new requests get
> recorded) AND stubs the requests in the cassette (so that previously
> recorded requests get replayed).
> - :once - Either allows real HTTP connections OR stubs the requests in