Feedjira: VCR won't record tapes

I have a very simple controller that grabs some data from rss using Feedjira. I want to test this controller by recording an 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 test 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 the 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 cassette is not being recorded in this particular test. All other tests that use web calls work, but with this one from Feedjira it seems that vcr is not detecting network calls. What for?

+3


source to share


2 answers


According to the Feedjira homepage , curb is used to make HTTP requests, rather than Net::HTTP

:

An important goal of Feedjira is faster downloads using libcurl-multi via the curb gem.



VCR can only use FakeWeb to connect to requests Net::HTTP

. To connect to constraint requests you need to use hook_into :webmock

instead.

0


source


Starting with this commit in Feedjira 2.0, Feedjira uses faraday, which means you can follow the testing guide in the Faraday readme or use a video recorder.

Feedjira now also uses a VCR. Example



For example, you can use vcr in rspec example like

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

      

0


source







All Articles