metainspector 5.22.0 → 6.0.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.
@@ -14,9 +14,6 @@ describe MetaInspector do
14
14
  store
15
15
  end
16
16
 
17
- # The deprecation warning prints once per process, so each example starts as a fresh process would
18
- before { MetaInspector::Request.instance_variable_set(:@faraday_http_cache_deprecation_warned, nil) }
19
-
20
17
  it "caches responses with faraday_options[:faraday_http_cache]" do
21
18
  MetaInspector.new('http://example.com', faraday_options: { faraday_http_cache: { store: cache } })
22
19
 
@@ -39,31 +36,12 @@ describe MetaInspector do
39
36
  expect(cache_options).to eq({ store: cache })
40
37
  end
41
38
 
42
- it "still caches responses with the deprecated top-level faraday_http_cache option" do
43
- expect do
44
- MetaInspector.new('http://example.com', faraday_http_cache: { store: cache })
45
- end.to output.to_stderr
46
-
47
- expect(cache.keys).not_to be_empty
48
- end
49
-
50
- it "warns that the top-level faraday_http_cache option is deprecated" do
39
+ it "raises ArgumentError for the top-level faraday_http_cache option removed in 6.0" do
51
40
  expect do
52
41
  MetaInspector.new('http://example.com', faraday_http_cache: { store: cache })
53
- end.to output(/DEPRECATION.*faraday_http_cache.*faraday_options/).to_stderr
54
- end
55
-
56
- it "prints the deprecation warning only once per process" do
57
- expect do
58
- 3.times { MetaInspector.new('http://example.com', faraday_http_cache: { store: cache }) }
59
- end.to output(/\ADEPRECATION WARNING: [^\n]*\n\z/).to_stderr
60
- end
42
+ end.to raise_error(ArgumentError, /faraday_http_cache.*faraday_options/)
61
43
 
62
- it "raises ArgumentError when the cache is configured in both places" do
63
- expect do
64
- MetaInspector.new('http://example.com', faraday_http_cache: { store: cache },
65
- faraday_options: { faraday_http_cache: { store: cache } })
66
- end.to raise_error(ArgumentError, /faraday_http_cache/)
44
+ expect(cache).to be_empty
67
45
  end
68
46
  end
69
47
  end
@@ -102,32 +102,50 @@ describe MetaInspector do
102
102
  context 'when the first title is empty' do
103
103
  let(:html) { '<html><head><title></title><title>Two</title></head></html>' }
104
104
 
105
- it 'should return an empty string without falling back to a later title' do
106
- expect(page.title).to eq('')
105
+ it 'should return nil without falling back to a later title' do
106
+ expect(page.title).to be_nil
107
+ end
108
+ end
109
+
110
+ context 'when the first title is blank' do
111
+ let(:html) { "<html><head><title> \n\t </title><title>Two</title></head></html>" }
112
+
113
+ it 'should return nil without falling back to a later title' do
114
+ expect(page.title).to be_nil
115
+ expect(page.to_hash['title']).to be_nil
107
116
  end
108
117
  end
109
118
 
110
119
  context 'when the title contains whitespace and entities' do
111
- let(:html) { '<html><head><title> One &amp; Two </title></head></html>' }
120
+ let(:html) { "<html><head><title>\n One &amp; Two \n</title></head></html>" }
121
+
122
+ it 'should strip surrounding whitespace and decode entities' do
123
+ expect(page.title).to eq('One & Two')
124
+ end
125
+ end
112
126
 
113
- it 'should preserve whitespace and decode entities' do
114
- expect(page.title).to eq(' One & Two ')
127
+ context 'when the title has whitespace inside' do
128
+ let(:html) { "<html><head><title>One\n Two</title></head></html>" }
129
+
130
+ it 'should keep the inner whitespace as written' do
131
+ expect(page.title).to eq("One\n Two")
115
132
  end
116
133
  end
117
134
 
118
135
  context 'when there is no title' do
119
136
  let(:html) { '<html><head></head><body></body></html>' }
120
137
 
121
- it 'should return an empty string' do
122
- expect(page.title).to eq('')
138
+ it 'should return nil, so a fallback can be chained' do
139
+ expect(page.title).to be_nil
140
+ expect(page.title || 'fallback').to eq('fallback')
123
141
  end
124
142
  end
125
143
 
126
144
  context 'when the title is only in the body' do
127
145
  let(:html) { '<html><head></head><body><title>Body title</title></body></html>' }
128
146
 
129
- it 'should return an empty string' do
130
- expect(page.title).to eq('')
147
+ it 'should return nil' do
148
+ expect(page.title).to be_nil
131
149
  end
132
150
  end
133
151
  end
@@ -348,6 +366,28 @@ describe MetaInspector do
348
366
 
