feedjira 2.0.0 → 2.2.0

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 (90) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +15 -0
  4. data/.travis.yml +31 -12
  5. data/CHANGELOG.md +34 -1
  6. data/Dangerfile +1 -0
  7. data/Gemfile +2 -1
  8. data/LICENSE +1 -1
  9. data/README.md +210 -7
  10. data/Rakefile +11 -1
  11. data/feedjira.gemspec +17 -14
  12. data/fixtures/vcr_cassettes/fetch_failure.yml +62 -0
  13. data/fixtures/vcr_cassettes/parse_error.yml +222 -0
  14. data/fixtures/vcr_cassettes/success.yml +281 -0
  15. data/lib/feedjira/configuration.rb +76 -0
  16. data/lib/feedjira/core_ext/date.rb +3 -1
  17. data/lib/feedjira/core_ext/string.rb +2 -1
  18. data/lib/feedjira/core_ext/time.rb +24 -17
  19. data/lib/feedjira/core_ext.rb +3 -3
  20. data/lib/feedjira/date_time_utilities/date_time_epoch_parser.rb +13 -0
  21. data/lib/feedjira/date_time_utilities/date_time_language_parser.rb +24 -0
  22. data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +34 -0
  23. data/lib/feedjira/date_time_utilities.rb +32 -0
  24. data/lib/feedjira/feed.rb +89 -62
  25. data/lib/feedjira/feed_entry_utilities.rb +20 -19
  26. data/lib/feedjira/feed_utilities.rb +37 -22
  27. data/lib/feedjira/parser/atom.rb +10 -8
  28. data/lib/feedjira/parser/atom_entry.rb +11 -13
  29. data/lib/feedjira/parser/atom_feed_burner.rb +27 -10
  30. data/lib/feedjira/parser/atom_feed_burner_entry.rb +12 -14
  31. data/lib/feedjira/parser/atom_youtube.rb +21 -0
  32. data/lib/feedjira/parser/atom_youtube_entry.rb +30 -0
  33. data/lib/feedjira/parser/google_docs_atom.rb +8 -7
  34. data/lib/feedjira/parser/google_docs_atom_entry.rb +13 -11
  35. data/lib/feedjira/parser/itunes_rss.rb +41 -22
  36. data/lib/feedjira/parser/itunes_rss_category.rb +39 -0
  37. data/lib/feedjira/parser/itunes_rss_item.rb +32 -20
  38. data/lib/feedjira/parser/itunes_rss_owner.rb +4 -4
  39. data/lib/feedjira/parser/podlove_chapter.rb +22 -0
  40. data/lib/feedjira/parser/rss.rb +11 -8
  41. data/lib/feedjira/parser/rss_entry.rb +17 -21
  42. data/lib/feedjira/parser/rss_feed_burner.rb +5 -6
  43. data/lib/feedjira/parser/rss_feed_burner_entry.rb +24 -28
  44. data/lib/feedjira/parser/rss_image.rb +15 -0
  45. data/lib/feedjira/parser.rb +1 -1
  46. data/lib/feedjira/preprocessor.rb +4 -2
  47. data/lib/feedjira/version.rb +1 -1
  48. data/lib/feedjira.rb +15 -0
  49. data/spec/feedjira/configuration_spec.rb +25 -0
  50. data/spec/feedjira/date_time_utilities_spec.rb +47 -0
  51. data/spec/feedjira/feed_entry_utilities_spec.rb +23 -19
  52. data/spec/feedjira/feed_spec.rb +140 -75
  53. data/spec/feedjira/feed_utilities_spec.rb +83 -63
  54. data/spec/feedjira/parser/atom_entry_spec.rb +54 -34
  55. data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +27 -20
  56. data/spec/feedjira/parser/atom_feed_burner_spec.rb +87 -30
  57. data/spec/feedjira/parser/atom_spec.rb +50 -48
  58. data/spec/feedjira/parser/atom_youtube_entry_spec.rb +86 -0
  59. data/spec/feedjira/parser/atom_youtube_spec.rb +43 -0
  60. data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +5 -4
  61. data/spec/feedjira/parser/google_docs_atom_spec.rb +6 -6
  62. data/spec/feedjira/parser/itunes_rss_item_spec.rb +49 -29
  63. data/spec/feedjira/parser/itunes_rss_owner_spec.rb +10 -9
  64. data/spec/feedjira/parser/itunes_rss_spec.rb +87 -30
  65. data/spec/feedjira/parser/podlove_chapter_spec.rb +37 -0
  66. data/spec/feedjira/parser/rss_entry_spec.rb +50 -33
  67. data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +55 -33
  68. data/spec/feedjira/parser/rss_feed_burner_spec.rb +31 -26
  69. data/spec/feedjira/parser/rss_spec.rb +56 -24
  70. data/spec/feedjira/preprocessor_spec.rb +11 -3
  71. data/spec/sample_feeds/AmazonWebServicesBlog.xml +797 -797
  72. data/spec/sample_feeds/AtomEscapedHTMLInPreTag.xml +13 -0
  73. data/spec/sample_feeds/CRE.xml +5849 -0
  74. data/spec/sample_feeds/FeedBurnerXHTML.xml +400 -400
  75. data/spec/sample_feeds/GiantRobotsSmashingIntoOtherGiantRobots.xml +682 -0
  76. data/spec/sample_feeds/ITunesWithSingleQuotedAttributes.xml +67 -0
  77. data/spec/sample_feeds/InvalidDateFormat.xml +20 -0
  78. data/spec/sample_feeds/PaulDixExplainsNothing.xml +175 -175
  79. data/spec/sample_feeds/PaulDixExplainsNothingAlternate.xml +175 -175
  80. data/spec/sample_feeds/PaulDixExplainsNothingFirstEntryContent.xml +16 -16
  81. data/spec/sample_feeds/PaulDixExplainsNothingWFW.xml +174 -174
  82. data/spec/sample_feeds/TenderLovemaking.xml +12 -2
  83. data/spec/sample_feeds/TrotterCashionHome.xml +611 -611
  84. data/spec/sample_feeds/TypePadNews.xml +368 -368
  85. data/spec/sample_feeds/itunes.xml +31 -2
  86. data/spec/sample_feeds/pet_atom.xml +229 -229
  87. data/spec/sample_feeds/youtube_atom.xml +395 -0
  88. data/spec/sample_feeds.rb +31 -21
  89. data/spec/spec_helper.rb +6 -0
  90. metadata +132 -25
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Feedjira::FeedUtilities do
4
4
  before(:each) do
