2

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.

orde
  • 5,233
  • 6
  • 31
  • 33
user1291365
  • 516
  • 1
  • 4
  • 16

1 Answers1

4
  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
Myron Marston
  • 21,452
  • 5
  • 64
  • 63
  • Yes, it works, but i need tests really make this responses on Travis-ci, and clean their test data on server after execution, so i can't use vcr cassettes for it. – user1291365 Aug 09 '13 at 10:31
  • 1
    If you want to turn VCR off, it provides APIs to do so: https://relishapp.com/vcr/vcr/v/2-5-0/docs/cassettes/error-for-http-request-made-when-no-cassette-is-in-use – Myron Marston Aug 09 '13 at 18:01