Testing Flickraw with VCR gives erratic results
Closed this issue · 2 comments
In my app I am importing a list of photosets
# models/photoset
class Photoset
def self.import(opts = {})
res = flickr.photosets.getList(opts)
res.map do |item|
set = find_or_initialize_by(uid: item["id"])
set.assign_attributes(
title: item["title"]
)
set
end.keep_if { |s| s.new_record? }
end
end
I then record the response with VCR in my specs, however this gives me some strange results
as flickr.photosets.getList
sometimes gives me a list of flickr.reflection.getMethods
results instead.
describe Photoset do
describe '.import' do
let(:photosets) do
VCR.use_cassette('photosets_getList') do
@photosets = Photoset.import(user_id: ENV['FLICKR_TEST_USER'])
end
end
it "gets photosets" do
expect(photosets.first).to be_a Photoset
end
it "sets uid" do
expect(photosets.first.uid).to eq '72157647753138397'
end
it "sets title", focus: true do
expect(hpotosets.first.title).to eq 'Showcase'
end
it "does not include sets that allready exist" do
expect(photosets.select(&:persisted?).count).to eq 0
end
end
end
The recorded response contains a call to flickr.reflection.getMethods
and a call to flickr.photosets.getList
.
Is the call to flickr.reflection.getMethods
used for some metaprogramming magic or why is it called at all?
flickr.reflection.getMethods
is called to build all the objects and methods. Flickraw does not know what methods are available when initiallzed. If you want a deterministic behavior, you can use flickraw-cached which embeds a list of all methods.
I have the opposite problem - in a place where getMethods
is called I get a list of photos. The problem is ONLY if VCR is enabled so looks like they don't play well together and VCR can't distinguish these requests
UPDATE: the issue was solved but by adding :body to a matched things list for VCR - https://relishapp.com/vcr/vcr/docs/request-matching/matching-on-body