<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

describe Feedzirra::Feed do
  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
      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
      Feedzirra::Parser::AtomEntry.new.should respond_to(:comment_rss)
    end
    
    it "should parse the added element out of RSS feeds" 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
    context "when there's an available parser" do
      it "should parse an rdf feed" do
        feed = Feedzirra::Feed.parse(sample_rdf_feed)
        feed.title.should == "HREF Considered Harmful"
        feed.entries.first.published.to_s.should == "Tue Sep 02 19:50:07 UTC 2008"
        feed.entries.size.should == 10
      end

      it "should parse an rss feed" do
        feed = Feedzirra::Feed.parse(sample_rss_feed)
        feed.title.should == "Tender Lovemaking"
        feed.entries.first.published.to_s.should == "Thu Dec 04 17:17:49 UTC 2008"
        feed.entries.size.should == 10
      end

      it "should parse an atom feed" do
        feed = Feedzirra::Feed.parse(sample_atom_feed)
        feed.title.should == "Amazon Web Services Blog"
        feed.entries.first.published.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
        feed.entries.size.should == 10
      end

      it "should parse an feedburner atom feed" do
        feed = Feedzirra::Feed.parse(sample_feedburner_atom_feed)
        feed.title.should == "Paul Dix Explains Nothing"
        feed.entries.first.published.to_s.should == "Thu Jan 22 15:50:22 UTC 2009"
        feed.entries.size.should == 5
      end      

      it "should parse an itunes feed" do
        feed = Feedzirra::Feed.parse(sample_itunes_feed)
        feed.title.should == "All About Everything"
        feed.entries.first.published.to_s.should == "Wed, 15 Jun 2005 19:00:00 GMT"
        feed.entries.first.itunes_author.should == "<NAME>"
        feed.entries.size.should == 3
      end
    end

    context "when there's no available parser" do
      it "raises Feedzirra::NoParserAvailable" do
        proc {
          Feedzirra::Feed.parse("I'm an invalid feed")<commit_msg>Change spec to reflect new method behavior.<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe Feedzirra::Feed do
  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
      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
      Feedzirra::Parser::AtomEntry.new.should respond_to(:comment_rss)
    end
    
    it "should parse the added element out of RSS feeds" 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
    context "when there's an available parser" do
      it "should parse an rdf feed" do
        feed = Feedzirra::Feed.parse(sample_rdf_feed)
        feed.title.should == "HREF Considered Harmful"
        feed.entries.first.published.to_s.should == "Tue Sep 02 19:50:07 UTC 2008"
        feed.entries.size.should == 10
      end

      it "should parse an rss feed" do
        feed = Feedzirra::Feed.parse(sample_rss_feed)
        feed.title.should == "Tender Lovemaking"
        feed.entries.first.published.to_s.should == "Thu Dec 04 17:17:49 UTC 2008"
        feed.entries.size.should == 10
      end

      it "should parse an atom feed" do
        feed = Feedzirra::Feed.parse(sample_atom_feed)
        feed.title.should == "Amazon Web Services Blog"
        feed.entries.first.published.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
        feed.entries.size.should == 10
      end

      it "should parse an feedburner atom feed" do
        feed = Feedzirra::Feed.parse(sample_feedburner_atom_feed)
        feed.title.should == "<NAME> Explains Nothing"
        feed.entries.first.published.to_s.should == "Thu Jan 22 15:50:22 UTC 2009"
        feed.entries.size.should == 5
      end      

      it "should parse an itunes feed as a standard RSS feed" do
        feed = Feedzirra::Feed.parse(sample_itunes_feed)
        feed.title.should == "All About Everything"
        feed.entries.first.published.should == Time.parse("Wed, 15 Jun 2005 19:00:00 GMT")
        
        # Since the commit 621957879, iTunes feeds will be parsed as standard RSS, so this
        # entry should now not have a method for itunes_author.
        feed.entries.first.should_not respond_to(:itunes_author)
        feed.entries.size.should == 3
      end
    end

    context "when there's no available parser" do
      it "raises Feedzirra::NoParserAvailable" do
        proc {
          Feedzirra::Feed.parse("I'm an invalid feed")
{'fraction_non_alphanumeric': 0.09502843514951385, 'fraction_numerical': 0.02660062373876353, 'mean_word_length': 2.8152554233729883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6690175', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1653, 'n_words': 488}