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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/feed-parsing.md +15 -0
  3. data/.rubocop.yml +32 -8
  4. data/.rubocop_todo.yml +11 -0
  5. data/.travis.yml +3 -7
  6. data/CHANGELOG.md +18 -9
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +8 -5
  9. data/README.md +46 -99
  10. data/Rakefile +8 -6
  11. data/feedjira.gemspec +31 -20
  12. data/lib/feedjira.rb +75 -41
  13. data/lib/feedjira/atom_entry_utilities.rb +51 -0
  14. data/lib/feedjira/configuration.rb +8 -10
  15. data/lib/feedjira/core_ext.rb +5 -3
  16. data/lib/feedjira/core_ext/date.rb +2 -1
  17. data/lib/feedjira/core_ext/string.rb +2 -1
  18. data/lib/feedjira/core_ext/time.rb +12 -12
  19. data/lib/feedjira/date_time_utilities.rb +8 -10
  20. data/lib/feedjira/date_time_utilities/date_time_epoch_parser.rb +3 -2
  21. data/lib/feedjira/date_time_utilities/date_time_language_parser.rb +4 -4
  22. data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +11 -15
  23. data/lib/feedjira/feed.rb +12 -82
  24. data/lib/feedjira/feed_entry_utilities.rb +14 -7
  25. data/lib/feedjira/feed_utilities.rb +5 -4
  26. data/lib/feedjira/parser.rb +6 -1
  27. data/lib/feedjira/parser/atom.rb +6 -5
  28. data/lib/feedjira/parser/atom_entry.rb +4 -21
  29. data/lib/feedjira/parser/atom_feed_burner.rb +7 -6
  30. data/lib/feedjira/parser/atom_feed_burner_entry.rb +7 -18
  31. data/lib/feedjira/parser/atom_google_alerts.rb +26 -0
  32. data/lib/feedjira/parser/atom_google_alerts_entry.rb +21 -0
  33. data/lib/feedjira/parser/atom_youtube.rb +4 -3
  34. data/lib/feedjira/parser/atom_youtube_entry.rb +9 -8
  35. data/lib/feedjira/parser/globally_unique_identifier.rb +21 -0
  36. data/lib/feedjira/parser/google_docs_atom.rb +6 -6
  37. data/lib/feedjira/parser/google_docs_atom_entry.rb +3 -19
  38. data/lib/feedjira/parser/itunes_rss.rb +4 -3
  39. data/lib/feedjira/parser/itunes_rss_category.rb +6 -5
  40. data/lib/feedjira/parser/itunes_rss_item.rb +5 -8
  41. data/lib/feedjira/parser/itunes_rss_owner.rb +2 -1
  42. data/lib/feedjira/parser/json_feed.rb +41 -0
  43. data/lib/feedjira/parser/json_feed_item.rb +57 -0
  44. data/lib/feedjira/parser/podlove_chapter.rb +4 -3
  45. data/lib/feedjira/parser/rss.rb +5 -3
  46. data/lib/feedjira/parser/rss_entry.rb +3 -24
  47. data/lib/feedjira/parser/rss_feed_burner.rb +4 -3
  48. data/lib/feedjira/parser/rss_feed_burner_entry.rb +6 -26
  49. data/lib/feedjira/parser/rss_image.rb +2 -0
  50. data/lib/feedjira/preprocessor.rb +4 -4
  51. data/lib/feedjira/rss_entry_utilities.rb +53 -0
  52. data/lib/feedjira/version.rb +3 -1
  53. data/spec/feedjira/configuration_spec.rb +11 -16
  54. data/spec/feedjira/date_time_utilities_spec.rb +22 -20
  55. data/spec/feedjira/feed_entry_utilities_spec.rb +20 -18
  56. data/spec/feedjira/feed_spec.rb +17 -229
  57. data/spec/feedjira/feed_utilities_spec.rb +75 -73
  58. data/spec/feedjira/parser/atom_entry_spec.rb +41 -38
  59. data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +22 -20
  60. data/spec/feedjira/parser/atom_feed_burner_spec.rb +122 -118
  61. data/spec/feedjira/parser/atom_google_alerts_entry_spec.rb +34 -0
  62. data/spec/feedjira/parser/atom_google_alerts_spec.rb +62 -0
  63. data/spec/feedjira/parser/atom_spec.rb +83 -77
  64. data/spec/feedjira/parser/atom_youtube_entry_spec.rb +41 -39
  65. data/spec/feedjira/parser/atom_youtube_spec.rb +21 -19
  66. data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +10 -8
  67. data/spec/feedjira/parser/google_docs_atom_spec.rb +25 -21
  68. data/spec/feedjira/parser/itunes_rss_item_spec.rb +39 -37
  69. data/spec/feedjira/parser/itunes_rss_owner_spec.rb +7 -5
  70. data/spec/feedjira/parser/itunes_rss_spec.rb +120 -116
  71. data/spec/feedjira/parser/json_feed_item_spec.rb +81 -0
  72. data/spec/feedjira/parser/json_feed_spec.rb +55 -0
  73. data/spec/feedjira/parser/podlove_chapter_spec.rb +14 -12
  74. data/spec/feedjira/parser/rss_entry_spec.rb +56 -34
  75. data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +36 -34
  76. data/spec/feedjira/parser/rss_feed_burner_spec.rb +49 -45
  77. data/spec/feedjira/parser/rss_spec.rb +38 -36
  78. data/spec/feedjira/preprocessor_spec.rb +9 -7
  79. data/spec/feedjira_spec.rb +166 -0
  80. data/spec/sample_feeds.rb +32 -29
  81. data/spec/sample_feeds/HuffPostCanada.xml +279 -0
  82. data/spec/sample_feeds/Permalinks.xml +22 -0
  83. data/spec/sample_feeds/a10.xml +72 -0
  84. data/spec/sample_feeds/google_alerts_atom.xml +1 -0
  85. data/spec/sample_feeds/json_feed.json +156 -0
  86. data/spec/spec_helper.rb +7 -5
  87. metadata +59 -70
  88. data/Dangerfile +0 -1
  89. data/fixtures/vcr_cassettes/fetch_failure.yml +0 -62
  90. data/fixtures/vcr_cassettes/parse_error.yml +0 -222
  91. data/fixtures/vcr_cassettes/success.yml +0 -281
