feedjira 2.2.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/feed-parsing.md +15 -0
- data/.rubocop.yml +32 -8
- data/.rubocop_todo.yml +11 -0
- data/.travis.yml +3 -7
- data/CHANGELOG.md +18 -9
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -5
- data/README.md +46 -99
- data/Rakefile +8 -6
- data/feedjira.gemspec +31 -20
- data/lib/feedjira.rb +75 -41
- data/lib/feedjira/atom_entry_utilities.rb +51 -0
- data/lib/feedjira/configuration.rb +8 -10
- data/lib/feedjira/core_ext.rb +5 -3
- data/lib/feedjira/core_ext/date.rb +2 -1
- data/lib/feedjira/core_ext/string.rb +2 -1
- data/lib/feedjira/core_ext/time.rb +12 -12
- data/lib/feedjira/date_time_utilities.rb +8 -10
- data/lib/feedjira/date_time_utilities/date_time_epoch_parser.rb +3 -2
- data/lib/feedjira/date_time_utilities/date_time_language_parser.rb +4 -4
- data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +11 -15
- data/lib/feedjira/feed.rb +12 -82
- data/lib/feedjira/feed_entry_utilities.rb +14 -7
- data/lib/feedjira/feed_utilities.rb +5 -4
- data/lib/feedjira/parser.rb +6 -1
- data/lib/feedjira/parser/atom.rb +6 -5
- data/lib/feedjira/parser/atom_entry.rb +4 -21
- data/lib/feedjira/parser/atom_feed_burner.rb +7 -6
- data/lib/feedjira/parser/atom_feed_burner_entry.rb +7 -18
- data/lib/feedjira/parser/atom_google_alerts.rb +26 -0
- data/lib/feedjira/parser/atom_google_alerts_entry.rb +21 -0
- data/lib/feedjira/parser/atom_youtube.rb +4 -3
- data/lib/feedjira/parser/atom_youtube_entry.rb +9 -8
- data/lib/feedjira/parser/globally_unique_identifier.rb +21 -0
- data/lib/feedjira/parser/google_docs_atom.rb +6 -6
- data/lib/feedjira/parser/google_docs_atom_entry.rb +3 -19
- data/lib/feedjira/parser/itunes_rss.rb +4 -3
- data/lib/feedjira/parser/itunes_rss_category.rb +6 -5
- data/lib/feedjira/parser/itunes_rss_item.rb +5 -8
- data/lib/feedjira/parser/itunes_rss_owner.rb +2 -1
- data/lib/feedjira/parser/json_feed.rb +41 -0
- data/lib/feedjira/parser/json_feed_item.rb +57 -0
- data/lib/feedjira/parser/podlove_chapter.rb +4 -3
- data/lib/feedjira/parser/rss.rb +5 -3
- data/lib/feedjira/parser/rss_entry.rb +3 -24
- data/lib/feedjira/parser/rss_feed_burner.rb +4 -3
- data/lib/feedjira/parser/rss_feed_burner_entry.rb +6 -26
- data/lib/feedjira/parser/rss_image.rb +2 -0
- data/lib/feedjira/preprocessor.rb +4 -4
- data/lib/feedjira/rss_entry_utilities.rb +53 -0
- data/lib/feedjira/version.rb +3 -1
- data/spec/feedjira/configuration_spec.rb +11 -16
- data/spec/feedjira/date_time_utilities_spec.rb +22 -20
- data/spec/feedjira/feed_entry_utilities_spec.rb +20 -18
- data/spec/feedjira/feed_spec.rb +17 -229
- data/spec/feedjira/feed_utilities_spec.rb +75 -73
- data/spec/feedjira/parser/atom_entry_spec.rb +41 -38
- data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +22 -20
- data/spec/feedjira/parser/atom_feed_burner_spec.rb +122 -118
- data/spec/feedjira/parser/atom_google_alerts_entry_spec.rb +34 -0
- data/spec/feedjira/parser/atom_google_alerts_spec.rb +62 -0
- data/spec/feedjira/parser/atom_spec.rb +83 -77
- data/spec/feedjira/parser/atom_youtube_entry_spec.rb +41 -39
- data/spec/feedjira/parser/atom_youtube_spec.rb +21 -19
- data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +10 -8
- data/spec/feedjira/parser/google_docs_atom_spec.rb +25 -21
- data/spec/feedjira/parser/itunes_rss_item_spec.rb +39 -37
- data/spec/feedjira/parser/itunes_rss_owner_spec.rb +7 -5
- data/spec/feedjira/parser/itunes_rss_spec.rb +120 -116
- data/spec/feedjira/parser/json_feed_item_spec.rb +81 -0
- data/spec/feedjira/parser/json_feed_spec.rb +55 -0
- data/spec/feedjira/parser/podlove_chapter_spec.rb +14 -12
- data/spec/feedjira/parser/rss_entry_spec.rb +56 -34
- data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +36 -34
- data/spec/feedjira/parser/rss_feed_burner_spec.rb +49 -45
- data/spec/feedjira/parser/rss_spec.rb +38 -36
- data/spec/feedjira/preprocessor_spec.rb +9 -7
- data/spec/feedjira_spec.rb +166 -0
- data/spec/sample_feeds.rb +32 -29
- data/spec/sample_feeds/HuffPostCanada.xml +279 -0
- data/spec/sample_feeds/Permalinks.xml +22 -0
- data/spec/sample_feeds/a10.xml +72 -0
- data/spec/sample_feeds/google_alerts_atom.xml +1 -0
- data/spec/sample_feeds/json_feed.json +156 -0
- data/spec/spec_helper.rb +7 -5
- metadata +59 -70
- data/Dangerfile +0 -1
- 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
|
@@ -1,62 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
describe '#will_parse?' do
|
|
5
|
-
it 'should return true for a feedburner rss feed' do
|
|
6
|
-
expect(RSSFeedBurner).to be_able_to_parse sample_rss_feed_burner_feed
|
|
7
|
-
end
|
|
3
|
+
require "spec_helper"
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
module Feedjira
|
|
6
|
+
module Parser
|
|
7
|
+
describe "#will_parse?" do
|
|
8
|
+
it "should return true for a feedburner rss feed" do
|
|
9
|
+
expect(RSSFeedBurner).to be_able_to_parse sample_rss_feed_burner_feed
|
|
10
|
+
end
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
it "should return false for a regular RSS feed" do
|
|
13
|
+
expect(RSSFeedBurner).to_not be_able_to_parse sample_rss_feed
|
|
14
|
+
end
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
it "should return false for a feedburner atom feed" do
|
|
17
|
+
expect(RSSFeedBurner).to_not be_able_to_parse sample_feedburner_atom_feed
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
20
|
+
it "should return false for an rdf feed" do
|
|
21
|
+
expect(RSSFeedBurner).to_not be_able_to_parse sample_rdf_feed
|
|
22
|
+
end
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
it "should return false for a regular atom feed" do
|
|
25
|
+
expect(RSSFeedBurner).to_not be_able_to_parse sample_atom_feed
|
|
26
|
+
end
|
|
29
27
|
end
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
describe "parsing" do
|
|
30
|
+
before(:each) do
|
|
31
|
+
@feed = RSSFeedBurner.parse(sample_rss_feed_burner_feed)
|
|
32
|
+
end
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
end
|
|
34
|
+
it "should parse the title" do
|
|
35
|
+
expect(@feed.title).to eq "TechCrunch"
|
|
36
|
+
end
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
it "should parse the description" do
|
|
39
|
+
description = "TechCrunch is a group-edited blog that profiles the companies, products and events defining and transforming the new web."
|
|
40
|
+
expect(@feed.description).to eq description
|
|
41
|
+
end
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
it "should parse the url" do
|
|
44
|
+
expect(@feed.url).to eq "http://techcrunch.com"
|
|
45
|
+
end
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
end
|
|
47
|
+
it "should parse the last build date" do
|
|
48
|
+
expect(@feed.last_built).to eq "Wed, 02 Nov 2011 17:29:59 +0000"
|
|
49
|
+
end
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
it "should parse the hub urls" do
|
|
52
|
+
expect(@feed.hubs.count).to eq 2
|
|
53
|
+
expect(@feed.hubs.first).to eq "http://pubsubhubbub.appspot.com/"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should provide an accessor for the feed_url" do
|
|
57
|
+
expect(@feed).to respond_to :feed_url
|
|
58
|
+
expect(@feed).to respond_to :feed_url=
|
|
59
|
+
end
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
it "should parse entries" do
|
|
62
|
+
expect(@feed.entries.size).to eq 20
|
|
63
|
+
end
|
|
60
64
|
end
|
|
61
65
|
end
|
|
62
66
|
end
|
|
@@ -1,89 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Feedjira::Parser::RSS do
|
|
4
|
-
describe
|
|
5
|
-
it
|
|
6
|
+
describe "#will_parse?" do
|
|
7
|
+
it "should return true for an RSS feed" do
|
|
6
8
|
expect(Feedjira::Parser::RSS).to be_able_to_parse(sample_rss_feed)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
it
|
|
11
|
+
it "should return false for an atom feed" do
|
|
10
12
|
expect(Feedjira::Parser::RSS).to_not be_able_to_parse(sample_atom_feed)
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
it
|
|
15
|
+
it "should return false for an rss feedburner feed" do
|
|
14
16
|
able = Feedjira::Parser::RSS.able_to_parse? sample_rss_feed_burner_feed
|
|
15
17
|
expect(able).to eq false
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
describe
|
|
21
|
+
describe "parsing" do
|
|
20
22
|
before(:each) do
|
|
21
23
|
@feed = Feedjira::Parser::RSS.parse(sample_rss_feed)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
it
|
|
25
|
-
expect(@feed.version).to eq
|
|
26
|
+
it "should parse the version" do
|
|
27
|
+
expect(@feed.version).to eq "2.0"
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
it
|
|
29
|
-
expect(@feed.title).to eq
|
|
30
|
+
it "should parse the title" do
|
|
31
|
+
expect(@feed.title).to eq "Tender Lovemaking"
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
it
|
|
33
|
-
expect(@feed.description).to eq
|
|
34
|
+
it "should parse the description" do
|
|
35
|
+
expect(@feed.description).to eq "The act of making love, tenderly."
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
it
|
|
37
|
-
expect(@feed.url).to eq
|
|
38
|
+
it "should parse the url" do
|
|
39
|
+
expect(@feed.url).to eq "http://tenderlovemaking.com"
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
it
|
|
41
|
-
expect(@feed.ttl).to eq
|
|
42
|
+
it "should parse the ttl" do
|
|
43
|
+
expect(@feed.ttl).to eq "60"
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
it
|
|
45
|
-
expect(@feed.last_built).to eq
|
|
46
|
+
it "should parse the last build date" do
|
|
47
|
+
expect(@feed.last_built).to eq "Sat, 07 Sep 2002 09:42:31 GMT"
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
it
|
|
50
|
+
it "should parse the hub urls" do
|
|
49
51
|
expect(@feed.hubs.count).to eq 1
|
|
50
|
-
expect(@feed.hubs.first).to eq
|
|
52
|
+
expect(@feed.hubs.first).to eq "http://pubsubhubbub.appspot.com/"
|
|
51
53
|
end
|
|
52
54
|
|
|
53
|
-
it
|
|
55
|
+
it "should provide an accessor for the feed_url" do
|
|
54
56
|
expect(@feed).to respond_to :feed_url
|
|
55
57
|
expect(@feed).to respond_to :feed_url=
|
|
56
58
|
end
|
|
57
59
|
|
|
58
|
-
it
|
|
59
|
-
expect(@feed.language).to eq
|
|
60
|
+
it "should parse the language" do
|
|
61
|
+
expect(@feed.language).to eq "en"
|
|
60
62
|
end
|
|
61
63
|
|
|
62
|
-
it
|
|
63
|
-
expect(@feed.image.url).to eq
|
|
64
|
+
it "should parse the image url" do
|
|
65
|
+
expect(@feed.image.url).to eq "https://tenderlovemaking.com/images/header-logo-text-trimmed.png"
|
|
64
66
|
end
|
|
65
67
|
|
|
66
|
-
it
|
|
67
|
-
expect(@feed.image.title).to eq
|
|
68
|
+
it "should parse the image title" do
|
|
69
|
+
expect(@feed.image.title).to eq "Tender Lovemaking"
|
|
68
70
|
end
|
|
69
71
|
|
|
70
|
-
it
|
|
71
|
-
expect(@feed.image.link).to eq
|
|
72
|
+
it "should parse the image link" do
|
|
73
|
+
expect(@feed.image.link).to eq "http://tenderlovemaking.com"
|
|
72
74
|
end
|
|
73
75
|
|
|
74
|
-
it
|
|
75
|
-
expect(@feed.image.width).to eq
|
|
76
|
+
it "should parse the image width" do
|
|
77
|
+
expect(@feed.image.width).to eq "766"
|
|
76
78
|
end
|
|
77
79
|
|
|
78
|
-
it
|
|
79
|
-
expect(@feed.image.height).to eq
|
|
80
|
+
it "should parse the image height" do
|
|
81
|
+
expect(@feed.image.height).to eq "138"
|
|
80
82
|
end
|
|
81
83
|
|
|
82
|
-
it
|
|
83
|
-
expect(@feed.image.description).to eq
|
|
84
|
+
it "should parse the image description" do
|
|
85
|
+
expect(@feed.image.description).to eq "The act of making love, tenderly."
|
|
84
86
|
end
|
|
85
87
|
|
|
86
|
-
it
|
|
88
|
+
it "should parse entries" do
|
|
87
89
|
expect(@feed.entries.size).to eq 10
|
|
88
90
|
end
|
|
89
91
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Feedjira::Preprocessor do
|
|
4
|
-
it
|
|
5
|
-
xml =
|
|
6
|
+
it "returns the xml as parsed by Nokogiri" do
|
|
7
|
+
xml = "<xml></xml>"
|
|
6
8
|
doc = Nokogiri::XML(xml).remove_namespaces!
|
|
7
9
|
processor = Feedjira::Preprocessor.new xml
|
|
8
10
|
escaped = processor.to_xml
|
|
@@ -10,7 +12,7 @@ describe Feedjira::Preprocessor do
|
|
|
10
12
|
expect(escaped).to eq doc.to_xml
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
it
|
|
15
|
+
it "escapes markup in xhtml content" do
|
|
14
16
|
processor = Feedjira::Preprocessor.new sample_atom_xhtml_feed
|
|
15
17
|
escaped = processor.to_xml
|
|
16
18
|
escaped_parts = escaped.split "\n"
|
|
@@ -20,10 +22,10 @@ describe Feedjira::Preprocessor do
|
|
|
20
22
|
expect(escaped_parts[26]).to match(/<p>$/) # content
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
it
|
|
24
|
-
processor = Feedjira::Preprocessor.new(sample_atom_xhtml_with_escpaed_html_in_pre_tag_feed)
|
|
25
|
+
it "leaves escaped html within pre tag" do
|
|
26
|
+
processor = Feedjira::Preprocessor.new(sample_atom_xhtml_with_escpaed_html_in_pre_tag_feed)
|
|
25
27
|
escaped = processor.to_xml
|
|
26
|
-
expected_pre_tag =
|
|
28
|
+
expected_pre_tag = " <pre>&lt;b&gt;test&lt;b&gt;</pre>"
|
|
27
29
|
expect(escaped.split("\n")[7]).to eq(expected_pre_tag)
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Feedjira do
|
|
6
|
+
describe ".parse" do
|
|
7
|
+
context "allows the parser to be specified" do
|
|
8
|
+
it "should parse an rss feed" do
|
|
9
|
+
parser = Feedjira.parser_for_xml(sample_rss_feed)
|
|
10
|
+
feed = Feedjira.parse(sample_rss_feed, parser: parser)
|
|
11
|
+
|
|
12
|
+
expect(feed.title).to eq "Tender Lovemaking"
|
|
13
|
+
published = Time.parse_safely "Thu Dec 04 17:17:49 UTC 2008"
|
|
14
|
+
expect(feed.entries.first.published).to eq published
|
|
15
|
+
expect(feed.entries.size).to eq 10
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when there's an available parser" do
|
|
20
|
+
it "should parse an rdf feed" do
|
|
21
|
+
feed = Feedjira.parse(sample_rdf_feed)
|
|
22
|
+
expect(feed.title).to eq "HREF Considered Harmful"
|
|
23
|
+
published = Time.parse_safely("Tue Sep 02 19:50:07 UTC 2008")
|
|
24
|
+
expect(feed.entries.first.published).to eq published
|
|
25
|
+
expect(feed.entries.size).to eq 10
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should parse an rss feed" do
|
|
29
|
+
feed = Feedjira.parse(sample_rss_feed)
|
|
30
|
+
expect(feed.title).to eq "Tender Lovemaking"
|
|
31
|
+
published = Time.parse_safely "Thu Dec 04 17:17:49 UTC 2008"
|
|
32
|
+
expect(feed.entries.first.published).to eq published
|
|
33
|
+
expect(feed.entries.size).to eq 10
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should parse an atom feed" do
|
|
37
|
+
feed = Feedjira.parse(sample_atom_feed)
|
|
38
|
+
expect(feed.title).to eq "Amazon Web Services Blog"
|
|
39
|
+
published = Time.parse_safely "Fri Jan 16 18:21:00 UTC 2009"
|
|
40
|
+
expect(feed.entries.first.published).to eq published
|
|
41
|
+
expect(feed.entries.size).to eq 10
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should parse an feedburner atom feed" do
|
|
45
|
+
feed = Feedjira.parse(sample_feedburner_atom_feed)
|
|
46
|
+
expect(feed.title).to eq "Paul Dix Explains Nothing"
|
|
47
|
+
published = Time.parse_safely "Thu Jan 22 15:50:22 UTC 2009"
|
|
48
|
+
expect(feed.entries.first.published).to eq published
|
|
49
|
+
expect(feed.entries.size).to eq 5
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should parse an itunes feed" do
|
|
53
|
+
feed = Feedjira.parse(sample_itunes_feed)
|
|
54
|
+
expect(feed.title).to eq "All About Everything"
|
|
55
|
+
published = Time.parse_safely "Wed, 15 Jun 2005 19:00:00 GMT"
|
|
56
|
+
expect(feed.entries.first.published).to eq published
|
|
57
|
+
expect(feed.entries.size).to eq 3
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "with nested dc:identifier it does not overwrite entry_id" do
|
|
61
|
+
feed = Feedjira.parse(sample_rss_feed_huffpost_ca)
|
|
62
|
+
expect(feed.title.strip).to eq "HuffPost Canada - Athena2 - All Posts"
|
|
63
|
+
expect(feed.entries.size).to eq 2
|
|
64
|
+
expect(feed.entries.first.id).to eq "23246627"
|
|
65
|
+
expect(feed.entries.last.id.strip).to eq "1"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "does not fail if multiple published dates exist and some are unparseable" do
|
|
69
|
+
expect(Feedjira.logger).to receive(:warn).twice
|
|
70
|
+
|
|
71
|
+
feed = Feedjira.parse(sample_invalid_date_format_feed)
|
|
72
|
+
expect(feed.title).to eq "Invalid date format feed"
|
|
73
|
+
published = Time.parse_safely "Mon, 16 Oct 2017 15:10:00 GMT"
|
|
74
|
+
expect(feed.entries.first.published).to eq published
|
|
75
|
+
expect(feed.entries.size).to eq 2
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "when there's no available parser" do
|
|
80
|
+
it "raises Feedjira::NoParserAvailable" do
|
|
81
|
+
expect do
|
|
82
|
+
Feedjira.parse("I'm an invalid feed")
|
|
83
|
+
end.to raise_error(Feedjira::NoParserAvailable)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should parse an feedburner rss feed" do
|
|
88
|
+
feed = Feedjira.parse(sample_rss_feed_burner_feed)
|
|
89
|
+
expect(feed.title).to eq "TechCrunch"
|
|
90
|
+
published = Time.parse_safely "Wed Nov 02 17:25:27 UTC 2011"
|
|
91
|
+
expect(feed.entries.first.published).to eq published
|
|
92
|
+
expect(feed.entries.size).to eq 20
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should parse an RSS feed with an a10 namespace" do
|
|
96
|
+
feed = Feedjira.parse(sample_rss_feed_with_a10_namespace)
|
|
97
|
+
expect(feed.url).to eq "http://www.example.com/"
|
|
98
|
+
expect(feed.entries.first.url).to eq "http://www.example.com/5"
|
|
99
|
+
expect(feed.entries.first.updated).to eq Time.parse_safely("2020-05-14T10:00:18Z")
|
|
100
|
+
expect(feed.entries.first.author).to eq "John Doe"
|
|
101
|
+
expect(feed.entries.size).to eq 5
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe ".parser_for_xml" do
|
|
106
|
+
it "with Google Docs atom feed it returns the GoogleDocsAtom parser" do
|
|
107
|
+
xml = sample_google_docs_list_feed
|
|
108
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
109
|
+
expect(actual_parser).to eq Feedjira::Parser::GoogleDocsAtom
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "with an atom feed it returns the Atom parser" do
|
|
113
|
+
xml = sample_atom_feed
|
|
114
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
115
|
+
expect(actual_parser).to eq Feedjira::Parser::Atom
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "with an atom feedburner feed it returns the AtomFeedBurner parser" do
|
|
119
|
+
xml = sample_feedburner_atom_feed
|
|
120
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
121
|
+
expect(actual_parser).to eq Feedjira::Parser::AtomFeedBurner
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "with an rdf feed it returns the RSS parser" do
|
|
125
|
+
xml = sample_rdf_feed
|
|
126
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
127
|
+
expect(actual_parser).to eq Feedjira::Parser::RSS
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "with an rss feedburner feed it returns the RSSFeedBurner parser" do
|
|
131
|
+
xml = sample_rss_feed_burner_feed
|
|
132
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
133
|
+
expect(actual_parser).to eq Feedjira::Parser::RSSFeedBurner
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "with an rss 2.0 feed it returns the RSS parser" do
|
|
137
|
+
xml = sample_rss_feed
|
|
138
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
139
|
+
expect(actual_parser).to eq Feedjira::Parser::RSS
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "with an itunes feed it returns the RSS parser" do
|
|
143
|
+
xml = sample_itunes_feed
|
|
144
|
+
actual_parser = Feedjira.parser_for_xml(xml)
|
|
145
|
+
expect(actual_parser).to eq Feedjira::Parser::ITunesRSS
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
context "when parsers are configured" do
|
|
149
|
+
it "does not use default parsers" do
|
|
150
|
+
xml = "Atom asdf"
|
|
151
|
+
new_parser = Class.new do
|
|
152
|
+
def self.able_to_parse?(_xml)
|
|
153
|
+
true
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
Feedjira.configure { |config| config.parsers = [new_parser] }
|
|
158
|
+
|
|
159
|
+
parser = Feedjira.parser_for_xml(xml)
|
|
160
|
+
expect(parser).to eq(new_parser)
|
|
161
|
+
|
|
162
|
+
Feedjira.reset_configuration!
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
data/spec/sample_feeds.rb
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SampleFeeds
|
|
4
4
|
FEEDS = {
|
|
5
|
-
sample_atom_feed:
|
|
6
|
-
sample_atom_middleman_feed:
|
|
7
|
-
sample_atom_xhtml_feed:
|
|
8
|
-
sample_atom_feed_line_breaks:
|
|
9
|
-
sample_atom_entry_content:
|
|
10
|
-
sample_itunes_feed:
|
|
11
|
-
sample_itunes_feed_with_single_quotes:
|
|
12
|
-
sample_itunes_feed_with_spaces:
|
|
13
|
-
sample_podlove_feed:
|
|
14
|
-
sample_rdf_feed:
|
|
15
|
-
sample_rdf_entry_content:
|
|
16
|
-
sample_rss_feed_burner_feed:
|
|
17
|
-
sample_rss_feed_burner_entry_content:
|
|
18
|
-
sample_rss_feed_burner_entry_description:
|
|
19
|
-
sample_rss_feed:
|
|
20
|
-
sample_rss_entry_content:
|
|
21
|
-
sample_feedburner_atom_feed:
|
|
22
|
-
sample_feedburner_atom_feed_alternate:
|
|
23
|
-
sample_feedburner_atom_entry_content:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
sample_atom_feed: "AmazonWebServicesBlog.xml",
|
|
6
|
+
sample_atom_middleman_feed: "FeedjiraBlog.xml",
|
|
7
|
+
sample_atom_xhtml_feed: "pet_atom.xml",
|
|
8
|
+
sample_atom_feed_line_breaks: "AtomFeedWithSpacesAroundEquals.xml",
|
|
9
|
+
sample_atom_entry_content: "AmazonWebServicesBlogFirstEntryContent.xml",
|
|
10
|
+
sample_itunes_feed: "itunes.xml",
|
|
11
|
+
sample_itunes_feed_with_single_quotes: "ITunesWithSingleQuotedAttributes.xml",
|
|
12
|
+
sample_itunes_feed_with_spaces: "ITunesWithSpacesInAttributes.xml",
|
|
13
|
+
sample_podlove_feed: "CRE.xml",
|
|
14
|
+
sample_rdf_feed: "HREFConsideredHarmful.xml",
|
|
15
|
+
sample_rdf_entry_content: "HREFConsideredHarmfulFirstEntry.xml",
|
|
16
|
+
sample_rss_feed_burner_feed: "TechCrunch.xml",
|
|
17
|
+
sample_rss_feed_burner_entry_content: "TechCrunchFirstEntry.xml",
|
|
18
|
+
sample_rss_feed_burner_entry_description: "TechCrunchFirstEntryDescription.xml",
|
|
19
|
+
sample_rss_feed: "TenderLovemaking.xml",
|
|
20
|
+
sample_rss_entry_content: "TenderLovemakingFirstEntry.xml",
|
|
21
|
+
sample_feedburner_atom_feed: "PaulDixExplainsNothing.xml",
|
|
22
|
+
sample_feedburner_atom_feed_alternate: "GiantRobotsSmashingIntoOtherGiantRobots.xml",
|
|
23
|
+
sample_feedburner_atom_entry_content: "PaulDixExplainsNothingFirstEntryContent.xml",
|
|
24
|
+
sample_google_alerts_atom_feed: "google_alerts_atom.xml",
|
|
25
|
+
sample_wfw_feed: "PaulDixExplainsNothingWFW.xml",
|
|
26
|
+
sample_google_docs_list_feed: "GoogleDocsList.xml",
|
|
27
|
+
sample_feed_burner_atom_xhtml_feed: "FeedBurnerXHTML.xml",
|
|
28
|
+
sample_duplicate_content_atom_feed: "DuplicateContentAtomFeed.xml",
|
|
29
|
+
sample_youtube_atom_feed: "youtube_atom.xml",
|
|
30
|
+
sample_atom_xhtml_with_escpaed_html_in_pre_tag_feed: "AtomEscapedHTMLInPreTag.xml",
|
|
31
|
+
sample_json_feed: "json_feed.json",
|
|
32
|
+
sample_rss_feed_huffpost_ca: "HuffPostCanada.xml",
|
|
33
|
+
sample_invalid_date_format_feed: "InvalidDateFormat.xml",
|
|
34
|
+
sample_rss_feed_permalinks: "Permalinks.xml",
|
|
35
|
+
sample_rss_feed_with_a10_namespace: "a10.xml"
|
|
31
36
|
}.freeze
|
|
32
37
|
|
|
33
38
|
FEEDS.each do |method, filename|
|
|
@@ -38,5 +43,3 @@ module SampleFeeds
|
|
|
38
43
|
File.read("#{File.dirname(__FILE__)}/sample_feeds/#{filename}")
|
|
39
44
|
end
|
|
40
45
|
end
|
|
41
|
-
|
|
42
|
-
# rubocop:enable Metrics/LineLength
|