@@ -8,47 +8,64 @@ describe Feedjira::FeedUtilities do
8
8
  end
9
9
  end
10
10
 
11
- describe "preprocessing" do
12
- context "when the flag is not set" do
13
- it "does not call the preprocessing method" do
11
+ describe 'preprocessing' do
12
+ context 'when the flag is not set' do
13
+ it 'does not call the preprocessing method' do
14
14
  @klass.preprocess_xml = false
15
15
  expect(@klass).to_not receive :preprocess
16
16
  @klass.parse sample_rss_feed
17
17
  end
18
18
  end
19
19
 
20
- context "when the flag is set" do
21
- it "calls the preprocessing method" do
20
+ context 'when the flag is set' do
21
+ it 'calls the preprocessing method' do
22
22
  @klass.preprocess_xml = true
23
- expect(@klass).to receive(:preprocess).
24
- and_return sample_rss_feed
23
+ expect(@klass).to receive(:preprocess).and_return sample_rss_feed
25
24
  @klass.parse sample_rss_feed
26
25
  end
27
26
  end
28
27
  end
29
28
 
30
- describe "instance methods" do
31
- it "should provide an updated? accessor" do
29
+ describe 'strip whitespace' do
30
+ context 'strip_whitespace config is true' do
31
+ it 'strips all XML whitespace' do
32
+ Feedjira.configure { |config| config.strip_whitespace = true }
33
+
34
+ expect(@klass.strip_whitespace("\nfoobar\n")).to eq('foobar')
35
+
36
+ Feedjira.configure { |config| config.strip_whitespace = false }
37
+ end
38
+ end
39
+
40
+ context 'strip_whitespace config is false' do
41
+ it 'lstrips XML whitespace' do
42
+ expect(@klass.strip_whitespace("\nfoobar\n")).to eq("foobar\n")
43
+ end
44
+ end
45
+ end
46
+
47
+ describe 'instance methods' do
48
+ it 'should provide an updated? accessor' do
32
49
  feed = @klass.new
