ruby-link-checker 0.4.0 → 0.6.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/CHANGELOG.md +34 -0
- data/LICENSE.md +0 -0
- data/README.md +227 -19
- data/UPGRADING.md +46 -0
- data/lib/ruby-link-checker/async/http/checker.rb +46 -7
- data/lib/ruby-link-checker/async/http/config.rb +4 -0
- data/lib/ruby-link-checker/async/http/result.rb +5 -1
- data/lib/ruby-link-checker/async/http.rb +0 -0
- data/lib/ruby-link-checker/cache.rb +170 -0
- data/lib/ruby-link-checker/callbacks.rb +0 -0
- data/lib/ruby-link-checker/checker.rb +200 -5
- data/lib/ruby-link-checker/config.rb +141 -0
- data/lib/ruby-link-checker/errors/base_error.rb +0 -0
- data/lib/ruby-link-checker/errors/connection_error.rb +23 -0
- data/lib/ruby-link-checker/errors/redirect_limit_error.rb +15 -0
- data/lib/ruby-link-checker/errors/redirect_loop_error.rb +0 -0
- data/lib/ruby-link-checker/errors.rb +2 -0
- data/lib/ruby-link-checker/logger.rb +0 -0
- data/lib/ruby-link-checker/net/http/checker.rb +5 -3
- data/lib/ruby-link-checker/net/http/config.rb +0 -0
- data/lib/ruby-link-checker/net/http/result.rb +5 -1
- data/lib/ruby-link-checker/net/http.rb +0 -0
- data/lib/ruby-link-checker/redirect.rb +11 -0
- data/lib/ruby-link-checker/result.rb +120 -0
- data/lib/ruby-link-checker/task.rb +2 -0
- data/lib/ruby-link-checker/tasks.rb +53 -7
- data/lib/ruby-link-checker/typhoeus/hydra/checker.rb +79 -9
- data/lib/ruby-link-checker/typhoeus/hydra/config.rb +0 -0
- data/lib/ruby-link-checker/typhoeus/hydra/result.rb +5 -1
- data/lib/ruby-link-checker/typhoeus/hydra.rb +0 -0
- data/lib/ruby-link-checker/version.rb +1 -1
- data/lib/ruby-link-checker.rb +2 -0
- data/lib/ruby_link_checker.rb +0 -0
- metadata +26 -72
- data/CONTRIBUTING.md +0 -125
- data/Dangerfile +0 -6
- data/Gemfile +0 -24
- data/Gemfile.lock +0 -334
- data/RELEASING.md +0 -60
- data/Rakefile +0 -18
- data/benchmarks/check.rb +0 -38
- data/benchmarks/data/opensearch.org/links.txt +0 -4270
- data/benchmarks/data/opensearch.org/small.txt +0 -100
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_both.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
- data/coverage/assets/0.13.2/application.css +0 -1
- data/coverage/assets/0.13.2/application.js +0 -7
- data/coverage/assets/0.13.2/colorbox/border.png +0 -0
- data/coverage/assets/0.13.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.13.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.13.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.13.2/favicon_green.png +0 -0
- data/coverage/assets/0.13.2/favicon_red.png +0 -0
- data/coverage/assets/0.13.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.13.2/loading.gif +0 -0
- data/coverage/assets/0.13.2/magnify.png +0 -0
- data/coverage/index.html +0 -10746
- data/ruby-link-checker.gemspec +0 -22
- data/spec/fixtures/200.yml +0 -65
- data/spec/fixtures/301_200.yml +0 -102
- data/spec/fixtures/301_301.yml +0 -114
- data/spec/fixtures/301_400_301_200.yml +0 -185
- data/spec/fixtures/301_403.yml +0 -78
- data/spec/fixtures/308_429.yml +0 -108
- data/spec/fixtures/404.yml +0 -57
- data/spec/fixtures/404_200.yml +0 -89
- data/spec/fixtures/404_404.yml +0 -81
- data/spec/fixtures/429_200.yml +0 -135
- data/spec/fixtures/429_429_200.yml +0 -201
- data/spec/ruby-link-checker/async/http/checker_spec.rb +0 -99
- data/spec/ruby-link-checker/callbacks_spec.rb +0 -76
- data/spec/ruby-link-checker/checker_spec.rb +0 -10
- data/spec/ruby-link-checker/config_spec.rb +0 -39
- data/spec/ruby-link-checker/errors/redirect_loop_error_spec.rb +0 -18
- data/spec/ruby-link-checker/net/http/checker_spec.rb +0 -78
- data/spec/ruby-link-checker/result_error_spec.rb +0 -17
- data/spec/ruby-link-checker/result_spec.rb +0 -41
- data/spec/ruby-link-checker/task_spec.rb +0 -20
- data/spec/ruby-link-checker/tasks_spec.rb +0 -47
- data/spec/ruby-link-checker/typhoeus/hydra/checker_spec.rb +0 -93
- data/spec/ruby-link-checker/version_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -19
- data/spec/support/config.rb +0 -8
- data/spec/support/link_checker.rb +0 -369
- data/spec/support/vcr.rb +0 -13
- data/spec/support/with_result.rb +0 -15
- data/spec/support/with_url.rb +0 -14
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Callbacks do
|
|
6
|
-
subject do
|
|
7
|
-
Class.new do
|
|
8
|
-
include LinkChecker::Callbacks
|
|
9
|
-
|
|
10
|
-
def logger
|
|
11
|
-
@logger ||= Logger.new(nil)
|
|
12
|
-
end
|
|
13
|
-
end.new
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context 'one callback' do
|
|
17
|
-
before do
|
|
18
|
-
allow(subject).to receive(:called!)
|
|
19
|
-
subject.on :foo do |data|
|
|
20
|
-
subject.called! data
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'invokes callback' do
|
|
25
|
-
2.times { subject.send(:callback, :foo, :foo) }
|
|
26
|
-
2.times { subject.send(:callback, :bar, :bar) }
|
|
27
|
-
expect(subject).to have_received(:called!).with(:foo).twice
|
|
28
|
-
expect(subject).not_to have_received(:called!).with(:bar)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
context 'multiple callbacks' do
|
|
33
|
-
before do
|
|
34
|
-
allow(subject).to receive(:called!)
|
|
35
|
-
subject.on :foo, :bar do |data|
|
|
36
|
-
subject.called! data
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'invokes both callbacks' do
|
|
41
|
-
2.times { subject.send(:callback, :foo, :foo) }
|
|
42
|
-
subject.send(:callback, :bar, :bar)
|
|
43
|
-
expect(subject).to have_received(:called!).with(:foo).twice
|
|
44
|
-
expect(subject).to have_received(:called!).with(:bar)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'method_missing' do
|
|
49
|
-
it 'invokes callback for a bang method' do
|
|
50
|
-
allow(subject).to receive(:called!)
|
|
51
|
-
subject.on :foo do |data|
|
|
52
|
-
subject.called! data
|
|
53
|
-
end
|
|
54
|
-
subject.foo! :foo
|
|
55
|
-
expect(subject).to have_received(:called!).with(:foo)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'raises NoMethodError for a non-bang method' do
|
|
59
|
-
expect { subject.foo }.to raise_error NoMethodError
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'when a callback raises an error' do
|
|
64
|
-
before do
|
|
65
|
-
subject.on :foo do
|
|
66
|
-
raise StandardError, 'oops'
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'rescues and logs the error' do
|
|
71
|
-
allow(subject.logger).to receive(:error)
|
|
72
|
-
expect(subject.send(:callback, :foo)).to be false
|
|
73
|
-
expect(subject.logger).to have_received(:error)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
describe LinkChecker::Checker do
|
|
5
|
-
context 'config' do
|
|
6
|
-
it 'requires at least one method' do
|
|
7
|
-
expect { LinkChecker::Checker.new(methods: []) }.to raise_error ArgumentError, 'Missing methods.'
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
describe LinkChecker::Config do
|
|
5
|
-
describe '#configure' do
|
|
6
|
-
context 'methods' do
|
|
7
|
-
before do
|
|
8
|
-
LinkChecker.configure do |config|
|
|
9
|
-
config.methods = %w[GET]
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'sets methods' do
|
|
14
|
-
expect(LinkChecker.config.methods).to eq %w[GET]
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'retries' do
|
|
19
|
-
it 'requires a positive integer' do
|
|
20
|
-
expect { LinkChecker.config.retries = -1 }.to raise_error ArgumentError, 'Invalid number of retries: -1'
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe 'defaults' do
|
|
26
|
-
it 'sets methods' do
|
|
27
|
-
expect(LinkChecker.config.methods).to eq %w[HEAD GET]
|
|
28
|
-
end
|
|
29
|
-
it 'sets user agent' do
|
|
30
|
-
expect(LinkChecker.config.user_agent).to eq "Ruby Link Checker/#{LinkChecker::VERSION}"
|
|
31
|
-
end
|
|
32
|
-
it 'does not set logger' do
|
|
33
|
-
expect(LinkChecker.config.logger).to be nil
|
|
34
|
-
end
|
|
35
|
-
it 'sets retries' do
|
|
36
|
-
expect(LinkChecker.config.retries).to eq 0
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Errors::RedirectLoopError do
|
|
6
|
-
subject(:error) do
|
|
7
|
-
described_class.new(['https://www.example.org', 'https://www.example.org/redirect'])
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it 'returns the last url' do
|
|
11
|
-
expect(error.url).to eq 'https://www.example.org/redirect'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'formats a message with all urls' do
|
|
15
|
-
expect(error.message)
|
|
16
|
-
.to eq 'Redirect loop: https://www.example.org -> https://www.example.org/redirect.'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Net::HTTP::Checker do
|
|
6
|
-
before :all do
|
|
7
|
-
VCR.configure do |config|
|
|
8
|
-
config.hook_into :webmock
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
after do
|
|
13
|
-
LinkChecker::Net::HTTP::Config.reset
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it_behaves_like 'a link checker'
|
|
17
|
-
|
|
18
|
-
describe '.config' do
|
|
19
|
-
it 'returns the Config module' do
|
|
20
|
-
expect(LinkChecker::Net::HTTP.config).to eq LinkChecker::Net::HTTP::Config
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context 'with timeout options', vcr: { cassette_name: '200' } do
|
|
25
|
-
before do
|
|
26
|
-
LinkChecker::Net::HTTP.configure do |config|
|
|
27
|
-
config.read_timeout = 5
|
|
28
|
-
config.open_timeout = 10
|
|
29
|
-
end
|
|
30
|
-
expect_any_instance_of(Net::HTTP).to receive(:read_timeout=).with(5)
|
|
31
|
-
expect_any_instance_of(Net::HTTP).to receive(:open_timeout=).with(10)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
include_context 'with url'
|
|
35
|
-
|
|
36
|
-
it 'creates requests with a default timeout' do
|
|
37
|
-
expect(result.success?).to be true
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context 'timeout' do
|
|
42
|
-
before do
|
|
43
|
-
stub_request(:get, 'https://www.example.org/').to_timeout
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
include_context 'with url'
|
|
47
|
-
|
|
48
|
-
around do |example|
|
|
49
|
-
VCR.turned_off { example.run }
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'times out' do
|
|
53
|
-
expect(result.success?).to be false
|
|
54
|
-
expect(result.error?).to be true
|
|
55
|
-
expect(result.to_s).to eq 'GET https://www.example.org : ERROR (Net::OpenTimeout)'
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'with metadata' do
|
|
59
|
-
let(:options) { { foo: :bar } }
|
|
60
|
-
|
|
61
|
-
it 'times out' do
|
|
62
|
-
expect(result.error?).to be true
|
|
63
|
-
expect(result.options).to eq(foo: :bar)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe LinkChecker::Net::HTTP::Result do
|
|
69
|
-
describe '#code' do
|
|
70
|
-
it 'returns -1 when the response raises' do
|
|
71
|
-
response = instance_double(Net::HTTPResponse)
|
|
72
|
-
allow(response).to receive(:code).and_raise(StandardError)
|
|
73
|
-
result = described_class.new(URI('https://www.example.org'), 'GET', nil, nil, response, {})
|
|
74
|
-
expect(result.code).to eq(-1)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::ResultError do
|
|
6
|
-
subject(:result) do
|
|
7
|
-
described_class.new('https://www.example.org', 'GET', 'https://www.example.org', StandardError.new('oops'))
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it 'is an error' do
|
|
11
|
-
expect(result.error?).to be true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'returns the error class name as code' do
|
|
15
|
-
expect(result.code).to eq 'StandardError'
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Result do
|
|
6
|
-
subject(:result) do
|
|
7
|
-
described_class.new('https://www.example.org', 'GET', 'https://www.example.org')
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it 'defaults to not successful' do
|
|
11
|
-
expect(result.success?).to be false
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'defaults to not a failure' do
|
|
15
|
-
expect(result.failure?).to be false
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'defaults to not an error' do
|
|
19
|
-
expect(result.error?).to be false
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'defaults to not a redirect' do
|
|
23
|
-
expect(result.redirect?).to be false
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'defaults redirect_to to nil' do
|
|
27
|
-
expect(result.redirect_to).to be_nil
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'defaults request_headers to an empty hash' do
|
|
31
|
-
expect(result.request_headers).to eq({})
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'defaults code to nil' do
|
|
35
|
-
expect(result.code).to be_nil
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'defaults error to nil' do
|
|
39
|
-
expect(result.error).to be_nil
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Task do
|
|
6
|
-
subject(:task) do
|
|
7
|
-
described_class.new(
|
|
8
|
-
LinkChecker::Net::HTTP::Checker.new,
|
|
9
|
-
'https://www.example.org',
|
|
10
|
-
'GET',
|
|
11
|
-
'https://www.example.org'
|
|
12
|
-
)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '#run!' do
|
|
16
|
-
it 'raises NotImplementedError' do
|
|
17
|
-
expect { task.run! }.to raise_error NotImplementedError
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Tasks do
|
|
6
|
-
describe '#_handle_result' do
|
|
7
|
-
# Reproduces issue #12: SystemStackError when logging causes repeated errors
|
|
8
|
-
# https://github.com/dblock/ruby-link-checker/issues/12
|
|
9
|
-
context 'when logger.info raises an error repeatedly' do
|
|
10
|
-
let(:checker) { LinkChecker::Net::HTTP::Checker.new(methods: ['GET']) }
|
|
11
|
-
let(:task_klass) { LinkChecker::Net::HTTP::Task }
|
|
12
|
-
let(:url) { 'https://www.example.org' }
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
stub_request(:get, url).to_return(status: 200, body: '', headers: {})
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'does not cause infinite recursion leading to SystemStackError' do
|
|
19
|
-
tasks = described_class.new(checker, task_klass, url, ['GET'])
|
|
20
|
-
|
|
21
|
-
# Stub logger to always raise an error on info, simulating the scenario
|
|
22
|
-
# from issue #12 where logging causes a stack overflow due to the
|
|
23
|
-
# rescue block in _handle_result recursively calling itself
|
|
24
|
-
allow(tasks).to receive(:logger).and_return(
|
|
25
|
-
instance_double(LinkChecker::Logger).tap do |logger|
|
|
26
|
-
allow(logger).to receive(:info).and_raise(StandardError, 'stack level too deep')
|
|
27
|
-
allow(logger).to receive(:error)
|
|
28
|
-
end
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
# Should not raise SystemStackError - the error should be handled gracefully
|
|
32
|
-
expect { tasks.execute! }.not_to raise_error
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe '#retries' do
|
|
38
|
-
let(:checker) { LinkChecker::Net::HTTP::Checker.new(methods: ['GET'], retries: 2) }
|
|
39
|
-
let(:task_klass) { LinkChecker::Net::HTTP::Task }
|
|
40
|
-
let(:url) { 'https://www.example.org' }
|
|
41
|
-
|
|
42
|
-
it 'delegates to the checker' do
|
|
43
|
-
tasks = described_class.new(checker, task_klass, url, ['GET'])
|
|
44
|
-
expect(tasks.send(:retries)).to eq 2
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe LinkChecker::Typhoeus::Hydra::Checker do
|
|
6
|
-
module TyphoeusTestLinkChecker
|
|
7
|
-
class Task < LinkChecker::Typhoeus::Hydra::Task; end
|
|
8
|
-
|
|
9
|
-
class LinkChecker < LinkChecker::Typhoeus::Hydra::Checker
|
|
10
|
-
def check(url, options = {})
|
|
11
|
-
super url, options
|
|
12
|
-
@hydra.run
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
before :all do
|
|
17
|
-
VCR.configure do |config|
|
|
18
|
-
config.hook_into :typhoeus
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe TyphoeusTestLinkChecker::LinkChecker do
|
|
23
|
-
it_behaves_like 'a link checker'
|
|
24
|
-
|
|
25
|
-
describe '.config' do
|
|
26
|
-
it 'returns the Config module' do
|
|
27
|
-
expect(LinkChecker::Typhoeus::Hydra.config).to eq LinkChecker::Typhoeus::Hydra::Config
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context 'with timeout options', vcr: { cassette_name: '200' } do
|
|
32
|
-
before do
|
|
33
|
-
LinkChecker::Typhoeus::Hydra.configure do |config|
|
|
34
|
-
config.timeout = 5
|
|
35
|
-
config.connecttimeout = 10
|
|
36
|
-
end
|
|
37
|
-
expect(Typhoeus::Request).to receive(:new).with(
|
|
38
|
-
URI(url),
|
|
39
|
-
hash_including(timeout: 5, connecttimeout: 10)
|
|
40
|
-
).and_call_original
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
include_context 'with url'
|
|
44
|
-
|
|
45
|
-
it 'creates requests with a default timeout' do
|
|
46
|
-
expect(result.success?).to be true
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context 'timeout', vcr: { cassette_name: '200' } do
|
|
51
|
-
before do
|
|
52
|
-
allow_any_instance_of(Typhoeus::Response).to receive(:timed_out?).and_return(true)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
include_context 'with url'
|
|
56
|
-
|
|
57
|
-
it 'times out' do
|
|
58
|
-
expect(result.success?).to be false
|
|
59
|
-
expect(result.error?).to be true
|
|
60
|
-
expect(result.to_s).to eq 'GET https://www.example.org : ERROR (Timeout::Error)'
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'with metadata' do
|
|
64
|
-
let(:options) { { foo: :bar } }
|
|
65
|
-
|
|
66
|
-
it 'times out' do
|
|
67
|
-
expect(result.error?).to be true
|
|
68
|
-
expect(result.options).to eq(foo: :bar)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe LinkChecker::Typhoeus::Hydra::Result do
|
|
75
|
-
describe '#code' do
|
|
76
|
-
it 'returns -1 when the response raises' do
|
|
77
|
-
request = instance_double(Typhoeus::Request)
|
|
78
|
-
response = instance_double(Typhoeus::Response)
|
|
79
|
-
allow(response).to receive(:code).and_raise(StandardError)
|
|
80
|
-
result = described_class.new(URI('https://www.example.org'), 'GET', nil, request, response, {})
|
|
81
|
-
expect(result.code).to eq(-1)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe '#run' do
|
|
87
|
-
it 'delegates to the hydra' do
|
|
88
|
-
checker = described_class.new
|
|
89
|
-
expect(checker.instance_variable_get(:@hydra)).to receive(:run)
|
|
90
|
-
checker.run
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
|
-
|
|
5
|
-
require 'rubygems'
|
|
6
|
-
|
|
7
|
-
require 'simplecov'
|
|
8
|
-
SimpleCov.start do
|
|
9
|
-
add_filter '/spec/'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
require 'rspec'
|
|
13
|
-
require 'ruby-link-checker'
|
|
14
|
-
|
|
15
|
-
RSpec.configure(&:raise_errors_for_deprecations!)
|
|
16
|
-
|
|
17
|
-
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
|
|
18
|
-
require file
|
|
19
|
-
end
|