Friday, 15 January 2010

facebook graph api - VCR is not recording cassettes on successful requests, only on failed ones -



facebook graph api - VCR is not recording cassettes on successful requests, only on failed ones -

i have simple test fetch 1 facebook object. i'm using curl request.

it "gets object facebook" vcr.use_cassette('facebook') 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 |c| c.cassette_library_dir = 'spec/fixtures/vcr_cassettes' c.hook_into :webmock end

when run tests, passes, , next logged:

[cassette: 'facebook'] initialized 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 request matchers [:method, :uri] , 0 interaction(s): { } [webmock] identified request type (recordable) [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 cassette not recorded , dir empty. i've tried :record => :all same results.

usually, people encountered error when using incompatible hooks library they're using, that's not case. i'm using webmock , curb.

curiously, cassette recorded when there's failure in request, e.g., token expired. when it's fixed, , delete file, it's not recorded again.

have had same problem?

it turns out code little more complicated above , executing callback after perfoming request. like:

success_handler = proc.new { homecoming c.body_str } curl.on_success |easy| success_handler.call(easy) end

that bypasses vcr , file not written. refactoring code not utilize callbacks works.

facebook-graph-api rspec vcr

No comments:

Post a Comment