Hooks before and after a recording session

21 views
Skip to first unread message

Ramon Tayag

unread,
Mar 7, 2013, 4:35:15 AM3/7/13
to vcr-...@googlegroups.com

I've created a "DatabaseCleaner" for Bitcoin Testnet in a Box. Basically, it stops, cleans, and restarts the Bitcoin daemons for every test. As you can imagine, this is slow. To speed it up, I can use VCR and only restart the daemons if no cassette exists. Is there something like this:

VCR.configure do |c|
  c.before_recording_session do
    # Restart and clean the Bitcoin Testnet here
  end

  c.after_recording_session do
    # Stop and clean the Bitcoin Testnet here
  end
end

If not, would it be a good addition? If it would be a good, I volunteer to add it. Myron, we had a discussion similar to this before. Thanks to your comments, I realized hooks would be a better place. Since cassettes can be recorded in another place other than the filesystem, what more generic method can I call to just get true/false to the question cassette_exists??

Thanks in advance!

Ramon Tayag

unread,
Mar 7, 2013, 5:06:31 AM3/7/13
to vcr-...@googlegroups.com

I should have stepped through the code before asking. I could have answered one of my questions:

  • what more generic method can I call to just get true/false to the question cassette_exists??

It looks like there isn't such a method. And right now, there's no way to enforce that custom Persisters will apply this. I thought of two ways around this:

  1. The hook will only work when the cassette responds to absolute_path_to_file. This isn't ideal, but it will get the job done for me.
  2. All persisters should inherit from a Persister class that has a method:

    def cassette_exists?(name)
    fail NotImplementedError, 'your persister must implement this method'
    end

Myron Marston

unread,
Mar 8, 2013, 1:43:56 AM3/8/13
to VCR Rubygem
Can you open a github issue? That's a better place to discuss feature
ideas like this.

Thanks,
Myron

On Mar 7, 2:06 am, Ramon Tayag <ramon.ta...@gmail.com> wrote:
> I should have stepped through the code before asking. I could have answered
> *one* of my questions:
>
>    - what more generic method can I call to just get true/false to the
>    question cassette_exists??
>
> It looks like there isn't such a method. And right now, there's no way to
> enforce that custom Persisters will apply this. I thought of two ways
> around this:
>
>    1. The hook will only work when the cassette responds to
>    absolute_path_to_file. This isn't ideal, but it will get the job done
>    for me.
>    2.
>
>    All persisters should inherit from a Persister class that has a method:
>
>    def cassette_exists?(name)
>    fail NotImplementedError, 'your persister must implement this method'
>    end
>
>
>
>
>
>
>
> On Thursday, March 7, 2013 5:35:15 PM UTC+8, Ramon Tayag wrote:
>
> > I've created a "DatabaseCleaner" for Bitcoin Testnet in a Box. Basically,
> > it stops, cleans, and restarts the Bitcoin daemons for every test. As you
> > can imagine, this is slow. To speed it up, I can use VCR and only restart
> > the daemons if no cassette exists. Is there something like this:
>
> > VCR.configure do |c|
> >   c.before_recording_session do
> >     # Restart and clean the Bitcoin Testnet here
> >   end
>
> >   c.after_recording_session do
> >     # Stop and clean the Bitcoin Testnet here
> >   end
> > end
>
> > If not, would it be a good addition? If it would be a good, I volunteer to
> > add it. Myron, we had a discussion similar<https://github.com/vcr/vcr/pull/232>to this before. Thanks to your comments, I realized hooks would be a better

Ramon Tayag

unread,
Mar 8, 2013, 8:26:44 PM3/8/13
to vcr-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages