spec/feedzirra/feed_spec.rb in feedzirra-0.0.24 vs spec/feedzirra/feed_spec.rb in feedzirra-0.0.30

- old
+ new

@@ -1,22 +1,41 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Feedzirra::Feed do + + describe "#add_common_feed_element" do + before(:all) do + Feedzirra::Feed.add_common_feed_element("generator") + end + + it "should parse the added element out of Atom feeds" do + Feedzirra::Feed.parse(sample_wfw_feed).generator.should == "TypePad" + end + + it "should parse the added element out of Atom Feedburner feeds" do + Feedzirra::Parser::Atom.new.should respond_to(:generator) + end + + it "should parse the added element out of RSS feeds" do + Feedzirra::Parser::RSS.new.should respond_to(:generator) + end + end + describe "#add_common_feed_entry_element" do before(:all) do Feedzirra::Feed.add_common_feed_entry_element("wfw:commentRss", :as => :comment_rss) end - it "should parse the added element out of Atom feeds" do + it "should parse the added element out of Atom feeds entries" do Feedzirra::Feed.parse(sample_wfw_feed).entries.first.comment_rss.should == "this is the new val" end - it "should parse the added element out of Atom Feedburner feeds" do + it "should parse the added element out of Atom Feedburner feeds entries" do Feedzirra::Parser::AtomEntry.new.should respond_to(:comment_rss) end - it "should parse the added element out of RSS feeds" do + it "should parse the added element out of RSS feeds entries" do Feedzirra::Parser::RSSEntry.new.should respond_to(:comment_rss) end end describe "#parse" do # many of these tests are redundant with the specific feed type tests, but I put them here for completeness @@ -105,11 +124,11 @@ end describe "when adding feed types" do it "should prioritize added types over the built in ones" do feed_text = "Atom asdf" - Feedzirra::Parser::Atom.should be_able_to_parse(feed_text) + Feedzirra::Parser::Atom.stub!(:able_to_parse?).and_return(true) new_feed_type = Class.new do def self.able_to_parse?(val) true end end @@ -298,11 +317,11 @@ Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {}) @easy_curl.on_success.call(@easy_curl) end it 'should parse the xml' do - Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).with(@paul_feed[:xml]).and_return(@feed) + Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).with(@paul_feed[:xml], an_instance_of(Proc)).and_return(@feed) Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {}) @easy_curl.on_success.call(@easy_curl) end describe 'when a compatible xml parser class is found' do @@ -522,11 +541,25 @@ StringIO.should_receive(:new).and_return(string_io) Zlib::GzipReader.should_receive(:new).with(string_io).and_return(string_io) Feedzirra::Feed.decode_content(@curl_easy) end + it 'should decode the response body using gzip if the Content-Encoding: is gzip even when the case is wrong' do + @curl_easy.stub!(:header_str).and_return('content-encoding: gzip') + string_io = mock('stringio', :read => @curl_easy.body_str, :close => true) + StringIO.should_receive(:new).and_return(string_io) + Zlib::GzipReader.should_receive(:new).with(string_io).and_return(string_io) + Feedzirra::Feed.decode_content(@curl_easy) + end + it 'should deflate the response body using inflate if the Content-Encoding: is deflate' do @curl_easy.stub!(:header_str).and_return('Content-Encoding: deflate') + Zlib::Inflate.should_receive(:inflate).with(@curl_easy.body_str) + Feedzirra::Feed.decode_content(@curl_easy) + end + + it 'should deflate the response body using inflate if the Content-Encoding: is deflate event if the case is wrong' do + @curl_easy.stub!(:header_str).and_return('content-encoding: deflate') Zlib::Inflate.should_receive(:inflate).with(@curl_easy.body_str) Feedzirra::Feed.decode_content(@curl_easy) end it 'should return the response body if it is not encoded' do \ No newline at end of file