33
50
  expect(feed).to_not be_updated
34
51
  feed.updated = true
35
52
  expect(feed).to be_updated
36
53
  end
37
54
 
38
- it "should provide a new_entries accessor" do
55
+ it 'should provide a new_entries accessor' do
39
56
  feed = @klass.new
40
57
  expect(feed.new_entries).to eq []
41
58
  feed.new_entries = [:foo]
42
59
  expect(feed.new_entries).to eq [:foo]
43
60
  end
44
61
 
45
- it "should provide an etag accessor" do
62
+ it 'should provide an etag accessor' do
46
63
  feed = @klass.new
47
- feed.etag = "foo"
48
- expect(feed.etag).to eq "foo"
64
+ feed.etag = 'foo'
65
+ expect(feed.etag).to eq 'foo'
49
66
  end
50
67
 
51
- it "should provide a last_modified accessor" do
68
+ it 'should provide a last_modified accessor' do
52
69
  feed = @klass.new
53
70
  time = Time.now
54
71
  feed.last_modified = time
@@ -56,21 +73,21 @@ describe Feedjira::FeedUtilities do
56
73
  expect(feed.last_modified.class).to eq Time
57
74
  end
58
75
 
59
- it "should return new_entries? as true when entries are put into new_entries" do
76
+ it 'should return new_entries? as true when entries are put into new_entries' do # rubocop:disable Metrics/LineLength
60
77
  feed = @klass.new
61
78
  feed.new_entries << :foo
62
- expect(feed).to have_new_entries
79
+ expect(feed.new_entries?).to eq true
63
80
  end
64
81
 
65
- 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
82
+ 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 # rubocop:disable Metrics/LineLength
66
83
  feed = Feedjira::Parser::Atom.new
67
- entry =Feedjira::Parser::AtomEntry.new
84
+ entry = Feedjira::Parser::AtomEntry.new
68
85
  entry.published = Time.now.to_s
69
86
  feed.entries << entry
70
87
  expect(feed.last_modified).to eq entry.published
71
88
  end
72
89
 
73
- it "should not throw an error if one of the entries has published date of nil" do
90
+ it 'should not throw an error if one of the entries has published date of nil' do # rubocop:disable Metrics/LineLength
74
91
  feed = Feedjira::Parser::Atom.new
75
92
  entry = Feedjira::Parser::AtomEntry.new
76
93
  entry.published = Time.now.to_s
@@ -80,122 +97,125 @@ describe Feedjira::FeedUtilities do
80
97
  end
81
98
  end
82
99
 
83
- describe "#update_from_feed" do
84
- describe "updating feed attributes" do
100
+ describe '#update_from_feed' do
101
+ describe 'updating feed attributes' do
85
102
  before(:each) do
86
- # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
87
- # method would only be called against a feed item.
103
+ # I'm using the Atom class when I know I should be using a different
104
+ # one. However, this update_from_feed method would only be called
105
+ # against a feed item.
88
106
  @feed = Feedjira::Parser::Atom.new
89
- @feed.title = "A title"
90
- @feed.url = "http://pauldix.net"
91
- @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
107
+ @feed.title = 'A title'
108
+ @feed.url = 'http://pauldix.net'
109
+ @feed.feed_url = 'http://feeds.feedburner.com/PaulDixExplainsNothing'
92
110
  @feed.updated = false
93
111
  @updated_feed = @feed.dup
94
112
  end
95
113
 
96
- it "should update the title if changed" do
97
- @updated_feed.title = "new title"
114
+ it 'should update the title if changed' do
115
+ @updated_feed.title = 'new title'
98
116
  @feed.update_from_feed(@updated_feed)
99
117
  expect(@feed.title).to eq @updated_feed.title
100
118
  expect(@feed).to be_updated
101
119
  end
102
120
 
103
- it "should not update the title if the same" do
121
+ it 'should not update the title if the same' do
104
122
  @feed.update_from_feed(@updated_feed)
105
123
  expect(@feed).to_not be_updated
106
124
  end
107
125
 
108
- it "should update the feed_url if changed" do
109
- @updated_feed.feed_url = "a new feed url"
126
+ it 'should update the feed_url if changed' do
127
+ @updated_feed.feed_url = 'a new feed url'
110
128
  @feed.update_from_feed(@updated_feed)
111
129
  expect(@feed.feed_url).to eq @updated_feed.feed_url
112
130
  expect(@feed).to be_updated
113
131
  end
114
132
 
115
- it "should not update the feed_url if the same" do
133
+ it 'should not update the feed_url if the same' do
116
134
  @feed.update_from_feed(@updated_feed)
117
135
  expect(@feed).to_not be_updated
118
136
  end
119
137
 
120
- it "should update the url if changed" do
121
- @updated_feed.url = "a new url"
138
+ it 'should update the url if changed' do
139
+ @updated_feed.url = 'a new url'
122
140
  @feed.update_from_feed(@updated_feed)
123
141
  expect(@feed.url).to eq @updated_feed.url
124
142
  end
125
143
 
126
- it "should not update the url if not changed" do
144
+ it 'should not update the url if not changed' do
127
145
  @feed.update_from_feed(@updated_feed)
128
146
  expect(@feed).to_not be_updated
129
147
  end
130
148
  end
131
149
 
132
- describe "updating entries" do
150
+ describe 'updating entries' do
133
151
  before(:each) do
134
- # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
135
- # method would only be called against a feed item.
152
+ # I'm using the Atom class when I know I should be using a different
153
+ # one. However, this update_from_feed method would only be called
154
+ # against a feed item.
136
155
  @feed = Feedjira::Parser::Atom.new
137
- @feed.title = "A title"
138
- @feed.url = "http://pauldix.net"
139
- @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
156
+ @feed.title = 'A title'
157
+ @feed.url = 'http://pauldix.net'
158
+ @feed.feed_url = 'http://feeds.feedburner.com/PaulDixExplainsNothing'
140
159
  @feed.updated = false
141
160
  @updated_feed = @feed.dup
142
161
  @old_entry = Feedjira::Parser::AtomEntry.new
143
- @old_entry.url = "http://pauldix.net/old.html"
162
+ @old_entry.url = 'http://pauldix.net/old.html'
144
163
  @old_entry.published = Time.now.to_s
145
- @old_entry.entry_id = "entry_id_old"
164
+ @old_entry.entry_id = 'entry_id_old'
146
165
  @new_entry = Feedjira::Parser::AtomEntry.new
147
- @new_entry.url = "http://pauldix.net/new.html"
166
+ @new_entry.url = 'http://pauldix.net/new.html'
148
167
  @new_entry.published = (Time.now + 10).to_s
149
- @new_entry.entry_id = "entry_id_new"
168
+ @new_entry.entry_id = 'entry_id_new'
150
169
  @feed.entries << @old_entry
151
170
  @updated_feed.entries << @new_entry
152
171
  @updated_feed.entries << @old_entry
153
172
  end
154
173
 
