VCR do not want to handle requests inside before and after hooks.

1.4k Views Asked by At

I developed a ruby wrapper for one HTTP REST API, using rspec with vcr for testing my requests. Project is loaded to travis-ci.org, which automatiacly runs tests all the time. I have a problem inside my test. VCR can't handle requests inside before and after hooks, implemented to prevent filling server with test data.

  describe '.find' do
    before :all do
      @project = Project.new(name: "Project#{Time.now.to_i}").save
    end

    after :all do
      @project.delete
    end

    #tests
  end

I got a vcr error:

An error occurred in a before(:all) hook.
  VCR::Errors::UnhandledHTTPRequestError: 

Of course, I don't want to create and delete a remote entity in each test.

1

There are 1 best solutions below

2
On
  describe '.find' do
    before :all do
      VCR.use_cassette("some_cassette_name") do
        @project = Project.new(name: "Project#{Time.now.to_i}").save
      end
    end

    after :all do
      VCR.use_cassette("some_other_cassette_name") do
        @project.delete
      end
    end

    #tests
  end