ruby-link-checker 0.5.1 → 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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/README.md +153 -19
  4. data/UPGRADING.md +46 -0
  5. data/lib/ruby-link-checker/async/http/checker.rb +19 -6
  6. data/lib/ruby-link-checker/async/http/result.rb +1 -1
  7. data/lib/ruby-link-checker/cache.rb +90 -21
  8. data/lib/ruby-link-checker/checker.rb +136 -13
  9. data/lib/ruby-link-checker/config.rb +79 -0
  10. data/lib/ruby-link-checker/net/http/checker.rb +3 -2
  11. data/lib/ruby-link-checker/net/http/result.rb +1 -1
  12. data/lib/ruby-link-checker/redirect.rb +11 -0
  13. data/lib/ruby-link-checker/result.rb +96 -1
  14. data/lib/ruby-link-checker/tasks.rb +24 -12
  15. data/lib/ruby-link-checker/typhoeus/hydra/checker.rb +59 -11
  16. data/lib/ruby-link-checker/typhoeus/hydra/result.rb +1 -1
  17. data/lib/ruby-link-checker/version.rb +1 -1
  18. data/lib/ruby-link-checker.rb +1 -0
  19. metadata +18 -51
  20. data/.github/workflows/coverage.yml +0 -24
  21. data/.github/workflows/danger-comment.yml +0 -17
  22. data/.github/workflows/danger.yml +0 -12
  23. data/.github/workflows/lint.yml +0 -20
  24. data/.github/workflows/release.yml +0 -14
  25. data/.github/workflows/test.yml +0 -25
  26. data/.gitignore +0 -6
  27. data/.rspec +0 -2
  28. data/.rubocop.yml +0 -26
  29. data/.rubocop_todo.yml +0 -332
  30. data/AGENTS.md +0 -23
  31. data/CONTRIBUTING.md +0 -129
  32. data/Dangerfile +0 -6
  33. data/Gemfile +0 -27
  34. data/RELEASING.md +0 -37
  35. data/Rakefile +0 -26
  36. data/benchmarks/check.rb +0 -38
  37. data/benchmarks/data/opensearch.org/links.txt +0 -4270
  38. data/benchmarks/data/opensearch.org/small.txt +0 -100
  39. data/ruby-link-checker.gemspec +0 -22
  40. data/spec/fixtures/200.yml +0 -65
  41. data/spec/fixtures/301_200.yml +0 -102
  42. data/spec/fixtures/301_301.yml +0 -114
  43. data/spec/fixtures/301_400_301_200.yml +0 -185
  44. data/spec/fixtures/301_403.yml +0 -78
  45. data/spec/fixtures/308_429.yml +0 -108
  46. data/spec/fixtures/404.yml +0 -57
  47. data/spec/fixtures/404_200.yml +0 -89
  48. data/spec/fixtures/404_404.yml +0 -81
  49. data/spec/fixtures/429_200.yml +0 -135
  50. data/spec/fixtures/429_429_200.yml +0 -201
  51. data/spec/ruby-link-checker/async/http/checker_spec.rb +0 -184
  52. data/spec/ruby-link-checker/callbacks_spec.rb +0 -76
  53. data/spec/ruby-link-checker/checker_spec.rb +0 -97
  54. data/spec/ruby-link-checker/config_spec.rb +0 -45
  55. data/spec/ruby-link-checker/errors/redirect_loop_error_spec.rb +0 -18
  56. data/spec/ruby-link-checker/net/http/checker_spec.rb +0 -93
  57. data/spec/ruby-link-checker/result_error_spec.rb +0 -34
  58. data/spec/ruby-link-checker/result_spec.rb +0 -41
  59. data/spec/ruby-link-checker/task_spec.rb +0 -20
  60. data/spec/ruby-link-checker/tasks_spec.rb +0 -91
  61. data/spec/ruby-link-checker/typhoeus/hydra/checker_spec.rb +0 -180
  62. data/spec/ruby-link-checker/version_spec.rb +0 -9
  63. data/spec/spec_helper.rb +0 -19
  64. data/spec/support/config.rb +0 -8
  65. data/spec/support/link_checker.rb +0 -609
  66. data/spec/support/vcr.rb +0 -13
  67. data/spec/support/with_result.rb +0 -15
  68. data/spec/support/with_url.rb +0 -14
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe LinkChecker::Tasks do
6
- describe 'retry delays' do
7
- let(:checker) { LinkChecker::Net::HTTP::Checker.new }
8
- let(:tasks) { described_class.new(checker, LinkChecker::Net::HTTP::Task, 'https://www.example.org', ['GET']) }
9
- let(:headers) { { 'Retry-After' => '60' } }
10
- let(:result) { instance_double(LinkChecker::Net::HTTP::Result, response_headers: headers) }
11
-
12
- before do
13
- allow(tasks).to receive(:result).and_return(result)
14
- end
15
-
16
- it 'parses delta-seconds' do
17
- expect(tasks.send(:_server_retry_delay)).to eq(60)
18
- end
19
-
20
- context 'with a past HTTP date' do
21
- let(:headers) { { 'Retry-After' => (Time.now - 60).httpdate } }
22
-
23
- it 'does not delay a retry' do
24
- expect(tasks.send(:_server_retry_delay)).to eq(0)
25
- end
26
- end
27
-
28
- context 'with an invalid negative delay' do
29
- let(:headers) { { 'Retry-After' => '-5' } }
30
-
31
- it 'does not delay a retry' do
32
- expect(tasks.send(:_server_retry_delay)).to eq(0)
33
- end
34
- end
35
-
36
- it 'caps configured delays' do
37
- checker.retry_after = 120
38
- checker.max_retry_delay = 10
39
- expect(tasks.send(:_retry_delay)).to eq(10)
40
- end
41
-
42
- it 'adds jitter without reducing the minimum delay' do
43
- checker.retry_after = 2
44
- checker.retry_jitter = 0.5
45
- allow(tasks).to receive(:rand).and_return(0.5)
46
- expect(tasks.send(:_retry_delay)).to eq(2.5)
47
- end
48
- end
49
-
50
- describe '#_handle_result' do
51
- # Reproduces issue #12: SystemStackError when logging causes repeated errors
52
- # https://github.com/dblock/ruby-link-checker/issues/12
53
- context 'when logger.info raises an error repeatedly' do
54
- let(:checker) { LinkChecker::Net::HTTP::Checker.new(methods: ['GET']) }
55
- let(:task_klass) { LinkChecker::Net::HTTP::Task }
56
- let(:url) { 'https://www.example.org' }
57
-
58
- before do
59
- stub_request(:get, url).to_return(status: 200, body: '', headers: {})
60
- end
61
-
62
- it 'does not cause infinite recursion leading to SystemStackError' do
63
- tasks = described_class.new(checker, task_klass, url, ['GET'])
64
-
65
- # Stub logger to always raise an error on info, simulating the scenario
66
- # from issue #12 where logging causes a stack overflow due to the
67
- # rescue block in _handle_result recursively calling itself
68
- allow(tasks).to receive(:logger).and_return(
69
- instance_double(LinkChecker::Logger).tap do |logger|
70
- allow(logger).to receive(:info).and_raise(StandardError, 'stack level too deep')
71
- allow(logger).to receive(:error)
72
- end
73
- )
74
-
75
- # Should not raise SystemStackError - the error should be handled gracefully
76
- expect { tasks.execute! }.not_to raise_error
77
- end
78
- end
79
- end
80
-
81
- describe '#retries' do
82
- let(:checker) { LinkChecker::Net::HTTP::Checker.new(methods: ['GET'], retries: 2) }
83
- let(:task_klass) { LinkChecker::Net::HTTP::Task }
84
- let(:url) { 'https://www.example.org' }
85
-
86
- it 'delegates to the checker' do
87
- tasks = described_class.new(checker, task_klass, url, ['GET'])
88
- expect(tasks.send(:retries)).to eq 2
89
- end
90
- end
91
- end
@@ -1,180 +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 :webmock
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
-
94
- describe 'delayed retries' do
95
- let(:checker) { described_class.new(methods: ['GET'], retries: 1, retry_after: 0.005) }
96
-
97
- around do |example|
98
- VCR.turned_off { example.run }
99
- end
100
-
101
- it 'processes unrelated requests before waiting for a retry' do
102
- completed = []
103
- stub_request(:get, 'https://www.example.org/retry').to_return({ status: 503 }, { status: 200 })
104
- stub_request(:get, 'https://www.example.org/other').to_return(status: 200)
105
- checker.on(:success) { |result| completed << result.uri.path }
106
- checker.check('https://www.example.org/retry')
107
- checker.check('https://www.example.org/other')
108
- checker.run
109
- expect(completed).to eq(['/other', '/retry'])
110
- end
111
- end
112
-
113
- describe 'transport failures' do
114
- let(:checker) { described_class.new(methods: ['GET']) }
115
-
116
- around do |example|
117
- VCR.turned_off do
118
- WebMock.disable!
119
- Typhoeus::Config.block_connection = true
120
- example.run
121
- ensure
122
- Typhoeus::Config.block_connection = false
123
- WebMock.enable!
124
- end
125
- end
126
-
127
- after do
128
- Typhoeus::Expectation.clear
129
- end
130
-
131
- it 'reports connection errors separately from HTTP failures' do
132
- response = Typhoeus::Response.new(code: 0, return_code: :couldnt_connect)
133
- Typhoeus.stub(nil).and_return(response)
134
- checker.check('https://www.example.org/')
135
- checker.run
136
- expect(checker.results[:failure]).to be_empty
137
- expect(checker.results[:error].first.error_type).to eq(:connection)
138
- end
139
- end
140
-
141
- describe 'in-flight deduplication' do
142
- let(:checker) { described_class.new(methods: ['GET'], deduplicate: true) }
143
- let(:url) { 'https://www.example.org/' }
144
-
145
- around do |example|
146
- VCR.turned_off { example.run }
147
- end
148
-
149
- it 'fans out events to duplicates queued before completion' do
150
- metadata = []
151
- stub_request(:any, url).to_return(status: 200)
152
- checker.on(:result) { |result| metadata << result.options }
153
- checker.check(url, location: 'one.html')
154
- checker.check(url, location: 'two.html')
155
- checker.run
156
- expect(a_request(:any, url)).to have_been_made.once
157
- expect(metadata).to eq([{ location: 'one.html' }, { location: 'two.html' }])
158
- end
159
-
160
- it 'replays events when a subscriber joins during a result callback' do
161
- stub_request(:any, url).to_return(status: 200)
162
- checker.on(:result) { |result| checker.check(url, location: 'two.html') if result.options[:location] == 'one.html' }
163
- checker.check(url, location: 'one.html')
164
- checker.run
165
- expect(checker.results[:success].map(&:options)).to eq([{ location: 'one.html' }, { location: 'two.html' }])
166
- expect(a_request(:any, url)).to have_been_made.once
167
- end
168
-
169
- it 'does not memoize a response if settings changed while queued' do
170
- stub_request(:any, url).to_return(status: 200)
171
- checker.check(url)
172
- checker.headers = { 'Accept' => 'text/html' }
173
- checker.run
174
- checker.headers = {}
175
- checker.check(url)
176
- checker.run
177
- expect(a_request(:any, url)).to have_been_made.twice
178
- end
179
- end
180
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe LinkChecker do
6
- it 'has a version' do
7
- expect(LinkChecker::VERSION).not_to be_nil
8
- end
9
- 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
@@ -1,8 +0,0 @@
1
- RSpec.configure do |config|
2
- config.before do
3
- LinkChecker::Logger.default.level = Logger::DEBUG
4
- end
5
- config.after do
6
- LinkChecker::Config.reset
7
- end
8
- end