155
- it "should update last-modified from the latest entry date" do
174
+ it 'should update last-modified from the latest entry date' do
156
175
  @feed.update_from_feed(@updated_feed)
157
176
  expect(@feed.last_modified).to eq @new_entry.published
158
177
  end
159
178
 
160
- it "should put new entries into new_entries" do
179
+ it 'should put new entries into new_entries' do
161
180
  @feed.update_from_feed(@updated_feed)
162
181
  expect(@feed.new_entries).to eq [@new_entry]
163
182
  end
164
183
 
165
- it "should also put new entries into the entries collection" do
184
+ it 'should also put new entries into the entries collection' do
166
185
  @feed.update_from_feed(@updated_feed)
167
186
  expect(@feed.entries).to include(@new_entry)
168
187
  expect(@feed.entries).to include(@old_entry)
169
188
  end
170
189
  end
171
190
 
172
- describe "#update_from_feed" do
191
+ describe '#update_from_feed' do
173
192
  let(:recent_entry_id) { 'entry_id' }
174
193
  let(:old_entry_id) { nil }
175
194
 
176
195
  before(:each) do
177
- # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
178
- # method would only be called against a feed item.
196
+ # I'm using the Atom class when I know I should be using a different
197
+ # one. However, this update_from_feed method would only be called
198
+ # against a feed item.
179
199
  @feed = Feedjira::Parser::Atom.new
180
- @feed.title = "A title"
181
- @feed.url = "http://pauldix.net"
182
- @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
200
+ @feed.title = 'A title'
201
+ @feed.url = 'http://pauldix.net'
202
+ @feed.feed_url = 'http://feeds.feedburner.com/PaulDixExplainsNothing'
183
203
  @feed.updated = false
184
204
  @updated_feed = @feed.dup
185
205
 
186
206
  @old_entry = Feedjira::Parser::AtomEntry.new
187
- @old_entry.url = "http://pauldix.net/old.html"
207
+ @old_entry.url = 'http://pauldix.net/old.html'
188
208
  @old_entry.entry_id = old_entry_id
189
209
  @old_entry.published = (Time.now - 10).to_s
190
210
 
191
211
  @entry = Feedjira::Parser::AtomEntry.new
192
212
  @entry.published = (Time.now + 10).to_s
193
213
  @entry.entry_id = recent_entry_id
194
- @entry.url = "http://pauldix.net/entry.html"
214
+ @entry.url = 'http://pauldix.net/entry.html'
195
215
 
196
216
  # only difference is a changed url
197
217
  @entry_changed_url = @entry.dup
198
- @entry_changed_url.url = "http://pauldix.net/updated.html"
218
+ @entry_changed_url.url = 'http://pauldix.net/updated.html'
199
219
 
200
220
  # entry with changed url must be first
201
221
  @feed.entries << @entry
@@ -204,8 +224,8 @@ describe Feedjira::FeedUtilities do
204
224
  @updated_feed.entries << @old_entry
205
225
  end
206
226
 
207
- context "changing the url of an existing entry" do
208
- it "should not put the complete feed into new_entries" do
227
+ context 'changing the url of an existing entry' do
228
+ it 'should not put the complete feed into new_entries' do
209
229
  @feed.update_from_feed(@updated_feed)
210
230
  expect(@feed.new_entries).to_not include(@entry_changed_url)
211
231
  expect(@feed.new_entries).to_not include(@old_entry)
@@ -214,11 +234,11 @@ describe Feedjira::FeedUtilities do
214
234
  end
215
235
  end
216
236
 
217
- context "feed not have entry id and only difference is a url" do
237
+ context 'feed not have entry id and only difference is a url' do
218
238
  let(:recent_entry_id) { nil }
219
239
  let(:old_entry_id) { nil }
220
240
 
221
- it "should put the complete feed into new_entries" do
241
+ it 'should put the complete feed into new_entries' do
222
242
  @feed.update_from_feed(@updated_feed)
