ndd-url_checker 0.2.1 → 0.3.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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -1
- data/Gemfile.lock +57 -44
- data/README.md +5 -2
- data/VERSION +1 -1
- data/lib/ndd/url_checker.rb +2 -0
- data/lib/ndd/url_checker/blocking_url_checker.rb +7 -4
- data/lib/ndd/url_checker/forked_url_checker.rb +4 -2
- data/lib/ndd/url_checker/reporting_url_checker.csv.erb +2 -2
- data/lib/ndd/url_checker/reporting_url_checker.html.erb +171 -80
- data/lib/ndd/url_checker/reporting_url_checker.json.erb +16 -9
- data/lib/ndd/url_checker/reporting_url_checker.rb +22 -11
- data/lib/ndd/url_checker/status.rb +1 -1
- data/lib/ndd/url_checker/status_decorator.rb +64 -0
- data/ndd-url_checker.gemspec +6 -4
- data/spec/ndd/url_checker/abstract_url_checker_spec.rb +1 -1
- data/spec/ndd/url_checker/blocking_url_checker_spec.rb +1 -1
- data/spec/ndd/url_checker/forked_url_checker_spec.rb +1 -1
- data/spec/ndd/url_checker/parallel_url_checker_spec.rb +1 -1
- data/spec/ndd/url_checker/reporting_url_checker/custom.txt.erb +2 -2
- data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.csv +5 -3
- data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.html +227 -92
- data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.json +29 -10
- data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.txt +12 -2
- data/spec/ndd/url_checker/reporting_url_checker/single_url.csv +1 -1
- data/spec/ndd/url_checker/reporting_url_checker/single_url.html +163 -78
- data/spec/ndd/url_checker/reporting_url_checker/single_url.json +14 -7
- data/spec/ndd/url_checker/reporting_url_checker_spec.rb +29 -12
- data/spec/ndd/url_checker/status_decorator_spec.rb +208 -0
- data/spec/ndd/url_checker/status_spec.rb +10 -10
- data/spec/ndd/url_checker/threaded_url_checker_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -3
- data/spec/support/multiple_url_checker_spec.rb +4 -4
- data/spec/support/single_url_checker_spec.rb +74 -21
- metadata +5 -3
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# ----------------------------------------------------------------------------------------------------------------------
|
4
|
+
RSpec.shared_examples 'a status' do |code|
|
5
|
+
context '#uri' do
|
6
|
+
it 'is decorated' do
|
7
|
+
expect(decorator.uri).to eq uri
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context '#code' do
|
12
|
+
it 'is decorated' do
|
13
|
+
expect(decorator.code).to eq code
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# ----------------------------------------------------------------------------------------------------------------------
|
19
|
+
|
20
|
+
RSpec.describe NDD::UrlChecker::StatusDecorator do
|
21
|
+
|
22
|
+
let(:uri) { 'http://www.example.com' }
|
23
|
+
let(:status) { NDD::UrlChecker::Status.new(uri) }
|
24
|
+
let(:decorator) { NDD::UrlChecker::StatusDecorator.new(status) }
|
25
|
+
|
26
|
+
let(:redirect_uri_1) { 'http://www.redirected1.com' }
|
27
|
+
let(:redirect_uri_2) { 'http://www.redirected2.com' }
|
28
|
+
let(:redirect_uri_3) { 'http://www.redirected3.com' }
|
29
|
+
|
30
|
+
|
31
|
+
# ------------------------------------------------------------------------------------------------------- direct -----
|
32
|
+
context 'when code is :direct' do
|
33
|
+
before(:each) { status.direct }
|
34
|
+
|
35
|
+
it_behaves_like 'a status', :direct
|
36
|
+
|
37
|
+
context '#details_title' do
|
38
|
+
it 'returns nil' do
|
39
|
+
expect(decorator.details_title).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#details_body' do
|
44
|
+
it 'returns nil' do
|
45
|
+
expect(decorator.details_body).to be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# ------------------------------------------------------------------------------------------------------- failed -----
|
52
|
+
context 'when code is :failed' do
|
53
|
+
context 'and received a Net::HTTPResponse' do
|
54
|
+
before(:each) do
|
55
|
+
response = Net::HTTPForbidden.new('1.1', 403, 'forbidden!')
|
56
|
+
status.failed(response)
|
57
|
+
allow(response).to receive(:body).and_return('The forbidden body!')
|
58
|
+
end
|
59
|
+
|
60
|
+
it_behaves_like 'a status', :failed
|
61
|
+
|
62
|
+
context '#details_title' do
|
63
|
+
it 'returns the name of the class' do
|
64
|
+
expect(decorator.details_title).to eq 'Net::HTTPForbidden'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context '#details_body' do
|
69
|
+
it 'returns the body of the response' do
|
70
|
+
expect(decorator.details_body).to eq 'The forbidden body!'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# --------------------------------------------------------------------------------------------------- redirected -----
|
77
|
+
context 'when code is :redirected' do
|
78
|
+
context 'and redirected 1 time' do
|
79
|
+
before(:each) { status.redirected(redirect_uri_1) }
|
80
|
+
|
81
|
+
it_behaves_like 'a status', :redirected
|
82
|
+
|
83
|
+
context '#details_title' do
|
84
|
+
it 'returns the number of redirect' do
|
85
|
+
expect(decorator.details_title).to eq 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context '#details_body' do
|
90
|
+
it 'returns the list of redirected URIs' do
|
91
|
+
expect(decorator.details_body).to eq <<-DOC.gsub(/^ +/, '')
|
92
|
+
- http://www.example.com
|
93
|
+
- http://www.redirected1.com
|
94
|
+
DOC
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'and redirected 3 times' do
|
100
|
+
before(:each) do
|
101
|
+
status
|
102
|
+
.redirected(redirect_uri_1)
|
103
|
+
.redirected(redirect_uri_2)
|
104
|
+
.redirected(redirect_uri_3)
|
105
|
+
end
|
106
|
+
|
107
|
+
it_behaves_like 'a status', :redirected
|
108
|
+
|
109
|
+
context '#details_title' do
|
110
|
+
it 'returns the number of redirect' do
|
111
|
+
expect(decorator.details_title).to eq 3
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context '#details_body' do
|
116
|
+
it 'returns the list of redirected URIs' do
|
117
|
+
expect(decorator.details_body).to eq <<-DOC.gsub(/^ +/, '')
|
118
|
+
- http://www.example.com
|
119
|
+
- http://www.redirected1.com
|
120
|
+
- http://www.redirected2.com
|
121
|
+
- http://www.redirected3.com
|
122
|
+
DOC
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# ------------------------------------------------------------------------------------------- too_many_redirects -----
|
129
|
+
context 'when code is :too_many_redirects' do
|
130
|
+
context 'and redirected 1 time' do
|
131
|
+
before(:each) { status.redirected(redirect_uri_1).too_many_redirects }
|
132
|
+
|
133
|
+
it_behaves_like 'a status', :too_many_redirects
|
134
|
+
|
135
|
+
context '#details_title' do
|
136
|
+
it 'returns the number of redirect' do
|
137
|
+
expect(decorator.details_title).to eq 1
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context '#details_body' do
|
142
|
+
it 'returns the list of redirected URIs' do
|
143
|
+
expect(decorator.details_body).to eq <<-DOC.gsub(/^ +/, '')
|
144
|
+
- http://www.example.com
|
145
|
+
- http://www.redirected1.com
|
146
|
+
DOC
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'and redirected 3 times' do
|
152
|
+
before(:each) do
|
153
|
+
status
|
154
|
+
.redirected(redirect_uri_1)
|
155
|
+
.redirected(redirect_uri_2)
|
156
|
+
.redirected(redirect_uri_3)
|
157
|
+
.too_many_redirects
|
158
|
+
end
|
159
|
+
|
160
|
+
it_behaves_like 'a status', :too_many_redirects
|
161
|
+
|
162
|
+
context '#details_title' do
|
163
|
+
it 'returns the number of redirect' do
|
164
|
+
expect(decorator.details_title).to eq 3
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context '#details_body' do
|
169
|
+
it 'returns the list of redirected URIs' do
|
170
|
+
expect(decorator.details_body).to eq <<-DOC.gsub(/^ +/, '')
|
171
|
+
- http://www.example.com
|
172
|
+
- http://www.redirected1.com
|
173
|
+
- http://www.redirected2.com
|
174
|
+
- http://www.redirected3.com
|
175
|
+
DOC
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# ------------------------------------------------------------------------------------------------- unknown_host -----
|
182
|
+
context 'when code is :unknown_host' do
|
183
|
+
before(:each) { status.redirected(redirect_uri_1).unknown_host }
|
184
|
+
|
185
|
+
it_behaves_like 'a status', :unknown_host
|
186
|
+
|
187
|
+
context '#code_as_css' do
|
188
|
+
it 'returns a CSS class suffix' do
|
189
|
+
expect(decorator.code_as_css).to eq 'unknown-host'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context '#details_title' do
|
194
|
+
it 'returns the unknown URI' do
|
195
|
+
expect(decorator.details_title).to eq redirect_uri_1
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context '#details_body' do
|
200
|
+
it 'returns the list of redirected URIs' do
|
201
|
+
expect(decorator.details_body).to eq <<-DOC.gsub(/^ +/, '')
|
202
|
+
- http://www.example.com
|
203
|
+
- http://www.redirected1.com
|
204
|
+
DOC
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe NDD::UrlChecker::Status do
|
3
|
+
RSpec.describe NDD::UrlChecker::Status do
|
4
4
|
|
5
5
|
# ------------------------------------------------------------------------------------------------------ unknown -----
|
6
6
|
context 'when initialized' do
|
@@ -54,7 +54,7 @@ describe NDD::UrlChecker::Status do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context '#failed' do
|
57
|
-
let!(:new_status) { status.failed('some error') }
|
57
|
+
let!(:new_status) { status.failed(StandardError.new('some error')) }
|
58
58
|
it 'changes the code to :failed' do
|
59
59
|
expect(status.code).to eq :failed
|
60
60
|
end
|
@@ -149,7 +149,7 @@ describe NDD::UrlChecker::Status do
|
|
149
149
|
|
150
150
|
context '#failed' do
|
151
151
|
it 'raises an error' do
|
152
|
-
expect { status.failed('some error') }.to raise_error(/from :direct to :failed is forbidden/)
|
152
|
+
expect { status.failed(StandardError.new('some error')) }.to raise_error(/from :direct to :failed is forbidden/)
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -181,7 +181,7 @@ describe NDD::UrlChecker::Status do
|
|
181
181
|
# ------------------------------------------------------------------------------------------------------- failed -----
|
182
182
|
context 'when code is :failed' do
|
183
183
|
let(:uri) { 'http://www.example.com' }
|
184
|
-
let(:status) { NDD::UrlChecker::Status.new(uri).failed('some error') }
|
184
|
+
let(:status) { NDD::UrlChecker::Status.new(uri).failed(StandardError.new('some error')) }
|
185
185
|
|
186
186
|
context '#uri' do
|
187
187
|
it 'returns the original URI' do
|
@@ -215,7 +215,7 @@ describe NDD::UrlChecker::Status do
|
|
215
215
|
|
216
216
|
context '#error' do
|
217
217
|
it 'returns the error' do
|
218
|
-
expect(status.error).to eq 'some error'
|
218
|
+
expect(status.error).to eq StandardError.new('some error')
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -227,7 +227,7 @@ describe NDD::UrlChecker::Status do
|
|
227
227
|
|
228
228
|
context '#failed' do
|
229
229
|
it 'raises an error' do
|
230
|
-
expect { status.failed('some error') }.to raise_error(/from :failed to :failed is forbidden/)
|
230
|
+
expect { status.failed(StandardError.new('some error')) }.to raise_error(/from :failed to :failed is forbidden/)
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -251,7 +251,7 @@ describe NDD::UrlChecker::Status do
|
|
251
251
|
|
252
252
|
context '#to_s' do
|
253
253
|
it 'returns the status representation' do
|
254
|
-
expect(status.to_s).to match %r{^#<NDD::UrlChecker::Status:0[xX][0-9a-fA-F]+ @uris=\["http://www.example.com"\], @code=:failed, @error
|
254
|
+
expect(status.to_s).to match %r{^#<NDD::UrlChecker::Status:0[xX][0-9a-fA-F]+ @uris=\["http://www.example.com"\], @code=:failed, @error=#<StandardError: some error>>$}
|
255
255
|
end
|
256
256
|
end
|
257
257
|
end
|
@@ -305,7 +305,7 @@ describe NDD::UrlChecker::Status do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
context '#failed' do
|
308
|
-
let!(:new_status) { status.failed('some error') }
|
308
|
+
let!(:new_status) { status.failed(StandardError.new('some error')) }
|
309
309
|
it 'changes the code to :failed' do
|
310
310
|
expect(status.code).to eq :failed
|
311
311
|
end
|
@@ -400,7 +400,7 @@ describe NDD::UrlChecker::Status do
|
|
400
400
|
|
401
401
|
context '#failed' do
|
402
402
|
it 'raises an error' do
|
403
|
-
expect { status.failed('some error') }.to raise_error(/from :too_many_redirects to :failed is forbidden/)
|
403
|
+
expect { status.failed(StandardError.new('some error')) }.to raise_error(/from :too_many_redirects to :failed is forbidden/)
|
404
404
|
end
|
405
405
|
end
|
406
406
|
|
@@ -478,7 +478,7 @@ describe NDD::UrlChecker::Status do
|
|
478
478
|
|
479
479
|
context '#failed' do
|
480
480
|
it 'raises an error' do
|
481
|
-
expect { status.failed('some error') }.to raise_error(/from :unknown_host to :failed is forbidden/)
|
481
|
+
expect { status.failed(StandardError.new('some error')) }.to raise_error(/from :unknown_host to :failed is forbidden/)
|
482
482
|
end
|
483
483
|
end
|
484
484
|
|
data/spec/spec_helper.rb
CHANGED
@@ -50,12 +50,10 @@ Spork.prefork do
|
|
50
50
|
|
51
51
|
# ----- filters
|
52
52
|
config.alias_example_to :fit, :focused
|
53
|
+
config.disable_monkey_patching!
|
53
54
|
config.filter_run_including :focused
|
54
55
|
config.order = 'random'
|
55
56
|
config.run_all_when_everything_filtered = true
|
56
|
-
config.expect_with :rspec do |c|
|
57
|
-
c.syntax = :expect
|
58
|
-
end
|
59
57
|
|
60
58
|
end
|
61
59
|
|
@@ -15,11 +15,11 @@ RSpec.shared_examples 'a multiple URL checker' do |skip_verify|
|
|
15
15
|
# ------------------------------------------------------------------------------------------------- multiple URL -----
|
16
16
|
context 'when there are multiple URLs' do
|
17
17
|
let!(:stub1) { stub_request(:get, 'http://www.valid.mock/').to_return(status: 200) }
|
18
|
-
let!(:stub2) { stub_request(:get, 'http://www.
|
18
|
+
let!(:stub2) { stub_request(:get, 'http://www.unknown.mock/').to_raise(SocketError) }
|
19
19
|
|
20
20
|
describe '#check' do
|
21
21
|
it 'returns a map of the results indexed by the URI' do
|
22
|
-
results = subject.check('http://www.valid.mock/', 'http://www.
|
22
|
+
results = subject.check('http://www.valid.mock/', 'http://www.unknown.mock/')
|
23
23
|
expect(results).to have(2).items
|
24
24
|
results_hash = results.reduce({}) { |hash, result| hash[result.uri] = result; hash }
|
25
25
|
|
@@ -28,9 +28,9 @@ RSpec.shared_examples 'a multiple URL checker' do |skip_verify|
|
|
28
28
|
expect(status1.uri).to eq 'http://www.valid.mock/'
|
29
29
|
expect(status1.error).to be_nil
|
30
30
|
|
31
|
-
status2 = results_hash['http://www.
|
31
|
+
status2 = results_hash['http://www.unknown.mock/']
|
32
32
|
expect(status2.code).to eq :failed
|
33
|
-
expect(status2.uri).to eq 'http://www.
|
33
|
+
expect(status2.uri).to eq 'http://www.unknown.mock/'
|
34
34
|
expect(status2.error).to be_a StandardError
|
35
35
|
end
|
36
36
|
end
|
@@ -20,9 +20,15 @@ RSpec.shared_examples 'a single URL checker' do
|
|
20
20
|
it 'returns a status with a :direct code' do
|
21
21
|
expect(status.code).to eq :direct
|
22
22
|
end
|
23
|
+
|
23
24
|
it 'returns a status with the requested URI' do
|
25
|
+
expect(status.uri).to eq 'http://www.valid.mock/'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns a status with the requested URIs' do
|
24
29
|
expect(status.uris).to eq ['http://www.valid.mock/']
|
25
30
|
end
|
31
|
+
|
26
32
|
it 'returns a status with no error' do
|
27
33
|
expect(status.error).to be_nil
|
28
34
|
end
|
@@ -52,7 +58,14 @@ RSpec.shared_examples 'a single URL checker' do
|
|
52
58
|
end
|
53
59
|
|
54
60
|
it 'returns a status with the requested URIs' do
|
55
|
-
expect(status.uris).to eq (
|
61
|
+
expect(status.uris).to eq %w(http://www.redirect1.mock/
|
62
|
+
http://www.redirect2.mock/
|
63
|
+
http://www.redirect3.mock/
|
64
|
+
http://www.redirect4.mock/)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns a status with no error' do
|
68
|
+
expect(status.error).to be_nil
|
56
69
|
end
|
57
70
|
end
|
58
71
|
|
@@ -70,17 +83,27 @@ RSpec.shared_examples 'a single URL checker' do
|
|
70
83
|
let!(:stub5) { stub_redirect('http://www.redirect4.mock/relative', 'http://www.redirect5.mock/') }
|
71
84
|
|
72
85
|
describe '#check' do
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
expect(
|
77
|
-
|
86
|
+
let (:status) { subject.check('http://www.redirect1.mock/') }
|
87
|
+
|
88
|
+
it 'returns a status with a :too_many_redirects code' do
|
89
|
+
expect(status.code).to eq :too_many_redirects
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns a status with the requested URI' do
|
93
|
+
expect(status.uri).to eq 'http://www.redirect1.mock/'
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns a status with the requested URIs' do
|
97
|
+
expect(status.uris).to eq %w(http://www.redirect1.mock/
|
78
98
|
http://www.redirect2.mock/
|
79
99
|
http://www.redirect3.mock/
|
80
100
|
http://www.redirect4.mock/
|
81
101
|
http://www.redirect4.mock/relative
|
82
|
-
http://www.redirect5.mock/
|
83
|
-
|
102
|
+
http://www.redirect5.mock/)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns a status with no error' do
|
106
|
+
expect(status.error).to be_nil
|
84
107
|
end
|
85
108
|
end
|
86
109
|
|
@@ -91,55 +114,73 @@ RSpec.shared_examples 'a single URL checker' do
|
|
91
114
|
|
92
115
|
# ------------------------------------------------------------------------------------------------- unknown_host -----
|
93
116
|
context 'when the URL cannot be resolved' do
|
94
|
-
let!(:
|
95
|
-
|
96
|
-
|
97
|
-
}
|
117
|
+
let!(:error) { SocketError.new('getaddrinfo: Name or service not known') }
|
118
|
+
let!(:stub1) { stub_redirect('http://www.redirect1.mock/', 'http://www.redirect2.mock/') }
|
119
|
+
let!(:stub2) { stub_redirect('http://www.redirect2.mock/', 'http://www.unknown.mock/') }
|
120
|
+
let!(:stub3) { stub_request(:get, 'http://www.unknown.mock/').to_raise(error) }
|
98
121
|
|
99
122
|
describe '#check' do
|
100
|
-
let (:status) { subject.check('http://www.
|
123
|
+
let (:status) { subject.check('http://www.redirect1.mock/') }
|
101
124
|
|
102
125
|
it 'returns a status with a :unknown_host code' do
|
103
126
|
expect(status.code).to eq :unknown_host
|
104
127
|
end
|
128
|
+
|
105
129
|
it 'returns a status with the requested URI' do
|
106
|
-
expect(status.uri).to eq 'http://www.
|
130
|
+
expect(status.uri).to eq 'http://www.redirect1.mock/'
|
107
131
|
end
|
132
|
+
|
133
|
+
it 'returns a status with the requested URIs' do
|
134
|
+
expect(status.uris).to eq %w(http://www.redirect1.mock/
|
135
|
+
http://www.redirect2.mock/
|
136
|
+
http://www.unknown.mock/)
|
137
|
+
end
|
138
|
+
|
108
139
|
it 'returns a status with no error' do
|
109
140
|
expect(status.error).to be_nil
|
110
141
|
end
|
111
142
|
end
|
112
143
|
|
113
144
|
after(:each) do
|
114
|
-
expect(stub).to have_been_requested
|
145
|
+
[stub1, stub2, stub3].each { |stub| expect(stub).to have_been_requested }
|
115
146
|
end
|
116
147
|
end
|
117
148
|
|
118
149
|
# ------------------------------------------------------------------------------------------------- socket error -----
|
119
150
|
context 'when there is a socket error' do
|
120
|
-
let!(:
|
151
|
+
let!(:stub1) { stub_redirect('http://www.redirect1.mock/', 'http://www.redirect2.mock/') }
|
152
|
+
let!(:stub2) { stub_redirect('http://www.redirect2.mock/', 'http://www.invalid.mock/') }
|
153
|
+
let!(:stub3) { stub_request(:get, 'http://www.invalid.mock/').to_raise(SocketError) }
|
121
154
|
|
122
155
|
describe '#check' do
|
123
|
-
let (:status) { subject.check('http://www.
|
156
|
+
let (:status) { subject.check('http://www.redirect1.mock/') }
|
124
157
|
|
125
158
|
it 'returns a status with a :failed code' do
|
126
159
|
expect(status.code).to eq :failed
|
127
160
|
end
|
161
|
+
|
128
162
|
it 'returns a status with the requested URI' do
|
129
|
-
expect(status.uri).to eq 'http://www.
|
163
|
+
expect(status.uri).to eq 'http://www.redirect1.mock/'
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'returns a status with the requested URIs' do
|
167
|
+
expect(status.uris).to eq %w(http://www.redirect1.mock/
|
168
|
+
http://www.redirect2.mock/
|
169
|
+
http://www.invalid.mock/)
|
130
170
|
end
|
171
|
+
|
131
172
|
it 'returns a status with the raised error' do
|
132
173
|
expect(status.error).to be_a SocketError
|
133
174
|
end
|
134
175
|
end
|
135
176
|
|
136
177
|
after(:each) do
|
137
|
-
expect(stub).to have_been_requested
|
178
|
+
[stub1, stub2, stub3].each { |stub| expect(stub).to have_been_requested }
|
138
179
|
end
|
139
180
|
end
|
140
181
|
|
141
|
-
#
|
142
|
-
context 'when there is an
|
182
|
+
# --------------------------------------------------------------------------------------- expected network error -----
|
183
|
+
context 'when there is an expected network error' do
|
143
184
|
let!(:stub) { stub_request(:get, 'http://www.error.mock/').to_return(status: 400) }
|
144
185
|
|
145
186
|
describe '#check' do
|
@@ -148,9 +189,15 @@ RSpec.shared_examples 'a single URL checker' do
|
|
148
189
|
it 'returns a status with a :failed code' do
|
149
190
|
expect(status.code).to eq :failed
|
150
191
|
end
|
192
|
+
|
151
193
|
it 'returns a status with the requested URI' do
|
152
194
|
expect(status.uri).to eq 'http://www.error.mock/'
|
153
195
|
end
|
196
|
+
|
197
|
+
it 'returns a status with the requested URIs' do
|
198
|
+
expect(status.uris).to eq ['http://www.error.mock/']
|
199
|
+
end
|
200
|
+
|
154
201
|
it 'returns a status with the raised error' do
|
155
202
|
expect(status.error).to be_a Net::HTTPBadRequest
|
156
203
|
end
|
@@ -171,9 +218,15 @@ RSpec.shared_examples 'a single URL checker' do
|
|
171
218
|
it 'returns a status with a :failed code' do
|
172
219
|
expect(status.code).to eq :failed
|
173
220
|
end
|
221
|
+
|
174
222
|
it 'returns a status with the requested URI' do
|
175
223
|
expect(status.uri).to eq 'http://www.error.mock/'
|
176
224
|
end
|
225
|
+
|
226
|
+
it 'returns a status with the requested URIs' do
|
227
|
+
expect(status.uris).to eq ['http://www.error.mock/']
|
228
|
+
end
|
229
|
+
|
177
230
|
it 'returns a status with the raised error' do
|
178
231
|
expect(status.error).to be_a StandardError
|
179
232
|
end
|