@@ -1,62 +1,66 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- module Feedjira::Parser
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
- it 'should return false for a regular RSS feed' do
10
- expect(RSSFeedBurner).to_not be_able_to_parse sample_rss_feed
11
- end
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
- it 'should return false for a feedburner atom feed' do
14
- expect(RSSFeedBurner).to_not be_able_to_parse sample_feedburner_atom_feed
15
- end
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
- it 'should return false for an rdf feed' do
18
- expect(RSSFeedBurner).to_not be_able_to_parse sample_rdf_feed
19
- end
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
- it 'should return false for a regular atom feed' do
22
- expect(RSSFeedBurner).to_not be_able_to_parse sample_atom_feed
23
- end
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
- describe 'parsing' do
27
- before(:each) do
28
- @feed = RSSFeedBurner.parse(sample_rss_feed_burner_feed)
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
- it 'should parse the title' do
32
- expect(@feed.title).to eq 'TechCrunch'
33
- end
29
+ describe "parsing" do
30
+ before(:each) do
31
+ @feed = RSSFeedBurner.parse(sample_rss_feed_burner_feed)
32
+ end
34
33
 
35
- it 'should parse the description' do
36
- description = 'TechCrunch is a group-edited blog that profiles the companies, products and events defining and transforming the new web.' # rubocop:disable Metrics/LineLength
37
- expect(@feed.description).to eq description
38
- end
34
+ it "should parse the title" do
35
+ expect(@feed.title).to eq "TechCrunch"
36
+ end
39
37
 
40
- it 'should parse the url' do
41
- expect(@feed.url).to eq 'http://techcrunch.com'
42
- end
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
- it 'should parse the last build date' do
45
- expect(@feed.last_built).to eq 'Wed, 02 Nov 2011 17:29:59 +0000'
46
- end
43
+ it "should parse the url" do
44
+ expect(@feed.url).to eq "http://techcrunch.com"
45
+ end
47
46
 
48
- it 'should parse the hub urls' do
49
- expect(@feed.hubs.count).to eq 2
50
- expect(@feed.hubs.first).to eq 'http://pubsubhubbub.appspot.com/'
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
- it 'should provide an accessor for the feed_url' do
54
- expect(@feed).to respond_to :feed_url
55
- expect(@feed).to respond_to :feed_url=
56
- end
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
- it 'should parse entries' do
59
- expect(@feed.entries.size).to eq 20
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
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe Feedjira::Parser::RSS do
4
- describe '#will_parse?' do
5
- it 'should return true for an RSS feed' do
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 'should return false for an atom feed' do
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 'should return false for an rss feedburner feed' do
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 'parsing' do
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 'should parse the version' do
25
- expect(@feed.version).to eq '2.0'
26
+ it "should parse the version" do
27
+ expect(@feed.version).to eq "2.0"
26
28
  end