223
243
  expect(@feed.new_entries).to include(@entry_changed_url)
224
244
  expect(@feed.new_entries).to include(@old_entry)
@@ -242,7 +262,7 @@ describe Feedjira::FeedUtilities do
242
262
  let(:feed_two) { double 'Feed Two', entries: [entry_two] }
243
263
 
244
264
  before do
245
- stub_const("Feedjira::FeedUtilities::UPDATABLE_ATTRIBUTES", [])
265
+ stub_const('Feedjira::FeedUtilities::UPDATABLE_ATTRIBUTES', [])
246
266
  feed_one.entries << entry_one
247
267
  end
248
268
 
@@ -1,58 +1,64 @@
1
- require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
1
+ require 'spec_helper'
2
2
 
3
3
  describe Feedjira::Parser::AtomEntry do
4
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
5
+ # I don't really like doing it this way because these unit test should only
6
+ # rely on AtomEntry, but this is actually how it should work. You would
7
+ # never just pass entry xml straight to the AtomEnry
7
8
  @entry = Feedjira::Parser::Atom.parse(sample_atom_feed).entries.first
8
9
  end
9
10
 
10
- it "should parse the title" do
11
- expect(@entry.title).to eq "AWS Job: Architect & Designer Position in Turkey"
11
+ it 'should parse the title' do
12
+ title = 'AWS Job: Architect & Designer Position in Turkey'
13
+ expect(@entry.title).to eq title
12
14
  end
13
15
 
14
- it "should parse the url" do
15
- expect(@entry.url).to eq "http://aws.typepad.com/aws/2009/01/aws-job-architect-designer-position-in-turkey.html"
16
+ it 'should parse the url' do
17
+ expect(@entry.url).to eq 'http://aws.typepad.com/aws/2009/01/aws-job-architect-designer-position-in-turkey.html'
16
18
  end
17
19
 
18
- it "should parse the url even when" do
19
- entries = Feedjira::Parser::Atom.parse(load_sample("atom_with_link_tag_for_url_unmarked.xml")).entries
20
- expect(entries.first.url).to eq "http://www.innoq.com/blog/phaus/2009/07/ja.html"
20
+ it 'should parse the url even when' do
21
+ xml = load_sample('atom_with_link_tag_for_url_unmarked.xml')
22
+ entries = Feedjira::Parser::Atom.parse(xml).entries
23
+ expect(entries.first.url).to eq 'http://www.innoq.com/blog/phaus/2009/07/ja.html'
21
24
  end
22
25
 
23
- it "should parse the author" do
24
- expect(@entry.author).to eq "AWS Editor"
26
+ it 'should parse the author' do
27
+ expect(@entry.author).to eq 'AWS Editor'
25
28
  end
26
29
 
27
- it "should parse the content" do
30
+ it 'should parse the content' do
28
31
  expect(@entry.content).to eq sample_atom_entry_content
29
32
  end
30
33
 
31
- it "should provide a summary" do
32
- expect(@entry.summary).to eq "Late last year an entrepreneur from Turkey visited me at Amazon HQ in Seattle. We talked about his plans to use AWS as part of his new social video portal startup. I won't spill any beans before he's ready to..."
34
+ it 'should provide a summary' do
35
+ summary = "Late last year an entrepreneur from Turkey visited me at Amazon HQ in Seattle. We talked about his plans to use AWS as part of his new social video portal startup. I won't spill any beans before he's ready to..." # rubocop:disable Metrics/LineLength
36
+ expect(@entry.summary).to eq summary
33
37
  end
34
38
 
35
- it "should parse the published date" do
36
- expect(@entry.published).to eq Time.parse_safely("Fri Jan 16 18:21:00 UTC 2009")
39
+ it 'should parse the published date' do
40
+ published = Time.parse_safely 'Fri Jan 16 18:21:00 UTC 2009'
41
+ expect(@entry.published).to eq published
37
42
  end
38
43
 
