0

I have a simple test to fetch one Facebook object. I'm using Curl for the request.

it "gets an object from Facebook" do
  VCR.use_cassette('facebook') do
    url = "https://graph.facebook.com/<ID>?access_token=#{@access_token}&#{query_string}"
    curl = Curl::Easy.perform(url)
    expect(curl.body_str).to eql('<my object>')
  end
end

My VCR configs are:

VCR.configure do |c|
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
  c.hook_into :webmock
end

When I run the tests, it passes, and the following is logged:

[Cassette: 'facebook'] Initialized with options: {:record=>:once, :match_requests_on=>[:method, :uri], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system}
[webmock] Handling request: [get https://graph.facebook.com/<ID>?access_token=<TOKEN>&fields=%5B%22id%22,%22account_id%22,%22name%22,%22campaign_group_status%22,%22objective%22%5D] (disabled: false)
[Cassette: 'facebook'] Initialized HTTPInteractionList with request matchers [:method, :uri] and 0 interaction(s): {  }
[webmock] Identified request type (recordable) for [get https://graph.facebook.com/<ID>?access_token=<TOKEN>&fields=%5B%22id%22,%22account_id%22,%22name%22,%22campaign_group_status%22,%22objective%22%5D]

But the cassette is not recorded and the dir is empty. I've tried :record => :all to same results.

Usually, people encountered this error when using incompatible hooks for the library they're using, but that's not the case. I'm using webmock and curb.

Curiously, the cassette is recorded when there's a failure in the request, e.g., the token is expired. When it's fixed, and I delete the file, it's not recorded again.

Have anyone had the same problem?

shadowmaru
  • 141
  • 1
  • 9

1 Answers1

1

It turns out that my code was a little more complicated than above and was executing a callback after perfoming the request. Something like:

success_handler = Proc.new { return c.body_str }

curl.on_success do |easy|
  success_handler.call(easy)
end

That bypasses VCR and the file is not written. Refactoring the code to not use callbacks works.

shadowmaru
  • 141
  • 1
  • 9
  • That sounds like a bug in webmock (the library VCR uses to interface with Curb). When users use the public Curb API it should not interfere with VCR's use of WebMock to intercept the HTTP calls, but it appears that these sorts of callbacks have that effect. I encourage you to report this to the WebMock issue tracker on github. – Myron Marston Oct 15 '14 at 00:28