27
29
 
28
- it 'should parse the title' do
29
- expect(@feed.title).to eq 'Tender Lovemaking'
30
+ it "should parse the title" do
31
+ expect(@feed.title).to eq "Tender Lovemaking"
30
32
  end
31
33
 
32
- it 'should parse the description' do
33
- expect(@feed.description).to eq 'The act of making love, tenderly.'
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 'should parse the url' do
37
- expect(@feed.url).to eq 'http://tenderlovemaking.com'
38
+ it "should parse the url" do
39
+ expect(@feed.url).to eq "http://tenderlovemaking.com"
38
40
  end
39
41
 
40
- it 'should parse the ttl' do
41
- expect(@feed.ttl).to eq '60'
42
+ it "should parse the ttl" do
43
+ expect(@feed.ttl).to eq "60"
42
44
  end
43
45
 
44
- it 'should parse the last build date' do
45
- expect(@feed.last_built).to eq 'Sat, 07 Sep 2002 09:42:31 GMT'
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 'should parse the hub urls' do
50
+ it "should parse the hub urls" do
49
51
  expect(@feed.hubs.count).to eq 1
50
- expect(@feed.hubs.first).to eq 'http://pubsubhubbub.appspot.com/'
52
+ expect(@feed.hubs.first).to eq "http://pubsubhubbub.appspot.com/"
51
53
  end
52
54
 
53
- it 'should provide an accessor for the feed_url' do
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 'should parse the language' do
59
- expect(@feed.language).to eq 'en'
60
+ it "should parse the language" do
61
+ expect(@feed.language).to eq "en"
60
62
  end
61
63
 
62
- it 'should parse the image url' do
63
- expect(@feed.image.url).to eq 'https://tenderlovemaking.com/images/header-logo-text-trimmed.png'
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 'should parse the image title' do
67
- expect(@feed.image.title).to eq 'Tender Lovemaking'
68
+ it "should parse the image title" do
69
+ expect(@feed.image.title).to eq "Tender Lovemaking"
68
70
  end
69
71
 
70
- it 'should parse the image link' do
71
- expect(@feed.image.link).to eq 'http://tenderlovemaking.com'
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 'should parse the image width' do
75
- expect(@feed.image.width).to eq '766'
76
+ it "should parse the image width" do
77
+ expect(@feed.image.width).to eq "766"
76
78
  end
77
79
 
78
- it 'should parse the image height' do
79
- expect(@feed.image.height).to eq '138'
80
+ it "should parse the image height" do
81
+ expect(@feed.image.height).to eq "138"
80
82
  end
81
83
 
82
- it 'should parse the image description' do
83
- expect(@feed.image.description).to eq 'The act of making love, tenderly.'
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 'should parse entries' do
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
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe Feedjira::Preprocessor do
4
- it 'returns the xml as parsed by Nokogiri' do
5
- xml = '<xml></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 'escapes markup in xhtml content' do
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(/&lt;p&gt;$/) # content
21
23
  end
22
24
 
23
- it 'leaves escaped html within pre tag' do
24
- processor = Feedjira::Preprocessor.new(sample_atom_xhtml_with_escpaed_html_in_pre_tag_feed) # rubocop:disable Metrics/LineLength
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 = ' &lt;pre&gt;&amp;lt;b&amp;gt;test&amp;lt;b&amp;gt;&lt;/pre&gt;' # rubocop:disable Metrics/LineLength
28
+ expected_pre_tag = " &lt;pre&gt;&amp;lt;b&amp;gt;test&amp;lt;b&amp;gt;&lt;/pre&gt;"
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
@@ -1,33 +1,38 @@
1
- # rubocop:disable Metrics/LineLength
1
+ # frozen_string_literal: true
2
2
 
3
3
  module SampleFeeds
4
4
  FEEDS = {
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_wfw_feed: 'PaulDixExplainsNothingWFW.xml',
25
- sample_google_docs_list_feed: 'GoogleDocsList.xml',
26
- sample_feed_burner_atom_xhtml_feed: 'FeedBurnerXHTML.xml',
27
- sample_duplicate_content_atom_feed: 'DuplicateContentAtomFeed.xml',
28
- sample_youtube_atom_feed: 'youtube_atom.xml',
29
- sample_atom_xhtml_with_escpaed_html_in_pre_tag_feed: 'AtomEscapedHTMLInPreTag.xml',
30
- sample_invalid_date_format_feed: 'InvalidDateFormat.xml'
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