rickerbh-feedzirra 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,149 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Feedzirra::FeedUtilities do
4
+ before(:each) do
5
+ @klass = Class.new do
6
+ include Feedzirra::FeedUtilities
7
+ end
8
+ end
9
+
10
+ describe "instance methods" do
11
+ it "should provide an updated? accessor" do
12
+ feed = @klass.new
13
+ feed.should_not be_updated
14
+ feed.updated = true
15
+ feed.should be_updated
16
+ end
17
+
18
+ it "should provide a new_entries accessor" do
19
+ feed = @klass.new
20
+ feed.new_entries.should == []
21
+ feed.new_entries = [:foo]
22
+ feed.new_entries.should == [:foo]
23
+ end
24
+
25
+ it "should provide an etag accessor" do
26
+ feed = @klass.new
27
+ feed.etag = "foo"
28
+ feed.etag.should == "foo"
29
+ end
30
+
31
+ it "should provide a last_modified accessor" do
32
+ feed = @klass.new
33
+ time = Time.now
34
+ feed.last_modified = time
35
+ feed.last_modified.should == time
36
+ end
37
+
38
+ it "should return new_entries? as true when entries are put into new_entries" do
39
+ feed = @klass.new
40
+ feed.new_entries << :foo
41
+ feed.should have_new_entries
42
+ end
43
+
44
+ it "should return a last_modified value from the entry with the most recent published date if the last_modified date hasn't been set" do
45
+ feed = Feedzirra::Atom.new
46
+ entry =Feedzirra::AtomEntry.new
47
+ entry.published = Time.now.to_s
48
+ feed.entries << entry
49
+ feed.last_modified.should == entry.published
50
+ end
51
+
52
+ it "should not throw an error if one of the entries has published date of nil" do
53
+ feed = Feedzirra::Atom.new
54
+ entry = Feedzirra::AtomEntry.new
55
+ entry.published = Time.now.to_s
56
+ feed.entries << entry
57
+ feed.entries << Feedzirra::AtomEntry.new
58
+ feed.last_modified.should == entry.published
59
+ end
60
+ end
61
+
62
+ describe "#update_from_feed" do
63
+ describe "updating feed attributes" do
64
+ before(:each) do
65
+ # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
66
+ # method would only be called against a feed item.
67
+ @feed = Feedzirra::Atom.new
68
+ @feed.title = "A title"
69
+ @feed.url = "http://pauldix.net"
70
+ @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
71
+ @feed.updated = false
72
+ @updated_feed = @feed.dup
73
+ end
74
+
75
+ it "should update the title if changed" do
76
+ @updated_feed.title = "new title"
77
+ @feed.update_from_feed(@updated_feed)
78
+ @feed.title.should == @updated_feed.title
79
+ @feed.should be_updated
80
+ end
81
+
82
+ it "should not update the title if the same" do
83
+ @feed.update_from_feed(@updated_feed)
84
+ @feed.should_not be_updated
85
+ end
86
+
87
+ it "should update the feed_url if changed" do
88
+ @updated_feed.feed_url = "a new feed url"
89
+ @feed.update_from_feed(@updated_feed)
90
+ @feed.feed_url.should == @updated_feed.feed_url
91
+ @feed.should be_updated
92
+ end
93
+
94
+ it "should not update the feed_url if the same" do
95
+ @feed.update_from_feed(@updated_feed)
96
+ @feed.should_not be_updated
97
+ end
98
+
99
+ it "should update the url if changed" do
100
+ @updated_feed.url = "a new url"
101
+ @feed.update_from_feed(@updated_feed)
102
+ @feed.url.should == @updated_feed.url
103
+ end
104
+
105
+ it "should not update the url if not changed" do
106
+ @feed.update_from_feed(@updated_feed)
107
+ @feed.should_not be_updated
108
+ end
109
+ end
110
+
111
+ describe "updating entries" do
112
+ before(:each) do
113
+ # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
114
+ # method would only be called against a feed item.
115
+ @feed = Feedzirra::Atom.new
116
+ @feed.title = "A title"
117
+ @feed.url = "http://pauldix.net"
118
+ @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
119
+ @feed.updated = false
120
+ @updated_feed = @feed.dup
121
+ @old_entry = Feedzirra::AtomEntry.new
122
+ @old_entry.url = "http://pauldix.net/old.html"
123
+ @old_entry.published = Time.now.to_s
124
+ @new_entry = Feedzirra::AtomEntry.new
125
+ @new_entry.url = "http://pauldix.net/new.html"
126
+ @new_entry.published = (Time.now + 10).to_s
127
+ @feed.entries << @old_entry
128
+ @updated_feed.entries << @new_entry
129
+ @updated_feed.entries << @old_entry
130
+ end
131
+
132
+ it "should update last-modified from the latest entry date" do
133
+ @feed.update_from_feed(@updated_feed)
134
+ @feed.last_modified.should == @new_entry.published
135
+ end
136
+
137
+ it "should put new entries into new_entries" do
138
+ @feed.update_from_feed(@updated_feed)
139
+ @feed.new_entries.should == [@new_entry]
140
+ end
141
+
142
+ it "should also put new entries into the entries collection" do
143
+ @feed.update_from_feed(@updated_feed)
144
+ @feed.entries.should include(@new_entry)
145
+ @feed.entries.should include(@old_entry)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Feedzirra::RDFEntry do
4
+ before(:each) do
5
+ # I don't really like doing it this way because these unit test should only rely on AtomEntry,
6
+ # but this is actually how it should work. You would never just pass entry xml straight to the AtomEnry
7
+ @entry = Feedzirra::RDF.parse(sample_rdf_feed).entries.first
8
+ end
9
+
10
+ it "should parse the title" do
11
+ @entry.title.should == "Chrome, V8 and Strongtalk"
12
+ end
13
+
14
+ it "should parse the url" do
15
+ @entry.url.should == "http://www.avibryant.com/2008/09/chrome-v8-and-s.html"
16
+ end
17
+
18
+ it "should parse the author" do
19
+ @entry.author.should == "Avi"
20
+ end
21
+
22
+ it "should parse the content" do
23
+ @entry.content.should == sample_rdf_entry_content
24
+ end
25
+
26
+ it "should provide a summary" do
27
+ @entry.summary.should == "There's lots to like about Google's new web browser, Chrome, which was released today. When I read the awesome comic strip introduction yesterday, however, the thing that stood out most for me was in very small type: the name Lars..."
28
+ end
29
+
30
+ it "should parse the published date" do
31
+ @entry.published.to_s.should == "Tue Sep 02 19:50:07 UTC 2008"
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Feedzirra::RDF do
4
+ describe "#will_parse?" do
5
+ it "should return true for an rdf feed" do
6
+ Feedzirra::RDF.should be_able_to_parse(sample_rdf_feed)
7
+ end
8
+
9
+ it "should return false for an atom feed" do
10
+ Feedzirra::RDF.should_not be_able_to_parse(sample_atom_feed)
11
+ end
12
+ end
13
+
14
+ describe "parsing" do
15
+ before(:each) do
16
+ @feed = Feedzirra::RDF.parse(sample_rdf_feed)
17
+ end
18
+
19
+ it "should parse the title" do
20
+ @feed.title.should == "HREF Considered Harmful"
21
+ end
22
+
23
+ it "should parse the url" do
24
+ @feed.url.should == "http://www.avibryant.com/"
25
+ end
26
+
27
+ # rdf doesn't actually specify the feed_url. This should be set in the fetcher.
28
+ it "should provide an accessor for the feed_url" do
29
+ @feed.respond_to?(:feed_url).should == true
30
+ @feed.respond_to?(:feed_url=).should == true
31
+ end
32
+
33
+ it "should parse entries" do
34
+ @feed.entries.size.should == 10
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Feedzirra::RSSEntry do
4
+ before(:each) do
5
+ # I don't really like doing it this way because these unit test should only rely on RSSEntry,
6
+ # but this is actually how it should work. You would never just pass entry xml straight to the AtomEnry
7
+ @entry = Feedzirra::RSS.parse(sample_rss_feed).entries.first
8
+ end
9
+
10
+ it "should parse the title" do
11
+ @entry.title.should == "Nokogiri’s Slop Feature"
12
+ end
13
+
14
+ it "should parse the url" do
15
+ @entry.url.should == "http://tenderlovemaking.com/2008/12/04/nokogiris-slop-feature/"
16
+ end
17
+
18
+ it "should parse the author" do
19
+ @entry.author.should == "Aaron Patterson"
20
+ end
21
+
22
+ it "should parse the content" do
23
+ @entry.content.should == sample_rss_entry_content
24
+ end
25
+
26
+ it "should provide a summary" do
27
+ @entry.summary.should == "Oops! When I released nokogiri version 1.0.7, I totally forgot to talk about Nokogiri::Slop() feature that was added. Why is it called \"slop\"? It lets you sloppily explore documents. Basically, it decorates your document with method_missing() that allows you to search your document via method calls.\nGiven this document:\n\ndoc = Nokogiri::Slop&#40;&#60;&#60;-eohtml&#41;\n&#60;html&#62;\n&#160; &#60;body&#62;\n&#160; [...]"
28
+ end
29
+
30
+ it "should parse the published date" do
31
+ @entry.published.to_s.should == "Thu Dec 04 17:17:49 UTC 2008"
32
+ end
33
+
34
+ it "should parse the categories" do
35
+ @entry.categories.should == ['computadora', 'nokogiri', 'rails']
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Feedzirra::RSS do
4
+ describe "#will_parse?" do
5
+ it "should return true for an RSS feed" do
6
+ Feedzirra::RSS.should be_able_to_parse(sample_rss_feed)
7
+ end
8
+
9
+ # this is no longer true. combined rdf and rss into one
10
+ # it "should return false for an rdf feed" do
11
+ # Feedzirra::RSS.should_not be_able_to_parse(sample_rdf_feed)
12
+ # end
13
+
14
+ it "should return fase for an atom feed" do
15
+ Feedzirra::RSS.should_not be_able_to_parse(sample_atom_feed)
16
+ end
17
+ end
18
+
19
+ describe "parsing" do
20
+ before(:each) do
21
+ @feed = Feedzirra::RSS.parse(sample_rss_feed)
22
+ end
23
+
24
+ it "should parse the title" do
25
+ @feed.title.should == "Tender Lovemaking"
26
+ end
27
+
28
+ it "should parse the url" do
29
+ @feed.url.should == "http://tenderlovemaking.com"
30
+ end
31
+
32
+ it "should provide an accessor for the feed_url" do
33
+ @feed.respond_to?(:feed_url).should == true
34
+ @feed.respond_to?(:feed_url=).should == true
35
+ end
36
+
37
+ it "should parse entries" do
38
+ @feed.entries.size.should == 10
39
+ end
40
+ end
41
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --diff
2
+ --color
@@ -0,0 +1,50 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ # gem install redgreen for colored test output
5
+ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
6
+
7
+ path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
8
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
9
+
10
+ require "lib/feedzirra"
11
+
12
+ def sample_atom_feed
13
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/AmazonWebServicesBlog.xml")
14
+ end
15
+
16
+ def sample_atom_entry_content
17
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/AmazonWebServicesBlogFirstEntryContent.xml")
18
+ end
19
+
20
+ def sample_itunes_feed
21
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/itunes.xml")
22
+ end
23
+
24
+ def sample_rdf_feed
25
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/HREFConsideredHarmful.xml")
26
+ end
27
+
28
+ def sample_rdf_entry_content
29
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/HREFConsideredHarmfulFirstEntry.xml")
30
+ end
31
+
32
+ def sample_rss_feed_burner_feed
33
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/SamHarrisAuthorPhilosopherEssayistAtheist.xml")
34
+ end
35
+
36
+ def sample_rss_feed
37
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/TenderLovemaking.xml")
38
+ end
39
+
40
+ def sample_rss_entry_content
41
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/TenderLovemakingFirstEntry.xml")
42
+ end
43
+
44
+ def sample_feedburner_atom_feed
45
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/PaulDixExplainsNothing.xml")
46
+ end
47
+
48
+ def sample_feedburner_atom_entry_content
49
+ File.read("#{File.dirname(__FILE__)}/sample_feeds/PaulDixExplainsNothingFirstEntryContent.xml")
50
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rickerbh-feedzirra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Paul Dix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: pauldix-sax-machine
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.9
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: taf2-curb
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.3
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: builder
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.1.2
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.0.0
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: mdalessio-dryopteris
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.0.0
74
+ version:
75
+ description:
76
+ email: paul@pauldix.net
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files: []
82
+
83
+ files:
84
+ - lib/core_ext/date.rb
85
+ - lib/feedzirra.rb
86
+ - lib/feedzirra/feed.rb
87
+ - lib/feedzirra/atom.rb
88
+ - lib/feedzirra/atom_entry.rb
89
+ - lib/feedzirra/atom_feed_burner.rb
90
+ - lib/feedzirra/atom_feed_burner_entry.rb
91
+ - lib/feedzirra/rdf.rb
92
+ - lib/feedzirra/rdf_entry.rb
93
+ - lib/feedzirra/rss.rb
94
+ - lib/feedzirra/rss_entry.rb
95
+ - lib/feedzirra/feed_utilities.rb
96
+ - lib/feedzirra/feed_entry_utilities.rb
97
+ - README.textile
98
+ - Rakefile
99
+ - spec/spec.opts
100
+ - spec/spec_helper.rb
101
+ - spec/feedzirra/feed_spec.rb
102
+ - spec/feedzirra/atom_spec.rb
103
+ - spec/feedzirra/atom_entry_spec.rb
104
+ - spec/feedzirra/atom_feed_burner_spec.rb
105
+ - spec/feedzirra/atom_feed_burner_entry_spec.rb
106
+ - spec/feedzirra/rdf_spec.rb
107
+ - spec/feedzirra/rdf_entry_spec.rb
108
+ - spec/feedzirra/rss_spec.rb
109
+ - spec/feedzirra/rss_entry_spec.rb
110
+ - spec/feedzirra/feed_utilities_spec.rb
111
+ - spec/feedzirra/feed_entry_utilities_spec.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/pauldix/feedzirra
114
+ post_install_message:
115
+ rdoc_options: []
116
+
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ version:
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: "0"
130
+ version:
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.2.0
135
+ signing_key:
136
+ specification_version: 2
137
+ summary: "A feed fetching and parsing library that treats the internet like Godzilla treats Japan: it dominates and eats all."
138
+ test_files: []
139
+