spec/feedzirra/feed_spec.rb in feedzirra-0.3.0 vs spec/feedzirra/feed_spec.rb in feedzirra-0.4.0
- old
+ new
@@ -1,7 +1,13 @@
require File.dirname(__FILE__) + '/../spec_helper'
+class FailParser
+ def self.parse(_, on_failure)
+ on_failure.call
+ end
+end
+
describe Feedzirra::Feed do
describe "#add_common_feed_element" do
before(:all) do
Feedzirra::Feed.add_common_feed_element("generator")
@@ -245,11 +251,11 @@
describe "#fetch_raw" do
before(:each) do
@cmock = double('cmock', :header_str => '', :body_str => @paul_feed[:xml] )
@multi = double('curl_multi', :add => true, :perform => true)
@curl_easy = double('curl_easy')
- @curl = double('curl', :headers => {}, :follow_location= => true, :on_failure => true)
+ @curl = double('curl', :headers => {}, :follow_location= => true, :on_failure => true, :on_complete => true)
@curl.stub(:on_success).and_yield(@cmock)
Curl::Multi.stub(:new).and_return(@multi)
Curl::Easy.stub(:new).and_yield(@curl).and_return(@curl_easy)
end
@@ -293,14 +299,14 @@
Curl::Multi.stub(:new).and_return(multi)
paul_response = double('paul_response', :header_str => '', :body_str => @paul_feed[:xml] )
trotter_response = double('trotter_response', :header_str => '', :body_str => @trotter_feed[:xml] )
- paul_curl = double('paul_curl', :headers => {}, :follow_location= => true, :on_failure => true)
+ paul_curl = double('paul_curl', :headers => {}, :follow_location= => true, :on_failure => true, :on_complete => true)
paul_curl.stub(:on_success).and_yield(paul_response)
- trotter_curl = double('trotter_curl', :headers => {}, :follow_location= => true, :on_failure => true)
+ trotter_curl = double('trotter_curl', :headers => {}, :follow_location= => true, :on_failure => true, :on_complete => true)
trotter_curl.stub(:on_success).and_yield(trotter_response)
Curl::Easy.should_receive(:new).with(@paul_feed[:url]).ordered.and_yield(paul_curl)
Curl::Easy.should_receive(:new).with(@trotter_feed[:url]).ordered.and_yield(trotter_curl)
@@ -423,14 +429,48 @@
success = lambda { |url, feed| }
success.should_receive(:call).with(@paul_feed[:url], @feed)
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)
+
+ Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_raise Exception
+ Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure })
+
+ @easy_curl.on_success.call(@easy_curl)
+ end
+ end
+
+ describe 'when the parser invokes its on_failure callback' do
+ 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)
+
+ 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 'should raise a NoParserAvailable exception'
+ it 'invokes the on_failure callback' do
+ failure = lambda { |url, feed| }
+ failure.should_receive(:call).with(@paul_feed[:url], 0, nil, nil)
+
+ 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)
+ end
end
end
describe 'on failure' do
before(:each) do
@@ -471,11 +511,11 @@
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)
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => complete })
- @easy_curl.on_complete.call(@easy_curl)
+ @easy_curl.on_missing.call(@easy_curl)
end
it 'should return the http code in the responses' do
responses = {}
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], responses, {})
@@ -541,12 +581,10 @@
Feedzirra::Parser::AtomFeedBurner.stub(:parse).and_return(@new_feed)
Feedzirra::Feed.stub(:etag_from_header).and_return('ziEyTl4q9GH04BR4jgkImd0GvSE')
Feedzirra::Feed.stub(:last_modified_from_header).and_return('Wed, 28 Jan 2009 04:10:32 GMT')
end
- it 'should process the next feed in the queue'
-
it 'should parse the updated feed' do
Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_return(@new_feed)
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {})
@easy_curl.on_success.call(@easy_curl)
end
@@ -589,10 +627,24 @@
it 'should call update from feed on the old feed with the updated feed' do
@feed.should_receive(:update_from_feed).with(@new_feed)
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {})
@easy_curl.on_success.call(@easy_curl)
end
+
+ describe 'when the parser invokes its on_failure callback' do
+ 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.should_receive(:call)
+
+ Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, { on_failure: failure })
+ @easy_curl.on_success.call(@easy_curl)
+ end
+ end
end
describe 'on failure' do
before(:each) do
@headers = "HTTP/1.0 404 Not Found\r\nDate: Thu, 29 Jan 2009 03:55:24 GMT\r\nServer: Apache\r\nX-FB-Host: chi-write6\r\nLast-Modified: Wed, 28 Jan 2009 04:10:32 GMT\r\n"
@@ -606,10 +658,10 @@
it 'should call on success callback if the response code is 304' do
success = lambda { |feed| }
success.should_receive(:call).with(@feed)
@easy_curl.should_receive(:response_code).and_return(304)
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, { :on_success => success })
- @easy_curl.on_failure.call(@easy_curl)
+ @easy_curl.on_redirect.call(@easy_curl)
end
it 'should return the http code in the responses' do
responses = {}
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], responses, {})