ndd-url_checker 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
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,49 +0,0 @@
1
- {
2
- "benchmark": {
3
- "total_duration": 123.456,
4
- "average_duration": 123.456,
5
- "average_throughput": 123.456
6
- },
7
- "statistics": {
8
- "count": 5,
9
- "valid_count": 2,
10
- "direct_count": 1,
11
- "redirected_count": 1,
12
- "invalid_count": 3,
13
- "failed_count": 1,
14
- "too_many_redirects_count": 1,
15
- "unknown_host_count": 1
16
- },
17
- "results": [
18
- {
19
- "index": 1,
20
- "url": "http://www.google.com",
21
- "code": "redirected",
22
- "details": ""
23
- },
24
- {
25
- "index": 2,
26
- "url": "http://www.google.de",
27
- "code": "failed",
28
- "details": "some error"
29
- },
30
- {
31
- "index": 3,
32
- "url": "http://www.google.es",
33
- "code": "too_many_redirects",
34
- "details": ""
35
- },
36
- {
37
- "index": 4,
38
- "url": "http://www.google.fr",
39
- "code": "direct",
40
- "details": ""
41
- },
42
- {
43
- "index": 5,
44
- "url": "http://www.google.it",
45
- "code": "unknown_host",
46
- "details": ""
47
- }
48
- ]
49
- }
@@ -1,26 +0,0 @@
1
- count = 5
2
-
3
- - index = 1
4
- - uri = http://www.google.com
5
- - valid = true
6
- - code = redirected
7
-
8
- - index = 2
9
- - uri = http://www.google.de
10
- - valid = false
11
- - code = failed
12
-
13
- - index = 3
14
- - uri = http://www.google.es
15
- - valid = false
16
- - code = too_many_redirects
17
-
18
- - index = 4
19
- - uri = http://www.google.fr
20
- - valid = true
21
- - code = direct
22
-
23
- - index = 5
24
- - uri = http://www.google.it
25
- - valid = false
26
- - code = unknown_host
@@ -1,2 +0,0 @@
1
- Index,URL,Result,Code,Details
2
- 1,http://www.google.fr,valid,direct,
@@ -1,182 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
-
7
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
8
- <style type="text/css">
9
- .popover-title {
10
- font-weight: bold;
11
- }
12
-
13
- .popover-content em {
14
- font-style: normal;
15
- font-weight: bold;
16
- }
17
-
18
- .popover-content ol {
19
- margin-left: -20px;
20
- }
21
- </style>
22
-
23
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
24
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
25
- <script language="JavaScript">
26
- if (!window.ndd_url_checker) {
27
- window.ndd_url_checker = {};
28
- }
29
-
30
- ndd_url_checker.STATES = ['direct', 'redirected', 'failed', 'too-many-redirects', 'unknown-host'];
31
-
32
- ndd_url_checker.displayStates = function () {
33
- var displayStates = {};
34
- $.each(ndd_url_checker.STATES, function (_, state) {
35
- var checked = $('.display-' + state).is(':checked');
36
- displayStates[state] = checked;
37
- });
38
- return displayStates;
39
- }
40
-
41
- ndd_url_checker.filter = function () {
42
- var displayStates = ndd_url_checker.displayStates();
43
-
44
- $.each(displayStates, function (state, display) {
45
- $('.result-' + state).toggle(display);
46
- });
47
- }
48
-
49
- $(document).ready(function () {
50
- // show or hide results depending on their state
51
- $.each(ndd_url_checker.STATES, function (_, state) {
52
- $('.display-' + state).change(function () {
53
- ndd_url_checker.filter();
54
- });
55
- });
56
-
57
- // activate all tooltips
58
- $('[data-toggle="popover"]')
59
- .popover()
60
- .click(function (e) {
61
- e.preventDefault();
62
- });
63
- });
64
- </script>
65
- </head>
66
-
67
-
68
- <body>
69
-
70
- <div class="container">
71
-
72
- <div class="page-header">
73
- <h1>
74
- <span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>
75
- URL Checker Report
76
- </h1>
77
- </div>
78
-
79
-
80
- <div class="row">
81
- <div class="col-md-4">
82
- <dl class="page-info dl-horizontal">
83
- <dt>Number of URLs</dt>
84
- <dd>1</dd>
85
- <dt>Duration</dt>
86
- <dd>123.456 s</dd>
87
- <dt>Average duration</dt>
88
- <dd>123.456 s/URL</dd>
89
- <dt>Average throughput</dt>
90
- <dd>123.456 URL/s</dd>
91
- </dl>
92
- </div>
93
- <div class="col-md-4">
94
- <dl class="page-info dl-horizontal">
95
- <dt>Valid URLS</dt>
96
- <dd>1</dd>
97
- <dt>direct</dt>
98
- <dd>1</dd>
99
- <dt>redirected</dt>
100
- <dd>0</dd>
101
- </dl>
102
- </div>
103
- <div class="col-md-4">
104
- <dl class="page-info dl-horizontal">
105
- <dt>Invalid URLS</dt>
106
- <dd>0</dd>
107
- <dt>failed</dt>
108
- <dd>0</dd>
109
- <dt>too many redirects</dt>
110
- <dd>0</dd>
111
- <dt>unknown host</dt>
112
- <dd>0</dd>
113
- </dl>
114
- </div>
115
- </div>
116
- <hr />
117
-
118
-
119
- <div class="row page-controls hidden-print">
120
- <div class="col-md-6">
121
- <span>Valid URLs:</span>
122
-
123
- <div class="btn-group page-display" data-toggle="buttons">
124
- <label class="btn btn-default active">
125
- <input type="checkbox" autocomplete="off" class="display-direct" checked="true" />
126
- Direct (1)
127
- </label>
128
- <label class="btn btn-default active">
129
- <input type="checkbox" autocomplete="off" class="display-redirected" checked="true" />
130
- Redirected (0)
131
- </label>
132
- </div>
133
- </div>
134
- <div class="col-md-6">
135
- <span>Invalid URLs:</span>
136
-
137
- <div class="btn-group page-display" data-toggle="buttons">
138
- <label class="btn btn-default active">
139
- <input type="checkbox" autocomplete="off" class="display-failed" checked="true" />
140
- Failed (0)
141
- </label>
142
- <label class="btn btn-default active">
143
- <input type="checkbox" autocomplete="off" class="display-too-many-redirects" checked="true" />
144
- Too many redirects (0)
145
- </label>
146
- <label class="btn btn-default active">
147
- <input type="checkbox" autocomplete="off" class="display-unknown-host" checked="true" />
148
- Unknown host (0)
149
- </label>
150
- </div>
151
- </div>
152
- </div>
153
- <hr />
154
-
155
-
156
- <table id="results" class="table table-condensed table-hover">
157
- <thead>
158
- <tr>
159
- <th>#</th>
160
- <th>URL</th>
161
- <th>Code</th>
162
- <th>Details</th>
163
- </tr>
164
- </thead>
165
- <tbody>
166
-
167
- <tr class="result result-direct ">
168
- <td>1</td>
169
- <td><a href="http://www.google.fr" target="_blank">http://www.google.fr</a></td>
170
- <td>direct</td>
171
- <td></td>
172
- <td>
173
- </td>
174
- </tr>
175
-
176
- </tbody>
177
- </table>
178
-
179
- </div>
180
-
181
- </body>
182
- </html>
@@ -1,25 +0,0 @@
1
- {
2
- "benchmark": {
3
- "total_duration": 123.456,
4
- "average_duration": 123.456,
5
- "average_throughput": 123.456
6
- },
7
- "statistics": {
8
- "count": 1,
9
- "valid_count": 1,
10
- "direct_count": 1,
11
- "redirected_count": 0,
12
- "invalid_count": 0,
13
- "failed_count": 0,
14
- "too_many_redirects_count": 0,
15
- "unknown_host_count": 0
16
- },
17
- "results": [
18
- {
19
- "index": 1,
20
- "url": "http://www.google.fr",
21
- "code": "direct",
22
- "details": ""
23
- }
24
- ]
25
- }
@@ -1,6 +0,0 @@
1
- count = 1
2
-
3
- - index = 1
4
- - uri = http://www.google.fr
5
- - valid = true
6
- - code = direct
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe NDD::UrlChecker::ReportingUrlChecker do
4
-
5
- before(:all) do
6
- # Logging.logger.root.level = :debug
7
- end
8
-
9
- subject(:checker) { NDD::UrlChecker::ReportingUrlChecker.new(NDD::UrlChecker::BlockingUrlChecker.new) }
10
-
11
- it_behaves_like 'a single URL checker'
12
- it_behaves_like 'a multiple URL checker'
13
-
14
-
15
- # ------------------------------------------------------------------------------------------------------ #report -----
16
- describe '#report' do
17
-
18
- context 'when checking a single URL' do
19
- before(:each) do
20
- expected_result = NDD::UrlChecker::Status.new('http://www.google.fr').direct
21
- checker = double
22
- expect(checker).to receive(:check).and_return(expected_result)
23
-
24
- @report_checker = NDD::UrlChecker::ReportingUrlChecker.new(checker)
25
- @report_checker.check(expected_result.uri)
26
- end
27
-
28
- it 'creates an CSV report' do
29
- actual_report = actual_report_csv(@report_checker, :csv, 'single_url.csv')
30
- expected_report = expected_report('single_url.csv')
31
- expect(actual_report).to eq expected_report
32
- end
33
-
34
- it 'creates an HTML report' do
35
- actual_report = actual_report_html(@report_checker, :html, 'single_url.html')
36
- expected_report = expected_report('single_url.html')
37
- expect(actual_report).to eq expected_report
38
- end
39
-
40
- it 'creates an JSON report' do
41
- actual_report = actual_report_json(@report_checker, :json, 'single_url.json')
42
- expected_report = expected_report('single_url.json')
43
- expect(actual_report).to eq expected_report
44
- end
45
-
46
- it 'creates a custom report' do
47
- custom_template = File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker/custom.txt.erb'))
48
- actual_report = actual_report(@report_checker, custom_template, 'single_url.txt')
49
- expected_report = expected_report('single_url.txt')
50
- expect(actual_report).to eq expected_report
51
- end
52
- end
53
-
54
- context 'when checking multiple URLs' do
55
- before(:each) do
56
- expected_results = [
57
- NDD::UrlChecker::Status.new('http://www.google.fr').direct,
58
- NDD::UrlChecker::Status.new('http://www.google.com').redirected('http://www.google.fr'),
59
- NDD::UrlChecker::Status.new('http://www.google.de').failed(StandardError.new('some error')),
60
- NDD::UrlChecker::Status.new('http://www.google.es').redirected('http://www.google.fr').too_many_redirects,
61
- NDD::UrlChecker::Status.new('http://www.google.it').unknown_host
62
- ]
63
- checker = double
64
- expect(checker).to receive(:check).and_return(expected_results)
65
-
66
- @report_checker = NDD::UrlChecker::ReportingUrlChecker.new(checker)
67
- @report_checker.check(*expected_results.map { |status| status.uri })
68
- end
69
-
70
- it 'creates an CSV report' do
71
- actual_report = actual_report_csv(@report_checker, :csv, 'multiple_urls.csv')
72
- expected_report = expected_report('multiple_urls.csv')
73
- expect(actual_report).to eq expected_report
74
- end
75
-
76
- it 'creates an HTML report' do
77
- actual_report = actual_report_html(@report_checker, :html, 'multiple_urls.html')
78
- expected_report = expected_report('multiple_urls.html')
79
- expect(actual_report).to eq expected_report
80
- end
81
-
82
- it 'creates an JSON report' do
83
- actual_report = actual_report_json(@report_checker, :json, 'multiple_urls.json')
84
- expected_report = expected_report('multiple_urls.json')
85
- expect(actual_report).to eq expected_report
86
- end
87
-
88
- it 'creates a custom report' do
89
- custom_template = File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker/custom.txt.erb'))
90
- actual_report = actual_report(@report_checker, custom_template, 'multiple_urls.txt')
91
- expected_report = expected_report('multiple_urls.txt')
92
- expect(actual_report).to eq expected_report
93
- end
94
- end
95
- end
96
-
97
-
98
- # ------------------------------------------------------------------------------------------------------ private -----
99
- private
100
-
101
- def actual_report(report_checker, report_type, output_file_name)
102
- # actual_file = File.new('/tmp/report.html', 'w+')
103
- actual_file = Tempfile.new(output_file_name)
104
- actual_report = report_checker.report(report_type, actual_file)
105
- expect(actual_report).to eq actual_file.read
106
- actual_report.gsub(/^\s+/, '')
107
- end
108
-
109
- def actual_report_csv(report_checker, report_type, output_file_name)
110
- actual_report(report_checker, report_type, output_file_name)
111
- end
112
-
113
- def actual_report_html(report_checker, report_type, output_file_name)
114
- actual_report = actual_report(report_checker, report_type, output_file_name)
115
- actual_report
116
- .gsub(/<dd>[\d\.e-]+ s<\/dd>/, '<dd>123.456 s</dd>')
117
- .gsub(/<dd>[\d\.e-]+ URL\/s<\/dd>/, '<dd>123.456 URL/s</dd>')
118
- .gsub(/<dd>[\d\.e-]+ s\/URL<\/dd>/, '<dd>123.456 s/URL</dd>')
119
- end
120
-
121
- def actual_report_json(report_checker, report_type, output_file_name)
122
- actual_report = actual_report(report_checker, report_type, output_file_name)
123
- actual_report.gsub(/\d+\.\d+(e-?\d*)?/, '123.456')
124
- end
125
-
126
- def expected_report(expected_file_name)
127
- expected_path = File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker/' + expected_file_name))
128
- expected_report = File.new(expected_path).read
129
- expected_report.gsub(/^\s+/, '')
130
- end
131
- end
@@ -1,208 +0,0 @@
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