Reputation: 11952
I have a very simple controller that grabs some data from rss using Feedjira. I want to test this controller by recording the RSS response. Here is the controller code:
def index
@news = Feedjira::Feed.fetch_and_parse URI.encode("http://news.google.com/news/feeds?q=\"#{query}\"&output=rss")
end
and my spec test:
it "should assign news feed", :vcr do
get :index
assigns(:news).entries.size.should == 6
assigns(:news).entries[0].title.should == "First item title"
end
and code for vcd config:
VCR.configure do |c|
c.cassette_library_dir = Rails.root.join("spec", "vcr")
c.hook_into :fakeweb
c.ignore_localhost = true
end
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
c.around(:each, :vcr) do |example|
name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
VCR.use_cassette(name, options) { example.call }
end
end
For some unknown reason, the VCR cassete is not being recorded in this specific test. All other tests that use web calls are working, but with this one with Feedjira it seems that vcr does not detects the network calls. Why?
Upvotes: 3
Views: 675
Reputation: 1637
As of this commit in Feedjira 2.0, Feedjira uses faraday, which means you can follow the testing guide in the Faraday readme or use VCR.
Feedjira uses VCR internally now too. Example
For example you could use vcr in an rspec example like this,
it 'fetches and parses the feed' do
VCR.use_cassette('success') do
feed = Feedjira::Feed.fetch_and_parse 'http://feedjira.com/blog/feed.xml'
expect(feed.last_modified).to eq('Fri, 07 Oct 2016 14:37:00 GMT')
end
end
Upvotes: 0
Reputation: 21810
According to Feedjira's home page, it uses curb, not Net::HTTP
to make HTTP requests:
An important goal of Feedjira is speed - fetching is fast by using libcurl-multi through the curb gem.
VCR can only use FakeWeb to hook into Net::HTTP
requests. To hook into curb requests, you'll need to use hook_into :webmock
instead.
Upvotes: 0