feedjira 2.2.0 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +635 -6
- data/.travis.yml +1 -1
- data/CHANGELOG.md +6 -12
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -5
- data/README.md +37 -99
- data/Rakefile +5 -5
- data/feedjira.gemspec +27 -19
- data/lib/feedjira.rb +69 -41
- data/lib/feedjira/configuration.rb +3 -8
- data/lib/feedjira/core_ext.rb +3 -3
- data/lib/feedjira/core_ext/date.rb +1 -1
- data/lib/feedjira/core_ext/time.rb +2 -2
- data/lib/feedjira/date_time_utilities.rb +2 -2
- data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +2 -2
- data/lib/feedjira/feed.rb +10 -80
- data/lib/feedjira/feed_entry_utilities.rb +4 -4
- data/lib/feedjira/parser.rb +4 -1
- data/lib/feedjira/parser/atom.rb +3 -3
- data/lib/feedjira/parser/atom_entry.rb +1 -1
- data/lib/feedjira/parser/atom_feed_burner.rb +4 -4
- data/lib/feedjira/parser/atom_feed_burner_entry.rb +1 -1
- data/lib/feedjira/parser/atom_youtube.rb +2 -2
- data/lib/feedjira/parser/atom_youtube_entry.rb +1 -1
- data/lib/feedjira/parser/google_docs_atom.rb +3 -3
- data/lib/feedjira/parser/google_docs_atom_entry.rb +1 -1
- data/lib/feedjira/parser/itunes_rss_item.rb +1 -1
- data/lib/feedjira/parser/json_feed.rb +39 -0
- data/lib/feedjira/parser/json_feed_item.rb +51 -0
- data/lib/feedjira/parser/podlove_chapter.rb +1 -1
- data/lib/feedjira/parser/rss.rb +1 -1
- data/lib/feedjira/parser/rss_entry.rb +5 -1
- data/lib/feedjira/parser/rss_feed_burner.rb +1 -1
- data/lib/feedjira/preprocessor.rb +1 -1
- data/lib/feedjira/version.rb +1 -1
- data/spec/feedjira/configuration_spec.rb +9 -16
- data/spec/feedjira/date_time_utilities_spec.rb +20 -20
- data/spec/feedjira/feed_entry_utilities_spec.rb +18 -18
- data/spec/feedjira/feed_spec.rb +15 -229
- data/spec/feedjira/feed_utilities_spec.rb +72 -72
- data/spec/feedjira/parser/atom_entry_spec.rb +34 -34
- data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +16 -16
- data/spec/feedjira/parser/atom_feed_burner_spec.rb +121 -119
- data/spec/feedjira/parser/atom_spec.rb +78 -76
- data/spec/feedjira/parser/atom_youtube_entry_spec.rb +38 -38
- data/spec/feedjira/parser/atom_youtube_spec.rb +15 -15
- data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +8 -8
- data/spec/feedjira/parser/google_docs_atom_spec.rb +23 -21
- data/spec/feedjira/parser/itunes_rss_item_spec.rb +37 -37
- data/spec/feedjira/parser/itunes_rss_owner_spec.rb +5 -5
- data/spec/feedjira/parser/itunes_rss_spec.rb +118 -116
- data/spec/feedjira/parser/json_feed_item_spec.rb +79 -0
- data/spec/feedjira/parser/json_feed_spec.rb +53 -0
- data/spec/feedjira/parser/podlove_chapter_spec.rb +12 -12
- data/spec/feedjira/parser/rss_entry_spec.rb +30 -30
- data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +32 -32
- data/spec/feedjira/parser/rss_feed_burner_spec.rb +47 -45
- data/spec/feedjira/parser/rss_spec.rb +36 -36
- data/spec/feedjira/preprocessor_spec.rb +6 -6
- data/spec/feedjira_spec.rb +145 -0
- data/spec/sample_feeds.rb +27 -26
- data/spec/sample_feeds/HuffPostCanada.xml +279 -0
- data/spec/sample_feeds/json_feed.json +156 -0
- data/spec/spec_helper.rb +5 -5
- metadata +31 -49
- data/fixtures/vcr_cassettes/fetch_failure.yml +0 -62
- data/fixtures/vcr_cassettes/parse_error.yml +0 -222
- data/fixtures/vcr_cassettes/success.yml +0 -281
- data/spec/sample_feeds/InvalidDateFormat.xml +0 -20
data/lib/feedjira/parser/rss.rb
CHANGED
@@ -14,7 +14,7 @@ module Feedjira
|
|
14
14
|
element :rss, as: :version, value: :version
|
15
15
|
element :title
|
16
16
|
element :ttl
|
17
|
-
elements :"atom:link", as: :hubs, value: :href, with: { rel:
|
17
|
+
elements :"atom:link", as: :hubs, value: :href, with: { rel: "hub" }
|
18
18
|
elements :item, as: :entries, class: RSSEntry
|
19
19
|
|
20
20
|
attr_accessor :feed_url
|
@@ -27,7 +27,11 @@ module Feedjira
|
|
27
27
|
elements :category, as: :categories
|
28
28
|
|
29
29
|
element :guid, as: :entry_id
|
30
|
-
element :"dc:identifier", as: :
|
30
|
+
element :"dc:identifier", as: :dc_identifier
|
31
|
+
|
32
|
+
def id
|
33
|
+
@entry_id ||= @dc_identifier || @url
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -9,7 +9,7 @@ module Feedjira
|
|
9
9
|
element :description
|
10
10
|
element :link, as: :url
|
11
11
|
element :lastBuildDate, as: :last_built
|
12
|
-
elements :"atom10:link", as: :hubs, value: :href, with: { rel:
|
12
|
+
elements :"atom10:link", as: :hubs, value: :href, with: { rel: "hub" }
|
13
13
|
elements :item, as: :entries, class: RSSFeedBurnerEntry
|
14
14
|
|
15
15
|
attr_accessor :feed_url
|
data/lib/feedjira/version.rb
CHANGED
@@ -1,25 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Feedjira::Configuration do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
Feedjira.configure { |config| config.follow_redirect_limit = 10 }
|
7
|
-
expect(Feedjira.follow_redirect_limit).to eq(10)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'sets request_timeout config' do
|
11
|
-
Feedjira.configure { |config| config.request_timeout = 45 }
|
12
|
-
expect(Feedjira.request_timeout).to eq(45)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'sets strip_whitespace config' do
|
4
|
+
describe ".configure" do
|
5
|
+
it "sets strip_whitespace config" do
|
16
6
|
Feedjira.configure { |config| config.strip_whitespace = true }
|
17
7
|
expect(Feedjira.strip_whitespace).to be true
|
18
8
|
end
|
19
9
|
|
20
|
-
it
|
21
|
-
|
22
|
-
|
10
|
+
it "allows parsers to be modified" do
|
11
|
+
CustomParser = Class.new
|
12
|
+
|
13
|
+
Feedjira.configure { |config| config.parsers.unshift(CustomParser) }
|
14
|
+
expect(Feedjira.parsers.first).to eq(CustomParser)
|
15
|
+
Feedjira.reset_configuration!
|
23
16
|
end
|
24
17
|
end
|
25
18
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Feedjira::FeedUtilities do
|
4
4
|
before(:each) do
|
@@ -7,41 +7,41 @@ describe Feedjira::FeedUtilities do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
12
|
-
time = @klass.new.parse_datetime(
|
10
|
+
describe "handling dates" do
|
11
|
+
it "should parse an ISO 8601 formatted datetime into Time" do
|
12
|
+
time = @klass.new.parse_datetime("2008-02-20T8:05:00-010:00")
|
13
13
|
expect(time.class).to eq Time
|
14
|
-
expect(time).to eq Time.parse_safely(
|
14
|
+
expect(time).to eq Time.parse_safely("Wed Feb 20 18:05:00 UTC 2008")
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
time = @klass.new.parse_datetime(
|
17
|
+
it "should parse a ISO 8601 with milliseconds into Time" do
|
18
|
+
time = @klass.new.parse_datetime("2013-09-17T08:20:13.931-04:00")
|
19
19
|
expect(time.class).to eq Time
|
20
|
-
expect(time).to eq Time.parse_safely(
|
20
|
+
expect(time).to eq Time.parse_safely("Tue Sep 17 12:20:13 UTC 2013")
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
time = @klass.new.parse_datetime(
|
23
|
+
it "should parse a US Format into Time" do
|
24
|
+
time = @klass.new.parse_datetime("8/23/2016 12:29:58 PM")
|
25
25
|
expect(time.class).to eq Time
|
26
|
-
expect(time).to eq Time.parse_safely(
|
26
|
+
expect(time).to eq Time.parse_safely("Wed Aug 23 12:29:58 UTC 2016")
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
time = @klass.new.parse_datetime(
|
29
|
+
it "should parse a Spanish Format into Time" do
|
30
|
+
time = @klass.new.parse_datetime("Wed, 31 Ago 2016 11:08:22 GMT")
|
31
31
|
expect(time.class).to eq Time
|
32
|
-
expect(time).to eq Time.parse_safely(
|
32
|
+
expect(time).to eq Time.parse_safely("Wed Aug 31 11:08:22 UTC 2016")
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
time = @klass.new.parse_datetime(
|
35
|
+
it "should parse Format with japanese symbols into Time" do
|
36
|
+
time = @klass.new.parse_datetime("水, 31 8 2016 07:37:00 PDT")
|
37
37
|
expect(time.class).to eq Time
|
38
|
-
expect(time).to eq Time.parse_safely(
|
38
|
+
expect(time).to eq Time.parse_safely("Wed Aug 31 14:37:00 UTC 2016")
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
time = @klass.new.parse_datetime(
|
41
|
+
it "should parse epoch into Time" do
|
42
|
+
time = @klass.new.parse_datetime("1472654220")
|
43
43
|
expect(time.class).to eq Time
|
44
|
-
expect(time).to eq Time.parse_safely(
|
44
|
+
expect(time).to eq Time.parse_safely("Wed Aug 31 14:37:00 UTC 2016")
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Feedjira::FeedUtilities do
|
4
4
|
before(:each) do
|
@@ -7,23 +7,23 @@ describe Feedjira::FeedUtilities do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
12
|
-
time = @klass.new.parse_datetime(
|
10
|
+
describe "handling dates" do
|
11
|
+
it "should parse an ISO 8601 formatted datetime into Time" do
|
12
|
+
time = @klass.new.parse_datetime("2008-02-20T8:05:00-010:00")
|
13
13
|
expect(time.class).to eq Time
|
14
|
-
expect(time).to eq Time.parse_safely(
|
14
|
+
expect(time).to eq Time.parse_safely("Wed Feb 20 18:05:00 UTC 2008")
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
time = @klass.new.parse_datetime(
|
17
|
+
it "should parse a ISO 8601 with milliseconds into Time" do
|
18
|
+
time = @klass.new.parse_datetime("2013-09-17T08:20:13.931-04:00")
|
19
19
|
expect(time.class).to eq Time
|
20
|
-
expect(time).to eq Time.parse_safely(
|
20
|
+
expect(time).to eq Time.parse_safely("Tue Sep 17 12:20:13 UTC 2013")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
24
|
+
describe "sanitizing" do
|
25
25
|
before(:each) do
|
26
|
-
@feed = Feedjira
|
26
|
+
@feed = Feedjira.parse(sample_atom_feed)
|
27
27
|
@entry = @feed.entries.first
|
28
28
|
end
|
29
29
|
|
@@ -31,15 +31,15 @@ describe Feedjira::FeedUtilities do
|
|
31
31
|
expect { @klass.new.sanitize! }.to_not raise_error
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
new_title =
|
34
|
+
it "should provide a sanitized title" do
|
35
|
+
new_title = "<script>this is not safe</script>" + @entry.title
|
36
36
|
@entry.title = new_title
|
37
37
|
scrubbed_title = Loofah.scrub_fragment(new_title, :prune).to_s
|
38
38
|
expect(@entry.title.sanitize).to eq scrubbed_title
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
new_content =
|
41
|
+
it "should sanitize content in place" do
|
42
|
+
new_content = "<script>" + @entry.content
|
43
43
|
@entry.content = new_content.dup
|
44
44
|
|
45
45
|
scrubbed_content = Loofah.scrub_fragment(new_content, :prune).to_s
|
@@ -48,10 +48,10 @@ describe Feedjira::FeedUtilities do
|
|
48
48
|
expect(@entry.content).to eq scrubbed_content
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
@entry.title +=
|
53
|
-
@entry.author +=
|
54
|
-
@entry.content +=
|
51
|
+
it "should sanitize things in place" do
|
52
|
+
@entry.title += "<script>"
|
53
|
+
@entry.author += "<script>"
|
54
|
+
@entry.content += "<script>"
|
55
55
|
|
56
56
|
cleaned_title = Loofah.scrub_fragment(@entry.title, :prune).to_s
|
57
57
|
cleaned_author = Loofah.scrub_fragment(@entry.author, :prune).to_s
|
data/spec/feedjira/feed_spec.rb
CHANGED
@@ -1,263 +1,49 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
# rubocop:disable Style/BlockDelimiters
|
1
|
+
require "spec_helper"
|
4
2
|
|
5
3
|
class Hell < StandardError; end
|
6
4
|
|
7
5
|
class FailParser
|
8
6
|
def self.parse(_, &on_failure)
|
9
|
-
on_failure.call
|
7
|
+
on_failure.call "this parser always fails."
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
13
11
|
describe Feedjira::Feed do
|
14
|
-
describe
|
15
|
-
it 'raises an error when the fetch fails' do
|
16
|
-
VCR.use_cassette('fetch_failure') do
|
17
|
-
url = 'http://www.example.com/feed.xml'
|
18
|
-
expect {
|
19
|
-
Feedjira::Feed.fetch_and_parse url
|
20
|
-
}.to raise_error Feedjira::FetchFailure
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'raises an error when no parser can be found' do
|
25
|
-
VCR.use_cassette('parse_error') do
|
26
|
-
url = 'http://feedjira.com'
|
27
|
-
expect {
|
28
|
-
Feedjira::Feed.fetch_and_parse url
|
29
|
-
}.to raise_error Feedjira::NoParserAvailable
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'fetches and parses the feed' do
|
34
|
-
VCR.use_cassette('success') do
|
35
|
-
url = 'http://feedjira.com/blog/feed.xml'
|
36
|
-
expected_time = DateTime.parse('Fri, 07 Oct 2016 14:37:00 GMT').to_time
|
37
|
-
feed = Feedjira::Feed.fetch_and_parse url
|
38
|
-
|
39
|
-
expect(feed.class).to eq Feedjira::Parser::Atom
|
40
|
-
expect(feed.entries.count).to eq 4
|
41
|
-
expect(feed.feed_url).to eq url
|
42
|
-
expect(feed.etag).to eq('393e-53e4757c9db00-gzip')
|
43
|
-
expect(feed.last_modified).to eq(expected_time)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#add_common_feed_element' do
|
12
|
+
describe "#add_common_feed_element" do
|
49
13
|
before(:all) do
|
50
|
-
Feedjira::Feed.add_common_feed_element(
|
14
|
+
Feedjira::Feed.add_common_feed_element("generator")
|
51
15
|
end
|
52
16
|
|
53
|
-
it
|
54
|
-
expect(Feedjira
|
17
|
+
it "should parse the added element out of Atom feeds" do
|
18
|
+
expect(Feedjira.parse(sample_wfw_feed).generator).to eq "TypePad"
|
55
19
|
end
|
56
20
|
|
57
|
-
it
|
21
|
+
it "should parse the added element out of Atom Feedburner feeds" do
|
58
22
|
expect(Feedjira::Parser::Atom.new).to respond_to(:generator)
|
59
23
|
end
|
60
24
|
|
61
|
-
it
|
25
|
+
it "should parse the added element out of RSS feeds" do
|
62
26
|
expect(Feedjira::Parser::RSS.new).to respond_to(:generator)
|
63
27
|
end
|
64
28
|
end
|
65
29
|
|
66
|
-
describe
|
30
|
+
describe "#add_common_feed_entry_element" do
|
67
31
|
before(:all) do
|
68
|
-
tag =
|
32
|
+
tag = "wfw:commentRss"
|
69
33
|
Feedjira::Feed.add_common_feed_entry_element tag, as: :comment_rss
|
70
34
|
end
|
71
35
|
|
72
|
-
it
|
73
|
-
entry = Feedjira
|
74
|
-
expect(entry.comment_rss).to eq
|
36
|
+
it "should parse the added element out of Atom feeds entries" do
|
37
|
+
entry = Feedjira.parse(sample_wfw_feed).entries.first
|
38
|
+
expect(entry.comment_rss).to eq "this is the new val"
|
75
39
|
end
|
76
40
|
|
77
|
-
it
|
41
|
+
it "should parse the added element out of Atom Feedburner feeds entries" do
|
78
42
|
expect(Feedjira::Parser::AtomEntry.new).to respond_to(:comment_rss)
|
79
43
|
end
|
80
44
|
|
81
|
-
it
|
45
|
+
it "should parse the added element out of RSS feeds entries" do
|
82
46
|
expect(Feedjira::Parser::RSSEntry.new).to respond_to(:comment_rss)
|
83
47
|
end
|
84
48
|
end
|
85
|
-
|
86
|
-
describe '#parse_with' do
|
87
|
-
let(:xml) { '<xml></xml>' }
|
88
|
-
|
89
|
-
it 'invokes the parser and passes the xml' do
|
90
|
-
parser = double 'Parser', parse: nil
|
91
|
-
expect(parser).to receive(:parse).with xml
|
92
|
-
Feedjira::Feed.parse_with parser, xml
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'with a callback block' do
|
96
|
-
it 'passes the callback to the parser' do
|
97
|
-
callback = ->(*) { raise Hell }
|
98
|
-
|
99
|
-
expect do
|
100
|
-
Feedjira::Feed.parse_with FailParser, xml, &callback
|
101
|
-
end.to raise_error Hell
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#parse' do
|
107
|
-
context "when there's an available parser" do
|
108
|
-
it 'should parse an rdf feed' do
|
109
|
-
feed = Feedjira::Feed.parse(sample_rdf_feed)
|
110
|
-
expect(feed.title).to eq 'HREF Considered Harmful'
|
111
|
-
published = Time.parse_safely('Tue Sep 02 19:50:07 UTC 2008')
|
112
|
-
expect(feed.entries.first.published).to eq published
|
113
|
-
expect(feed.entries.size).to eq 10
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should parse an rss feed' do
|
117
|
-
feed = Feedjira::Feed.parse(sample_rss_feed)
|
118
|
-
expect(feed.title).to eq 'Tender Lovemaking'
|
119
|
-
published = Time.parse_safely 'Thu Dec 04 17:17:49 UTC 2008'
|
120
|
-
expect(feed.entries.first.published).to eq published
|
121
|
-
expect(feed.entries.size).to eq 10
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should parse an atom feed' do
|
125
|
-
feed = Feedjira::Feed.parse(sample_atom_feed)
|
126
|
-
expect(feed.title).to eq 'Amazon Web Services Blog'
|
127
|
-
published = Time.parse_safely 'Fri Jan 16 18:21:00 UTC 2009'
|
128
|
-
expect(feed.entries.first.published).to eq published
|
129
|
-
expect(feed.entries.size).to eq 10
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should parse an feedburner atom feed' do
|
133
|
-
feed = Feedjira::Feed.parse(sample_feedburner_atom_feed)
|
134
|
-
expect(feed.title).to eq 'Paul Dix Explains Nothing'
|
135
|
-
published = Time.parse_safely 'Thu Jan 22 15:50:22 UTC 2009'
|
136
|
-
expect(feed.entries.first.published).to eq published
|
137
|
-
expect(feed.entries.size).to eq 5
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should parse an itunes feed' do
|
141
|
-
feed = Feedjira::Feed.parse(sample_itunes_feed)
|
142
|
-
expect(feed.title).to eq 'All About Everything'
|
143
|
-
published = Time.parse_safely 'Wed, 15 Jun 2005 19:00:00 GMT'
|
144
|
-
expect(feed.entries.first.published).to eq published
|
145
|
-
expect(feed.entries.size).to eq 3
|
146
|
-
end
|
147
|
-
|
148
|
-
# rubocop:disable Metrics/LineLength
|
149
|
-
it 'does not fail if multiple published dates exist and some are unparseable' do
|
150
|
-
expect(Feedjira.logger).to receive(:warn).once
|
151
|
-
|
152
|
-
feed = Feedjira::Feed.parse(sample_invalid_date_format_feed)
|
153
|
-
expect(feed.title).to eq 'Invalid date format feed'
|
154
|
-
published = Time.parse_safely 'Mon, 16 Oct 2017 15:10:00 GMT'
|
155
|
-
expect(feed.entries.first.published).to eq published
|
156
|
-
expect(feed.entries.size).to eq 2
|
157
|
-
end
|
158
|
-
# rubocop:enable Metrics/LineLength
|
159
|
-
end
|
160
|
-
|
161
|
-
context "when there's no available parser" do
|
162
|
-
it 'raises Feedjira::NoParserAvailable' do
|
163
|
-
expect {
|
164
|
-
Feedjira::Feed.parse("I'm an invalid feed")
|
165
|
-
}.to raise_error(Feedjira::NoParserAvailable)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'should parse an feedburner rss feed' do
|
170
|
-
feed = Feedjira::Feed.parse(sample_rss_feed_burner_feed)
|
171
|
-
expect(feed.title).to eq 'TechCrunch'
|
172
|
-
published = Time.parse_safely 'Wed Nov 02 17:25:27 UTC 2011'
|
173
|
-
expect(feed.entries.first.published).to eq published
|
174
|
-
expect(feed.entries.size).to eq 20
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe '#determine_feed_parser_for_xml' do
|
179
|
-
it 'with Google Docs atom feed it returns the GoogleDocsAtom parser' do
|
180
|
-
xml = sample_google_docs_list_feed
|
181
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
182
|
-
expect(actual_parser).to eq Feedjira::Parser::GoogleDocsAtom
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'with an atom feed it returns the Atom parser' do
|
186
|
-
xml = sample_atom_feed
|
187
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
188
|
-
expect(actual_parser).to eq Feedjira::Parser::Atom
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'with an atom feedburner feed it returns the AtomFeedBurner parser' do
|
192
|
-
xml = sample_feedburner_atom_feed
|
193
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
194
|
-
expect(actual_parser).to eq Feedjira::Parser::AtomFeedBurner
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'with an rdf feed it returns the RSS parser' do
|
198
|
-
xml = sample_rdf_feed
|
199
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
200
|
-
expect(actual_parser).to eq Feedjira::Parser::RSS
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'with an rss feedburner feed it returns the RSSFeedBurner parser' do
|
204
|
-
xml = sample_rss_feed_burner_feed
|
205
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
206
|
-
expect(actual_parser).to eq Feedjira::Parser::RSSFeedBurner
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'with an rss 2.0 feed it returns the RSS parser' do
|
210
|
-
xml = sample_rss_feed
|
211
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
212
|
-
expect(actual_parser).to eq Feedjira::Parser::RSS
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'with an itunes feed it returns the RSS parser' do
|
216
|
-
xml = sample_itunes_feed
|
217
|
-
actual_parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
218
|
-
expect(actual_parser).to eq Feedjira::Parser::ITunesRSS
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe 'when adding feed types' do
|
223
|
-
it 'should prioritize added types over the built in ones' do
|
224
|
-
xml = 'Atom asdf'
|
225
|
-
allow(Feedjira::Parser::Atom).to receive(:able_to_parse?).and_return(true)
|
226
|
-
new_parser = Class.new do
|
227
|
-
def self.able_to_parse?(_)
|
228
|
-
true
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
expect(new_parser).to be_able_to_parse(xml)
|
233
|
-
|
234
|
-
Feedjira::Feed.add_feed_class(new_parser)
|
235
|
-
|
236
|
-
parser = Feedjira::Feed.determine_feed_parser_for_xml xml
|
237
|
-
expect(parser).to eq new_parser
|
238
|
-
|
239
|
-
Feedjira::Feed.reset_parsers!
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe 'when parsers are configured' do
|
244
|
-
it 'does not use default parsers' do
|
245
|
-
xml = 'Atom asdf'
|
246
|
-
new_parser = Class.new do
|
247
|
-
def self.able_to_parse?(_)
|
248
|
-
true
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
Feedjira.configure { |config| config.parsers = [new_parser] }
|
253
|
-
|
254
|
-
parser = Feedjira::Feed.determine_feed_parser_for_xml(xml)
|
255
|
-
expect(parser).to eq(new_parser)
|
256
|
-
|
257
|
-
Feedjira.reset_configuration!
|
258
|
-
Feedjira::Feed.reset_parsers!
|
259
|
-
end
|
260
|
-
end
|
261
49
|
end
|
262
|
-
|
263
|
-
# rubocop:enable Style/BlockDelimiters
|