39
- it "should parse the categories" do
40
- expect(@entry.categories).to eq ['Turkey', 'Seattle']
44
+ it 'should parse the categories' do
45
+ expect(@entry.categories).to eq %w(Turkey Seattle)
41
46
  end
42
47
 
43
- it "should parse the updated date" do
44
- expect(@entry.updated).to eq Time.parse_safely("Fri Jan 16 18:21:00 UTC 2009")
48
+ it 'should parse the updated date' do
49
+ updated = Time.parse_safely 'Fri Jan 16 18:21:00 UTC 2009'
50
+ expect(@entry.updated).to eq updated
45
51
  end
46
52
 
47
- it "should parse the id" do
48
- expect(@entry.id).to eq "tag:typepad.com,2003:post-61484736"
53
+ it 'should parse the id' do
54
+ expect(@entry.id).to eq 'tag:typepad.com,2003:post-61484736'
49
55
  end
50
56
 
51
- it "should support each" do
57
+ it 'should support each' do
52
58
  expect(@entry).to respond_to :each
53
59
  end
54
60
 
55
- it "should be able to list out all fields with each" do
61
+ it 'should be able to list out all fields with each' do
56
62
  all_fields = []
57
63
  title_value = ''
58
64
 
@@ -61,22 +67,36 @@ describe Feedjira::Parser::AtomEntry do
61
67
  title_value = value if field == 'title'
62
68
  end
63
69
 
64
- expect(all_fields.sort).to eq ["author", "categories", "content", "entry_id", "links", "published", "summary", "title", "updated", "url"]
65
- expect(title_value).to eq "AWS Job: Architect & Designer Position in Turkey"
70
+ expect(title_value).to eq 'AWS Job: Architect & Designer Position in Turkey'
71
+
72
+ expected_fields = %w(
73
+ author
74
+ categories
75
+ content
76
+ entry_id
77
+ links
78
+ published
79
+ summary
80
+ title
81
+ updated
82
+ url
83
+ )
84
+ expect(all_fields.sort).to eq expected_fields
66
85
  end
67
86
 
68
- it "should support checking if a field exists in the entry" do
87
+ it 'should support checking if a field exists in the entry' do
69
88
  expect(@entry).to include 'author'
70
89
  expect(@entry).to include 'title'
71
90
  end
72
91
 
73
- it "should allow access to fields with hash syntax" do
74
- expect(@entry['title']).to eq "AWS Job: Architect & Designer Position in Turkey"
75
- expect(@entry['author']).to eq "AWS Editor"
92
+ it 'should allow access to fields with hash syntax' do
93
+ title = 'AWS Job: Architect & Designer Position in Turkey'
94
+ expect(@entry['title']).to eq title
95
+ expect(@entry['author']).to eq 'AWS Editor'
76
96
  end
77
97
 
78
- it "should allow setting field values with hash syntax" do
79
- @entry['title'] = "Foobar"
80
- expect(@entry.title).to eq "Foobar"
98
+ it 'should allow setting field values with hash syntax' do
99
+ @entry['title'] = 'Foobar'
100
+ expect(@entry.title).to eq 'Foobar'
81
101
  end
82
102
  end
@@ -1,47 +1,54 @@
1
- require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
1
+ require 'spec_helper'
2
2
 
3
3
  describe Feedjira::Parser::AtomFeedBurnerEntry do
4
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 = Feedjira::Parser::AtomFeedBurner.parse(sample_feedburner_atom_feed).entries.first
5
+ Feedjira::Parser::AtomFeedBurner.preprocess_xml = false
6
+ # I don't really like doing it this way because these unit test should only
7
+ # rely on AtomEntry, but this is actually how it should work. You would
8
+ # never just pass entry xml straight to the AtomEnry
9
+ feed = Feedjira::Parser::AtomFeedBurner.parse sample_feedburner_atom_feed
10
+ @entry = feed.entries.first
8
11
  end