349
367
  expect(page.description).to be(nil)
350
368
  end
369
+
370
+ it "should strip surrounding whitespace" do
371
+ html = %(<meta name="description" content="\n The description \n">)
372
+ page = MetaInspector.new('http://example.com/', document: html)
373
+
374
+ expect(page.description).to eq('The description')
375
+ end
376
+
377
+ it "should keep the inner whitespace as written" do
378
+ html = %(<meta name="description" content="One\n Two">)
379
+ page = MetaInspector.new('http://example.com/', document: html)
380
+
381
+ expect(page.description).to eq("One\n Two")
382
+ end
383
+
384
+ ['', ' ', "\n\t "].each do |blank|
385
+ it "should be nil for a blank meta description (#{blank.inspect})" do
386
+ page = MetaInspector.new('http://example.com/', document: %(<meta name="description" content="#{blank}">))
387
+
388
+ expect(page.description).to be_nil
389
+ end
390
+ end
351
391
  end
352
392
 
353
393
  describe "#best_description" do
@@ -369,13 +409,28 @@ describe MetaInspector do
369
409
  expect(page.best_description).to eq("the twitter description")
370
410
  end
371
411
 
412
+ it "should strip surrounding whitespace, like description" do
413
+ html = %(<meta name="description" content="\n One\n Two \n">)
414
+ page = MetaInspector.new('http://example.com/', document: html)
415
+
416
+ expect(page.best_description).to eq("One\n Two")
417
+ expect(page.best_description).to eq(page.description)
418
+ end
419
+
420
+ it "should strip surrounding whitespace from the paragraph fallback" do
421
+ paragraph = 'This paragraph is long enough to be used as the description when the page has no description in its metadata at all.'
422
+ page = MetaInspector.new('http://example.com/', document: "<p>\n #{paragraph}\n </p>")
423
+
424
+ expect(page.best_description).to eq(paragraph)
425
+ end
426
+
372
427
  ['', ' ', "\n\t "].each do |blank|
373
428
  it "should skip a blank standard description (#{blank.inspect})" do
374
429
  html = %(<html><head><meta name="description" content="#{blank}"><meta property="og:description" content="Useful Open Graph description"></head></html>)
375
430
  page = MetaInspector.new('http://example.com/', document: html)
376
431
 
377
432
  expect(page.best_description).to eq('Useful Open Graph description')
378
- expect(page.description).to eq(blank)
433
+ expect(page.description).to be_nil
379
434
  end
380
435
 
381
436
  it "should skip a blank Open Graph description (#{blank.inspect})" do
@@ -410,12 +465,12 @@ describe MetaInspector do
410
465
  end
411
466
 
412
467
  ['description', 'og:description', 'twitter:description'].each do |name|
413
- it "should preserve whitespace in a useful #{name} value" do
468
+ it "should strip surrounding whitespace from a useful #{name} value" do
414
469
  description = " \n Useful description\t "
415
470
  html = %(<html><head><meta name="#{name}" content="#{description}"></head></html>)
416
471
  page = MetaInspector.new('http://example.com/', document: html)
417
472
 
418
- expect(page.best_description).to eq(description)
473
+ expect(page.best_description).to eq('Useful description')
419
474
  end
420
475
  end
421
476
 
data/spec/parser_spec.rb CHANGED
@@ -5,16 +5,6 @@ describe MetaInspector::Parser do
5
5
  let(:doc) { MetaInspector::Document.new('http://pagerankalert.com') }
6
6
  let(:parser) { MetaInspector::Parser.new(doc) }
7
7
 
8
- it 'returns the first feed URL through the deprecated feed method' do
9
- expect { expect(parser.feed).to eq('http://feeds.feedburner.com/PageRankAlert') }
10
- .to output(/DEPRECATION.*page\.feed.*6\.0.*page\.feeds/).to_stderr
11
- end
12
-
13
- it 'returns the favicon URL through the deprecated favicon method' do
14
- expect { expect(parser.favicon).to eq('http://pagerankalert.com/src/favicon.ico') }
15
- .to output(/DEPRECATION.*page\.favicon.*6\.0.*page\.images\.favicon/).to_stderr
16
- end
17
-
18
8
  it "should have a Nokogiri::HTML5::Document as parsed" do
19
9
  expect(parser.parsed.class).to eq(Nokogiri::HTML5::Document)
20
10
  end
@@ -52,7 +52,7 @@ RSpec.describe 'request error handling' do
52
52
  'Content-Type' => 'text/html', 'Content-Encoding' => 'gzip'
53
53
  })
54
54
 
55
- expect(MetaInspector.new(url).title).to eq('')
55
+ expect(MetaInspector.new(url).title).to be_nil
56
56
  end
57
57
  end
58
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metainspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.22.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Iniesta