ndd-url_checker 0.3.2 → 0.3.3

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/LICENSE.txt +18 -17
  4. data/README.md +14 -7
  5. data/lib/ndd/url_checker.rb +6 -0
  6. data/lib/ndd/url_checker/reporting_url_checker.rb +4 -0
  7. data/lib/ndd/url_checker/status.rb +1 -0
  8. data/lib/ndd/url_checker/status_decorator.rb +11 -0
  9. data/lib/ndd/url_checker/version.rb +5 -0
  10. metadata +9 -249
  11. data/.document +0 -5
  12. data/.rspec +0 -1
  13. data/.ruby-gemset +0 -1
  14. data/.ruby-version +0 -1
  15. data/.travis.yml +0 -16
  16. data/Gemfile +0 -50
  17. data/Gemfile.lock +0 -162
  18. data/Guardfile +0 -38
  19. data/Rakefile +0 -51
  20. data/VERSION +0 -1
  21. data/lib/ndd/url_checker/reporting_url_checker.csv.erb +0 -4
  22. data/lib/ndd/url_checker/reporting_url_checker.html.erb +0 -188
  23. data/lib/ndd/url_checker/reporting_url_checker.json.erb +0 -27
  24. data/ndd-url_checker.gemspec +0 -134
  25. data/spec/ndd/url_checker/abstract_url_checker_spec.rb +0 -11
  26. data/spec/ndd/url_checker/blocking_url_checker_spec.rb +0 -12
  27. data/spec/ndd/url_checker/forked_url_checker_spec.rb +0 -12
  28. data/spec/ndd/url_checker/parallel_url_checker_spec.rb +0 -62
  29. data/spec/ndd/url_checker/reporting_url_checker/custom.txt.erb +0 -8
  30. data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.csv +0 -6
  31. data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.html +0 -246
  32. data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.json +0 -49
  33. data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.txt +0 -26
  34. data/spec/ndd/url_checker/reporting_url_checker/single_url.csv +0 -2
  35. data/spec/ndd/url_checker/reporting_url_checker/single_url.html +0 -182
  36. data/spec/ndd/url_checker/reporting_url_checker/single_url.json +0 -25
  37. data/spec/ndd/url_checker/reporting_url_checker/single_url.txt +0 -6
  38. data/spec/ndd/url_checker/reporting_url_checker_spec.rb +0 -131
  39. data/spec/ndd/url_checker/status_decorator_spec.rb +0 -208
  40. data/spec/ndd/url_checker/status_spec.rb +0 -510
  41. data/spec/ndd/url_checker/threaded_url_checker_spec.rb +0 -13
  42. data/spec/spec_helper.rb +0 -81
  43. data/spec/support/multiple_url_checker_spec.rb +0 -58
  44. data/spec/support/single_url_checker_spec.rb +0 -252
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe NDD::UrlChecker::ThreadedUrlChecker do
4
-
5
- before(:all) do
6
- # Logging.logger.root.level = :debug
7
- end
8
-
9
- # TODO
10
- # it_behaves_like 'a single URL checker'
11
- # it_behaves_like 'a multiple URL checker', skip_verify = true
12
-
13
- end
data/spec/spec_helper.rb DELETED
@@ -1,81 +0,0 @@
1
- # encoding: utf-8
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
4
-
5
- require 'rubygems'
6
- require 'spork'
7
-
8
-
9
- # ----------------------------------------------------------------------------------------------------------------------
10
- # Spork prefork
11
- # Loading more in this block will cause your tests to run faster. However, if you change any
12
- # configuration or code from libraries loaded here, you'll need to restart spork for it take effect.
13
- # ----------------------------------------------------------------------------------------------------------------------
14
-
15
- lib_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
16
- spec_dir = File.dirname(__FILE__)
17
-
18
- Spork.prefork do
19
-
20
- # ----- load path
21
-
22
- $LOAD_PATH.unshift(lib_path)
23
- $LOAD_PATH.unshift(spec_dir)
24
-
25
- # ----- requirements
26
-
27
- require 'logging'
28
- require 'rspec'
29
- require 'rspec/collection_matchers'
30
- require 'tempfile'
31
- require 'webmock/rspec'
32
-
33
- # ----- code coverage
34
-
35
- if ENV['COVERAGE'] and not ENV['DRB']
36
- require 'simplecov'
37
- SimpleCov.start 'test_frameworks'
38
- end
39
-
40
- # ----- logging
41
-
42
- Logging.logger.root.appenders = Logging.appenders.stdout
43
- Logging.logger.root.level = :off
44
-
45
- # ----- RSpec configuration
46
-
47
- RSpec.configure do |config|
48
-
49
- config.mock_with :rspec
50
-
51
- # ----- filters
52
- config.alias_example_to :fit, :focused
53
- config.disable_monkey_patching!
54
- config.filter_run_including :focused
55
- config.order = 'random'
56
- config.run_all_when_everything_filtered = true
57
-
58
- end
59
-
60
- end
61
-
62
-
63
- # ----------------------------------------------------------------------------------------------------------------------
64
- # Spork each_run
65
- # This code will be run each time you run your specs.
66
- # ----------------------------------------------------------------------------------------------------------------------
67
-
68
- Spork.each_run do
69
-
70
- # ----- code coverage
71
-
72
- # if ENV['COVERAGE'] and not ENV['DRB']
73
- # require 'simplecov'
74
- # SimpleCov.start 'test_frameworks'
75
- # end
76
-
77
- # ----- files reload
78
- Dir["#{lib_path}/**/*.rb"].each { |file| require file }
79
- Dir["#{spec_dir}/support/**/*.rb"].each { |file| require file }
80
-
81
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # @param [Boolean] skip_verify because a forked process cannot be verified
4
- RSpec.shared_examples 'a multiple URL checker' do |skip_verify|
5
-
6
- before(:all) do
7
- WebMock.allow_net_connect!
8
- end
9
-
10
- before(:each) do
11
- WebMock.reset!
12
- end
13
-
14
-
15
- # ------------------------------------------------------------------------------------------------- multiple URL -----
16
- context 'when there are multiple URLs' do
17
- let!(:stub1) { stub_request(:get, 'http://www.valid.mock/').to_return(status: 200) }
18
- let!(:stub2) { stub_request(:get, 'http://www.unknown.mock/').to_raise(SocketError) }
19
-
20
- describe '#check' do
21
- it 'returns a map of the results indexed by the URI' do
22
- results = subject.check('http://www.valid.mock/', 'http://www.unknown.mock/')
23
- expect(results).to have(2).items
24
- results_hash = results.reduce({}) { |hash, result| hash[result.uri] = result; hash }
25
-
26
- status1 = results_hash['http://www.valid.mock/']
27
- expect(status1.code).to eq :direct
28
- expect(status1.uri).to eq 'http://www.valid.mock/'
29
- expect(status1.error).to be_nil
30
-
31
- status2 = results_hash['http://www.unknown.mock/']
32
- expect(status2.code).to eq :failed
33
- expect(status2.uri).to eq 'http://www.unknown.mock/'
34
- expect(status2.error).to be_a StandardError
35
- end
36
- end
37
-
38
- after(:each) do
39
- unless skip_verify
40
- expect(stub1).to have_been_requested
41
- expect(stub2).to have_been_requested
42
- end
43
- end
44
- end
45
-
46
-
47
- # ------------------------------------------------------------------------------------------------------ private -----
48
- private
49
-
50
- def stub_redirect(from, to)
51
- stub_request(:get, from).to_return(status: 301, headers: {Location: to})
52
- end
53
- end
54
-
55
- # expect(subject.valid?('http://www.google.fr')).to be_truthy
56
- # expect(subject.valid?('http://www.google.fr/')).to be_truthy
57
- # expect(subject.valid?('http://www.invalid123456789xyz.com')).to be_falsey
58
- # expect(subject.valid?('http://www.invalid123456789xyz.com/')).to be_falsey
@@ -1,252 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.shared_examples 'a single URL checker' do
4
-
5
- before(:all) do
6
- WebMock.allow_net_connect!
7
- end
8
-
9
- before(:each) do
10
- WebMock.reset!
11
- end
12
-
13
- # ------------------------------------------------------------------------------------------------------- direct -----
14
- context 'when the URL is valid' do
15
- let!(:stub) { stub_request(:get, 'http://www.valid.mock/').to_return(status: 200) }
16
-
17
- describe '#check' do
18
- let (:status) { subject.check('http://www.valid.mock/') }
19
-
20
- it 'returns a status with a :direct code' do
21
- expect(status.code).to eq :direct
22
- end
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
29
- expect(status.uris).to eq ['http://www.valid.mock/']
30
- end
31
-
32
- it 'returns a status with no error' do
33
- expect(status.error).to be_nil
34
- end
35
- end
36
-
37
- after(:each) do
38
- expect(stub).to have_been_requested
39
- end
40
- end
41
-
42
- # --------------------------------------------------------------------------------------------------- redirected -----
43
- context 'when there are not too many redirects' do
44
- let!(:stub1) { stub_redirect('http://www.redirect1.mock/', 'http://www.redirect2.mock/') }
45
- let!(:stub2) { stub_redirect('http://www.redirect2.mock/', 'http://www.redirect3.mock/') }
46
- let!(:stub3) { stub_redirect('http://www.redirect3.mock/', 'http://www.redirect4.mock/') }
47
- let!(:stub4) { stub_request(:get, 'http://www.redirect4.mock/').to_return(status: 200) }
48
-
49
- describe '#check' do
50
- let (:status) { subject.check('http://www.redirect1.mock/') }
51
-
52
- it 'returns a status with a :direct code' do
53
- expect(status.code).to eq :redirected
54
- end
55
-
56
- it 'returns a status with the requested URI' do
57
- expect(status.uri).to eq 'http://www.redirect1.mock/'
58
- end
59
-
60
- it 'returns a status with the requested URIs' do
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
69
- end
70
- end
71
-
72
- after(:each) do
73
- [stub1, stub2, stub3, stub4].each { |stub| expect(stub).to have_been_requested }
74
- end
75
- end
76
-
77
- # ------------------------------------------------------------------------------------------- too_many_redirects -----
78
- context 'when there are too many redirects' do
79
- let!(:stub1) { stub_redirect('http://www.redirect1.mock/', 'http://www.redirect2.mock/') }
80
- let!(:stub2) { stub_redirect('http://www.redirect2.mock/', 'http://www.redirect3.mock/') }
81
- let!(:stub3) { stub_redirect('http://www.redirect3.mock/', 'http://www.redirect4.mock/') }
82
- let!(:stub4) { stub_redirect('http://www.redirect4.mock/', 'relative') }
83
- let!(:stub5) { stub_redirect('http://www.redirect4.mock/relative', 'http://www.redirect5.mock/') }
84
-
85
- describe '#check' do
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/
98
- http://www.redirect2.mock/
99
- http://www.redirect3.mock/
100
- http://www.redirect4.mock/
101
- http://www.redirect4.mock/relative
102
- http://www.redirect5.mock/)
103
- end
104
-
105
- it 'returns a status with no error' do
106
- expect(status.error).to be_nil
107
- end
108
- end
109
-
110
- after(:each) do
111
- [stub1, stub2, stub3, stub4, stub5].each { |stub| expect(stub).to have_been_requested }
112
- end
113
- end
114
-
115
- # ------------------------------------------------------------------------------------------------- unknown_host -----
116
- context 'when the URL cannot be resolved' do
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) }
121
-
122
- describe '#check' do
123
- let (:status) { subject.check('http://www.redirect1.mock/') }
124
-
125
- it 'returns a status with a :unknown_host code' do
126
- expect(status.code).to eq :unknown_host
127
- end
128
-
129
- it 'returns a status with the requested URI' do
130
- expect(status.uri).to eq 'http://www.redirect1.mock/'
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
-
139
- it 'returns a status with no error' do
140
- expect(status.error).to be_nil
141
- end
142
- end
143
-
144
- after(:each) do
145
- [stub1, stub2, stub3].each { |stub| expect(stub).to have_been_requested }
146
- end
147
- end
148
-
149
- # ------------------------------------------------------------------------------------------------- socket error -----
150
- context 'when there is a socket error' do
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) }
154
-
155
- describe '#check' do
156
- let (:status) { subject.check('http://www.redirect1.mock/') }
157
-
158
- it 'returns a status with a :failed code' do
159
- expect(status.code).to eq :failed
160
- end
161
-
162
- it 'returns a status with the requested URI' do
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/)
170
- end
171
-
172
- it 'returns a status with the raised error' do
173
- expect(status.error).to be_a SocketError
174
- end
175
- end
176
-
177
- after(:each) do
178
- [stub1, stub2, stub3].each { |stub| expect(stub).to have_been_requested }
179
- end
180
- end
181
-
182
- # --------------------------------------------------------------------------------------- expected network error -----
183
- context 'when there is an expected network error' do
184
- let!(:stub) { stub_request(:get, 'http://www.error.mock/').to_return(status: 400) }
185
-
186
- describe '#check' do
187
- let (:status) { subject.check('http://www.error.mock/') }
188
-
189
- it 'returns a status with a :failed code' do
190
- expect(status.code).to eq :failed
191
- end
192
-
193
- it 'returns a status with the requested URI' do
194
- expect(status.uri).to eq 'http://www.error.mock/'
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
-
201
- it 'returns a status with the raised error' do
202
- expect(status.error).to be_a Net::HTTPBadRequest
203
- end
204
- end
205
-
206
- after(:each) do
207
- expect(stub).to have_been_requested
208
- end
209
- end
210
-
211
- # --------------------------------------------------------------------------------------------- unexpected error -----
212
- context 'when there is an unexpected error' do
213
- let!(:stub) { stub_request(:get, 'http://www.error.mock/').to_raise('Some error') }
214
-
215
- describe '#check' do
216
- let (:status) { subject.check('http://www.error.mock/') }
217
-
218
- it 'returns a status with a :failed code' do
219
- expect(status.code).to eq :failed
220
- end
221
-
222
- it 'returns a status with the requested URI' do
223
- expect(status.uri).to eq 'http://www.error.mock/'
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
-
230
- it 'returns a status with the raised error' do
231
- expect(status.error).to be_a StandardError
232
- end
233
- end
234
-
235
- after(:each) do
236
- expect(stub).to have_been_requested
237
- end
238
- end
239
-
240
-
241
- # ------------------------------------------------------------------------------------------------------ private -----
242
- private
243
-
244
- def stub_redirect(from, to)
245
- stub_request(:get, from).to_return(status: 301, headers: {Location: to})
246
- end
247
- end
248
-
249
- # expect(subject.valid?('http://www.google.fr')).to be_truthy
250
- # expect(subject.valid?('http://www.google.fr/')).to be_truthy
251
- # expect(subject.valid?('http://www.invalid123456789xyz.com')).to be_falsey
252
- # expect(subject.valid?('http://www.invalid123456789xyz.com/')).to be_falsey