9
12
 
10
- it "should parse the title" do
11
- expect(@entry.title).to eq "Making a Ruby C library even faster"
13
+ it 'should parse the title' do
14
+ expect(@entry.title).to eq 'Making a Ruby C library even faster'
12
15
  end
13
16
 
14
- it "should be able to fetch a url via the 'alternate' rel if no origLink exists" do
15
- entry = Feedjira::Parser::AtomFeedBurner.parse(File.read("#{File.dirname(__FILE__)}/../../sample_feeds/PaulDixExplainsNothingAlternate.xml")).entries.first
17
+ it "should be able to fetch a url via the 'alternate' rel if no origLink exists" do # rubocop:disable Metrics/LineLength
18
+ xml = File.read("#{File.dirname(__FILE__)}/../../sample_feeds/PaulDixExplainsNothingAlternate.xml") # rubocop:disable Metrics/LineLength
19
+ entry = Feedjira::Parser::AtomFeedBurner.parse(xml).entries.first
16
20
  expect(entry.url).to eq 'http://feeds.feedburner.com/~r/PaulDixExplainsNothing/~3/519925023/making-a-ruby-c-library-even-faster.html'
17
21
  end
18
22
 
19
- it "should parse the url" do
20
- expect(@entry.url).to eq "http://www.pauldix.net/2009/01/making-a-ruby-c-library-even-faster.html"
23
+ it 'should parse the url' do
24
+ expect(@entry.url).to eq 'http://www.pauldix.net/2009/01/making-a-ruby-c-library-even-faster.html'
21
25
  end
22
26
 
23
- it "should parse the url when there is no alternate" do
24
- entry = Feedjira::Parser::AtomFeedBurner.parse(File.read("#{File.dirname(__FILE__)}/../../sample_feeds/FeedBurnerUrlNoAlternate.xml")).entries.first
27
+ it 'should parse the url when there is no alternate' do
28
+ xml = File.read("#{File.dirname(__FILE__)}/../../sample_feeds/FeedBurnerUrlNoAlternate.xml") # rubocop:disable Metrics/LineLength
29
+ entry = Feedjira::Parser::AtomFeedBurner.parse(xml).entries.first
25
30
  expect(entry.url).to eq 'http://example.com/QQQQ.html'
26
31
  end
27
32
 
28
- it "should parse the author" do
29
- expect(@entry.author).to eq "Paul Dix"
33
+ it 'should parse the author' do
34
+ expect(@entry.author).to eq 'Paul Dix'
30
35
  end
31
36
 
32
- it "should parse the content" do
37
+ it 'should parse the content' do
33
38
  expect(@entry.content).to eq sample_feedburner_atom_entry_content
34
39
  end
35
40
 
36
- it "should provide a summary" do
37
- expect(@entry.summary).to eq "Last week I released the first version of a SAX based XML parsing library called SAX-Machine. It uses Nokogiri, which uses libxml, so it's pretty fast. However, I felt that it could be even faster. The only question was how..."
41
+ it 'should provide a summary' do
42
+ summary = "Last week I released the first version of a SAX based XML parsing library called SAX-Machine. It uses Nokogiri, which uses libxml, so it's pretty fast. However, I felt that it could be even faster. The only question was how..." # rubocop:disable Metrics/LineLength
43
+ expect(@entry.summary).to eq summary
38
44
  end
39
45
 
40
- it "should parse the published date" do
41
- expect(@entry.published).to eq Time.parse_safely("Thu Jan 22 15:50:22 UTC 2009")
46
+ it 'should parse the published date' do
47
+ published = Time.parse_safely 'Thu Jan 22 15:50:22 UTC 2009'
48
+ expect(@entry.published).to eq published
42
49
  end
43
50
 
44
- it "should parse the categories" do
51
+ it 'should parse the categories' do
45
52
  expect(@entry.categories).to eq ['Ruby', 'Another Category']
46
53
  end
47
54
  end