spec/feedzirra/feed_spec.rb in feedzirra-0.6.0 vs spec/feedzirra/feed_spec.rb in feedzirra-0.7.0

- old
+ new

@@ -2,11 +2,11 @@ class Hell < StandardError; end class FailParser def self.parse(_, &on_failure) - on_failure.call + on_failure.call 'this parser always fails.' end end describe Feedzirra::Feed do @@ -55,11 +55,11 @@ Feedzirra::Feed.parse_with parser, xml end context 'with a callback block' do it 'passes the callback to the parser' do - callback = -> { raise Hell } + callback = ->(*) { raise Hell } expect do Feedzirra::Feed.parse_with FailParser, xml, &callback end.to raise_error Hell end @@ -266,10 +266,11 @@ describe "fetching feeds" do before(:each) do @paul_feed = { :xml => load_sample("PaulDixExplainsNothing.xml"), :url => "http://feeds.feedburner.com/PaulDixExplainsNothing" } @trotter_feed = { :xml => load_sample("TrotterCashionHome.xml"), :url => "http://feeds2.feedburner.com/trottercashion" } + @invalid_feed = { :xml => 'This feed is invalid', :url => "http://feeds.feedburner.com/InvalidFeed" } end describe "#fetch_raw" do before(:each) do @cmock = double('cmock', :header_str => '', :body_str => @paul_feed[:xml] ) @@ -454,15 +455,15 @@ Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_success => success }) @easy_curl.on_success.call(@easy_curl) end describe 'when the parser raises an exception' do - it 'invokes the on_failure callback' do - failure = lambda { |url, feed| } - failure.should_receive(:call).with(@paul_feed[:url], 0, nil, nil) + it 'invokes the on_failure callback with that exception' do + failure = double 'Failure callback', arity: 2 + failure.should_receive(:call).with(@easy_curl, an_instance_of(Hell)) - Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_raise Exception + Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_raise Hell Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure }) @easy_curl.on_success.call(@easy_curl) end end @@ -471,23 +472,23 @@ before(:each) do Feedzirra::Feed.stub(:determine_feed_parser_for_xml).and_return FailParser end it 'invokes the on_failure callback' do - failure = lambda { |url, feed| } - failure.should_receive(:call).with(@paul_feed[:url], 0, nil, nil) + failure = double 'Failure callback', arity: 2 + failure.should_receive(:call).with(@easy_curl, an_instance_of(RuntimeError)) Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure }) @easy_curl.on_success.call(@easy_curl) end end end describe 'when no compatible xml parser class is found' do it 'invokes the on_failure callback' do - failure = lambda { |url, feed| } - failure.should_receive(:call).with(@paul_feed[:url], 0, nil, nil) + failure = double 'Failure callback', arity: 2 + failure.should_receive(:call).with(@easy_curl, "Can't determine a parser") Feedzirra::Feed.should_receive(:determine_feed_parser_for_xml).and_return nil Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure }) @easy_curl.on_success.call(@easy_curl) @@ -504,12 +505,12 @@ @easy_curl.stub(:header_str).and_return(@headers) @easy_curl.stub(:body_str).and_return(@body) end it 'should call proc if :on_failure option is passed' do - failure = lambda { |url, feed| } - failure.should_receive(:call).with(@paul_feed[:url], 500, @headers, @body) + failure = double 'Failure callback', arity: 2 + failure.should_receive(:call).with(@easy_curl, nil) Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => failure }) @easy_curl.on_failure.call(@easy_curl) end it 'should return the http code in the responses' do @@ -531,12 +532,12 @@ @easy_curl.stub(:header_str).and_return(@headers) @easy_curl.stub(:body_str).and_return(@body) end it 'should call proc if :on_failure option is passed' do - complete = lambda { |url| } - complete.should_receive(:call).with(@paul_feed[:url], 404, @headers, @body) + complete = double 'Failure callback', arity: 2 + complete.should_receive(:call).with(@easy_curl, 'Server returned a 404') Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => complete }) @easy_curl.on_missing.call(@easy_curl) end it 'should return the http code in the responses' do @@ -657,11 +658,11 @@ before(:each) do Feedzirra::Feed.stub(:determine_feed_parser_for_xml).and_return FailParser end it 'invokes the on_failure callback' do - failure = lambda { |feed| } + failure = double 'Failure callback', arity: 2 failure.should_receive(:call) Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, { on_failure: failure }) @easy_curl.on_success.call(@easy_curl) end @@ -690,10 +691,10 @@ responses = {} Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], responses, {}) @easy_curl.on_failure.call(@easy_curl) responses.length.should == 1 - responses['http://www.pauldix.net/'].should == 404 + responses[@paul_feed[:url]].should == 404 end end end describe "#fetch_and_parse" do