metainspector 3.1.1 → 3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9335bc2c238b50b6674633cbed8575ca4b8f839d
4
- data.tar.gz: aa6f0afd00f2f42662a2d0048851476bf0da8afe
3
+ metadata.gz: 553be427edfb113d96f5956a55d184ecce6c2874
4
+ data.tar.gz: 5c11f4b906d2fafa9bda9669521ac1cb1a958734
5
5
  SHA512:
6
- metadata.gz: 29694513da14081b5197bd3e7ebe2a52e8b0a64cd629ff5f45425a08a546651df454381da0f8b89cb98a03b4b925dbf11ece9baa9cef61c5e643afdf8ccd5cd4
7
- data.tar.gz: df6617ce0020ea959dd3e5707dfff94b1157f62cf305866c86052d38bc36c6ebfe3748753d79d3c96a2f2ba36ffd789f426699ac893c3094b2e04d0d9740f53b
6
+ metadata.gz: 0188e170dce0f4a4e94b5f91c280b6bc597dfe8b14eb3795d4bf0f7719a282ae04b1277c1b9bb02675f27891d2ddc23781e444bc78b47e95c61151a579bf92f3
7
+ data.tar.gz: 51f3d50f0d1f575f5bafe3977bc9fbac3de740a7caf89a92b54a47e25408ba29946e9e09ea0a475462b7ded4651a237da72f8b8cd50e2672742a20caa9f692bb
@@ -68,8 +68,7 @@ module MetaInspector
68
68
  :html_content_only => false,
69
69
  :warn_level => :raise,
70
70
  :headers => {'User-Agent' => "MetaInspector/#{MetaInspector::VERSION} (+https://github.com/jaimeiniesta/metainspector)"},
71
- :allow_redirections => true,
72
- :exception_log => MetaInspector::ExceptionLog.new
71
+ :allow_redirections => true
73
72
  }
74
73
  end
75
74
 
@@ -7,8 +7,7 @@ module MetaInspector
7
7
  attr_reader :exceptions, :warn_level
8
8
 
9
9
  def initialize(options = {})
10
- options = defaults.merge(options)
11
- @warn_level = options[:warn_level]
10
+ @warn_level = options[:warn_level] || :raise
12
11
  @exceptions = []
13
12
  end
14
13
 
@@ -30,11 +29,5 @@ module MetaInspector
30
29
  warn "ExceptionLog#ok? should only be used when warn_level is :store"
31
30
  end
32
31
  end
33
-
34
- private
35
-
36
- def defaults
37
- { warn_level: :raise }
38
- end
39
32
  end
40
33
  end
@@ -8,8 +8,6 @@ module MetaInspector
8
8
  include MetaInspector::Exceptionable
9
9
 
10
10
  def initialize(document, options = {})
11
- options = defaults.merge(options)
12
-
13
11
  @document = document
14
12
  @exception_log = options[:exception_log]
15
13
  end
@@ -106,10 +104,6 @@ module MetaInspector
106
104
 
107
105
  private
108
106
 
109
- def defaults
110
- { exception_log: MetaInspector::ExceptionLog.new }
111
- end
112
-
113
107
  def meta_tags_by(attribute)
114
108
  hash = {}
115
109
  parsed.css("meta[@#{attribute}]").map do |tag|
@@ -9,8 +9,7 @@ module MetaInspector
9
9
  include MetaInspector::Exceptionable
10
10
 
11
11
  def initialize(initial_url, options = {})
12
- options = defaults.merge(options)
13
- @exception_log = options[:exception_log]
12
+ @exception_log = options[:exception_log]
14
13
 
15
14
  self.url = initial_url
16
15
  end
@@ -50,10 +49,6 @@ module MetaInspector
50
49
 
51
50
  private
52
51
 
53
- def defaults
54
- { exception_log: MetaInspector::ExceptionLog.new }
55
- end
56
-
57
52
  # Adds 'http' as default scheme, if there is none
58
53
  def with_default_scheme(url)
59
54
  parsed(url) && parsed(url).scheme.nil? ? 'http://' + url : url
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module MetaInspector
4
- VERSION = "3.1.1"
4
+ VERSION = "3.2.0"
5
5
  end
@@ -89,13 +89,60 @@ describe MetaInspector::Document do
89
89
 
90
90
  tar_url.title
91
91
  end
92
+
93
+ context 'when a warn_level of :store is passed in' do
94
+ before do
95
+ @bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :store)
96
+ @bad_request.title
97
+ end
98
+
99
+ it 'stores the exceptions' do
100
+ @bad_request.exceptions.should_not be_empty
101
+ end
102
+
103
+ it 'makes ok? to return false' do
104
+ @bad_request.should_not be_ok
105
+ end
106
+ end
107
+
108
+ context 'when a warn_level of :warn is passed in' do
109
+ before do
110
+ $stderr = StringIO.new
111
+ end
112
+
113
+ after do
114
+ $stderr = STDERR
115
+ end
116
+
117
+ it 'warns on STDERR' do
118
+ bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :warn)
119
+ bad_request.title
120
+
121
+ $stderr.rewind
122
+ $stderr.string.chomp.should eq("The url provided contains image/png content instead of text/html content")
123
+ end
124
+
125
+ it 'does not raise an exception' do
126
+ expect {
127
+ bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :warn)
128
+ bad_request.title
129
+ }.to_not raise_exception
130
+ end
131
+
132
+ it 'does not store exceptions' do
133
+ bad_request = MetaInspector::Document.new('http://pagerankalert.com/image.png', html_content_only: true, warn_level: :warn)
134
+ bad_request.title
135
+
136
+ expect( bad_request.exceptions ).to be_empty
137
+ end
138
+ end
92
139
  end
93
140
 
94
141
  describe 'headers' do
95
142
  it "should include default headers" do
96
143
  url = "http://pagerankalert.com/"
97
144
  expected_headers = {'User-Agent' => "MetaInspector/#{MetaInspector::VERSION} (+https://github.com/jaimeiniesta/metainspector)"}
98
-
145
+
99
146
  headers = {}
100
147
  headers.should_receive(:merge!).with(expected_headers)
101
148
  Faraday::Connection.any_instance.stub(:headers){headers}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metainspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Iniesta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri