ndd-url_checker 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99d36713ad66fe4e91a94f8244232de75f4c9e2c
4
- data.tar.gz: 49b3313cc7ef54b102f1af8a2e921f9b96e5c70e
3
+ metadata.gz: 0ddb514dd4940f3ca4e1c12b26d11569a5d14196
4
+ data.tar.gz: def79c9bdbfaa493381bcc6bce5e147363afba86
5
5
  SHA512:
6
- metadata.gz: eb756c557e6c76cb1f5ba947b383e3b3a5baec440f7b4ae1763251744fb925050a5724588d779ea51f1901948abf2777c77bd5f86c57734117a533794144a7b6
7
- data.tar.gz: 3d1aa11d6dec0ea8159bb643b6cebe52f33d84b979e0f2bd858356085a616e5c170af888e72cb8f5872a0617421c0e34541b5ace207e12eaf7ff537a6d3e1727
6
+ metadata.gz: 46cc5e1d3a0442608626e1d86d7e77730b8a5f012781a7711fd7de39f88999e7d776137b9493dcc2117f28db7636b9f439a7c773fcc383c6b5f50e40bdef6e10
7
+ data.tar.gz: de7f6677ed2b53345150cbb1eb71cc8ee0608957bb28b31f273e43af58dd5b50a68b8794cfab2a48229bcec4f593f4ad297d82d740d50705d034b3337e5bdaa0
data/CHANGELOG.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # NDD URL Checker changelog
2
2
 
3
+ ## Version 0.2.1
4
+
5
+ - Replaced status class by status code in reports
6
+ - Added CSV and JSON reports
7
+
3
8
  ## Version 0.2.0
4
9
 
5
10
  - Switched to named parameters
6
11
  - Fixed documentation
7
- - Removed the `UrlChecker#validate` method.
8
- - Changed the type of the return value of `UrlChecker#check`.
12
+ - Removed the `UrlChecker#validate` method
13
+ - Changed the type of the return value of `UrlChecker#check`
14
+ - Added `ReportingUrlChecker`
9
15
 
10
16
  ## Version 0.1.0
11
17
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -0,0 +1,4 @@
1
+ Index,URL,Result,Code,Comment
2
+ <% results.each_with_index do |status, index| %>
3
+ <%= index+1 %>,<%= status.uri %>,<%= status.valid? ? 'valid' : 'invalid' %>,<%= status.code %>,<% if status.invalid? %><%= status.error %><% end %>
4
+ <% end %>
@@ -77,7 +77,7 @@
77
77
  <tr>
78
78
  <th>#</th>
79
79
  <th>URL</th>
80
- <th>Result</th>
80
+ <th>Code</th>
81
81
  <th>Comment</th>
82
82
  </tr>
83
83
  </thead>
@@ -86,7 +86,7 @@
86
86
  <tr class="<%= status.invalid? ? 'danger' : '' %>">
87
87
  <td><%= index+1 %></td>
88
88
  <td><a href="<%= status.uri %>" target="_blank"><%= status.uri %></a></td>
89
- <td><%= status.class %></td>
89
+ <td><%= status.code %></td>
90
90
  <td><% if status.invalid? %><%= status.error %><% end %></td>
91
91
  </tr>
92
92
  <% end %>
@@ -0,0 +1,20 @@
1
+ {
2
+ "benchmark": {
3
+ "utime": "<%= benchmark.utime %>",
4
+ "stime": "<%= benchmark.stime %>",
5
+ "total": "<%= benchmark.total %>",
6
+ "real": "<%= benchmark.real %>",
7
+ "size": "<%= results.size %>",
8
+ "throughput": "<%= benchmark.real/results.size %>"
9
+ },
10
+ "results": [
11
+ <% results.each_with_index do |status, index| %>
12
+ {
13
+ "index": <%= index+1 %>,
14
+ "url": "<%= status.uri %>",
15
+ "code": "<%= status.code %>",
16
+ "comment": "<% if status.invalid? %><%= status.error %><% end %>"
17
+ }<% if index < results.size - 1 %>,<% end %>
18
+ <% end %>
19
+ ]
20
+ }
@@ -67,13 +67,11 @@ module NDD
67
67
  def template_path(symbol_or_path)
68
68
  case symbol_or_path
69
69
  when :csv then
70
- # File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker.csv.erb'))
71
- raise 'TODO'
70
+ File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker.csv.erb'))
72
71
  when :html then
73
72
  File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker.html.erb'))
74
73
  when :json then
75
- # File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker.json.erb'))
76
- raise 'TODO'
74
+ File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker.json.erb'))
77
75
  else
78
76
  symbol_or_path
79
77
  end
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: ndd-url_checker 0.2.0 ruby lib
5
+ # stub: ndd-url_checker 0.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "ndd-url_checker"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -37,7 +37,9 @@ Gem::Specification.new do |s|
37
37
  "lib/ndd/url_checker/blocking_url_checker.rb",
38
38
  "lib/ndd/url_checker/forked_url_checker.rb",
39
39
  "lib/ndd/url_checker/parallel_url_checker.rb",
40
+ "lib/ndd/url_checker/reporting_url_checker.csv.erb",
40
41
  "lib/ndd/url_checker/reporting_url_checker.html.erb",
42
+ "lib/ndd/url_checker/reporting_url_checker.json.erb",
41
43
  "lib/ndd/url_checker/reporting_url_checker.rb",
42
44
  "lib/ndd/url_checker/status.rb",
43
45
  "lib/ndd/url_checker/threaded_url_checker.rb",
@@ -46,8 +48,15 @@ Gem::Specification.new do |s|
46
48
  "spec/ndd/url_checker/blocking_url_checker_spec.rb",
47
49
  "spec/ndd/url_checker/forked_url_checker_spec.rb",
48
50
  "spec/ndd/url_checker/parallel_url_checker_spec.rb",
51
+ "spec/ndd/url_checker/reporting_url_checker/custom.txt.erb",
52
+ "spec/ndd/url_checker/reporting_url_checker/multiple_urls.csv",
49
53
  "spec/ndd/url_checker/reporting_url_checker/multiple_urls.html",
54
+ "spec/ndd/url_checker/reporting_url_checker/multiple_urls.json",
55
+ "spec/ndd/url_checker/reporting_url_checker/multiple_urls.txt",
56
+ "spec/ndd/url_checker/reporting_url_checker/single_url.csv",
50
57
  "spec/ndd/url_checker/reporting_url_checker/single_url.html",
58
+ "spec/ndd/url_checker/reporting_url_checker/single_url.json",
59
+ "spec/ndd/url_checker/reporting_url_checker/single_url.txt",
51
60
  "spec/ndd/url_checker/reporting_url_checker_spec.rb",
52
61
  "spec/ndd/url_checker/status_spec.rb",
53
62
  "spec/ndd/url_checker/threaded_url_checker_spec.rb",
@@ -0,0 +1,8 @@
1
+ count = <%= results.size %>
2
+
3
+ <% results.each_with_index do |status, index| %>
4
+ - index = <%= index+1 %>
5
+ - uri = <%= status.uri %>
6
+ - valid = <%= status.valid? %>
7
+ - code = <%= status.code %>
8
+ <% end %>
@@ -0,0 +1,4 @@
1
+ Index,URL,Result,Code,Comment
2
+ 1,http://www.google.com,valid,direct,
3
+ 2,http://www.google.de,invalid,failed,some error
4
+ 3,http://www.google.fr,valid,direct,
@@ -77,7 +77,7 @@
77
77
  <tr>
78
78
  <th>#</th>
79
79
  <th>URL</th>
80
- <th>Result</th>
80
+ <th>Code</th>
81
81
  <th>Comment</th>
82
82
  </tr>
83
83
  </thead>
@@ -86,21 +86,21 @@
86
86
  <tr class="">
87
87
  <td>1</td>
88
88
  <td><a href="http://www.google.com" target="_blank">http://www.google.com</a></td>
89
- <td>NDD::UrlChecker::Status</td>
89
+ <td>direct</td>
90
90
  <td></td>
91
91
  </tr>
92
92
 
93
93
  <tr class="danger">
94
94
  <td>2</td>
95
95
  <td><a href="http://www.google.de" target="_blank">http://www.google.de</a></td>
96
- <td>NDD::UrlChecker::Status</td>
96
+ <td>failed</td>
97
97
  <td>some error</td>
98
98
  </tr>
99
99
 
100
100
  <tr class="">
101
101
  <td>3</td>
102
102
  <td><a href="http://www.google.fr" target="_blank">http://www.google.fr</a></td>
103
- <td>NDD::UrlChecker::Status</td>
103
+ <td>direct</td>
104
104
  <td></td>
105
105
  </tr>
106
106
 
@@ -0,0 +1,30 @@
1
+ {
2
+ "benchmark": {
3
+ "utime": "XXX",
4
+ "stime": "XXX",
5
+ "total": "XXX",
6
+ "real": "XXX",
7
+ "size": "3",
8
+ "throughput": "XXX"
9
+ },
10
+ "results": [
11
+ {
12
+ "index": 1,
13
+ "url": "http://www.google.com",
14
+ "code": "direct",
15
+ "comment": ""
16
+ },
17
+ {
18
+ "index": 2,
19
+ "url": "http://www.google.de",
20
+ "code": "failed",
21
+ "comment": "some error"
22
+ },
23
+ {
24
+ "index": 3,
25
+ "url": "http://www.google.fr",
26
+ "code": "direct",
27
+ "comment": ""
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1,16 @@
1
+ count = 3
2
+
3
+ - index = 1
4
+ - uri = http://www.google.com
5
+ - valid = true
6
+ - code = direct
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.fr
15
+ - valid = true
16
+ - code = direct
@@ -0,0 +1,2 @@
1
+ Index,URL,Result,Code,Comment
2
+ 1,http://www.google.fr,valid,direct,
@@ -77,7 +77,7 @@
77
77
  <tr>
78
78
  <th>#</th>
79
79
  <th>URL</th>
80
- <th>Result</th>
80
+ <th>Code</th>
81
81
  <th>Comment</th>
82
82
  </tr>
83
83
  </thead>
@@ -86,7 +86,7 @@
86
86
  <tr class="">
87
87
  <td>1</td>
88
88
  <td><a href="http://www.google.fr" target="_blank">http://www.google.fr</a></td>
89
- <td>NDD::UrlChecker::Status</td>
89
+ <td>direct</td>
90
90
  <td></td>
91
91
  </tr>
92
92
 
@@ -0,0 +1,18 @@
1
+ {
2
+ "benchmark": {
3
+ "utime": "XXX",
4
+ "stime": "XXX",
5
+ "total": "XXX",
6
+ "real": "XXX",
7
+ "size": "1",
8
+ "throughput": "XXX"
9
+ },
10
+ "results": [
11
+ {
12
+ "index": 1,
13
+ "url": "http://www.google.fr",
14
+ "code": "direct",
15
+ "comment": ""
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,6 @@
1
+ count = 1
2
+
3
+ - index = 1
4
+ - uri = http://www.google.fr
5
+ - valid = true
6
+ - code = direct
@@ -16,22 +16,43 @@ describe NDD::UrlChecker::ReportingUrlChecker do
16
16
  describe '#report' do
17
17
 
18
18
  context 'when checking a single URL' do
19
- it 'creates an HTML report' do
19
+ before(:each) do
20
20
  expected_result = NDD::UrlChecker::Status.new('http://www.google.fr').direct
21
21
  checker = double
22
22
  expect(checker).to receive(:check).and_return(expected_result)
23
23
 
24
- report_checker = NDD::UrlChecker::ReportingUrlChecker.new(checker)
25
- report_checker.check(expected_result.uri)
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(@report_checker, :csv, 'single_url.csv')
30
+ expected_report = expected_report('single_url.csv')
31
+ expect(actual_report).to eq expected_report
32
+ end
26
33
 
27
- actual_report = actual_report(report_checker, 'single_url.html')
34
+ it 'creates an HTML report' do
35
+ actual_report = actual_report(@report_checker, :html, 'single_url.html')
28
36
  expected_report = expected_report('single_url.html')
29
37
  expect(actual_report).to eq expected_report
30
38
  end
39
+
40
+ it 'creates an JSON report' do
41
+ actual_report = actual_report(@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
31
52
  end
32
53
 
33
54
  context 'when checking multiple URLs' do
34
- it 'creates an HTML report' do
55
+ before(:each) do
35
56
  expected_results = [
36
57
  NDD::UrlChecker::Status.new('http://www.google.fr').direct,
37
58
  NDD::UrlChecker::Status.new('http://www.google.com').direct,
@@ -40,13 +61,34 @@ describe NDD::UrlChecker::ReportingUrlChecker do
40
61
  checker = double
41
62
  expect(checker).to receive(:check).and_return(expected_results)
42
63
 
43
- report_checker = NDD::UrlChecker::ReportingUrlChecker.new(checker)
44
- report_checker.check(*expected_results.map { |status| status.uri })
64
+ @report_checker = NDD::UrlChecker::ReportingUrlChecker.new(checker)
65
+ @report_checker.check(*expected_results.map { |status| status.uri })
66
+ end
67
+
68
+ it 'creates an CSV report' do
69
+ actual_report = actual_report(@report_checker, :csv, 'multiple_urls.csv')
70
+ expected_report = expected_report('multiple_urls.csv')
71
+ expect(actual_report).to eq expected_report
72
+ end
45
73
 
46
- actual_report = actual_report(report_checker, 'multiple_urls.html')
74
+ it 'creates an HTML report' do
75
+ actual_report = actual_report(@report_checker, :html, 'multiple_urls.html')
47
76
  expected_report = expected_report('multiple_urls.html')
48
77
  expect(actual_report).to eq expected_report
49
78
  end
79
+
80
+ it 'creates an JSON report' do
81
+ actual_report = actual_report(@report_checker, :json, 'multiple_urls.json')
82
+ expected_report = expected_report('multiple_urls.json')
83
+ expect(actual_report).to eq expected_report
84
+ end
85
+
86
+ it 'creates a custom report' do
87
+ custom_template = File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker/custom.txt.erb'))
88
+ actual_report = actual_report(@report_checker, custom_template, 'multiple_urls.txt')
89
+ expected_report = expected_report('multiple_urls.txt')
90
+ expect(actual_report).to eq expected_report
91
+ end
50
92
  end
51
93
  end
52
94
 
@@ -54,12 +96,14 @@ describe NDD::UrlChecker::ReportingUrlChecker do
54
96
  # ------------------------------------------------------------------------------------------------------ private -----
55
97
  private
56
98
 
57
- def actual_report(report_checker, output_file_name)
99
+ def actual_report(report_checker, report_type, output_file_name)
58
100
  # actual_file = '/tmp/multiple_urls.html'
59
101
  actual_file = Tempfile.new(output_file_name)
60
- actual_report = report_checker.report(:html, actual_file)
102
+ actual_report = report_checker.report(report_type, actual_file)
61
103
  expect(actual_report).to eq actual_file.read
62
- actual_report.gsub(/^\s+/, '').gsub(/<td>[\d\.e-]+ second\(s\)<\/td>/, '<td>XXX second(s)</td>')
104
+ actual_report.gsub(/^\s+/, '')
105
+ .gsub(/<td>[\d\.e-]+ second\(s\)<\/td>/, '<td>XXX second(s)</td>') # HTML
106
+ .gsub(/"\d+\.\d+"/, '"XXX"').gsub(/"\d+\.\d+e-\d+"/, '"XXX"') # JSON
63
107
  end
64
108
 
65
109
  def expected_report(expected_file_name)
@@ -66,16 +66,21 @@ RSpec.shared_examples 'a single URL checker' do
66
66
  let!(:stub1) { stub_redirect('http://www.redirect1.mock/', 'http://www.redirect2.mock/') }
67
67
  let!(:stub2) { stub_redirect('http://www.redirect2.mock/', 'http://www.redirect3.mock/') }
68
68
  let!(:stub3) { stub_redirect('http://www.redirect3.mock/', 'http://www.redirect4.mock/') }
69
- let!(:stub4) { stub_redirect('http://www.redirect4.mock/', 'http://www.redirect5.mock/') }
70
- let!(:stub5) { stub_redirect('http://www.redirect5.mock/', 'http://www.redirect6.mock/') }
69
+ let!(:stub4) { stub_redirect('http://www.redirect4.mock/', 'relative') }
70
+ let!(:stub5) { stub_redirect('http://www.redirect4.mock/relative', 'http://www.redirect5.mock/') }
71
71
 
72
72
  describe '#check' do
73
73
  it 'returns UrlChecker::Direct' do
74
74
  result = subject.check('http://www.redirect1.mock/')
75
75
  expect(result).to be_kind_of NDD::UrlChecker::Status
76
- # expect(result).to be_kind_of UrlChecker::TooManyRedirect
77
76
  expect(result.uri).to eq 'http://www.redirect1.mock/'
78
- expect(result.uris).to eq (1..6).to_a.map { |i| "http://www.redirect#{i}.mock/" }
77
+ expect(result.uris).to eq %w(http://www.redirect1.mock/
78
+ http://www.redirect2.mock/
79
+ http://www.redirect3.mock/
80
+ http://www.redirect4.mock/
81
+ http://www.redirect4.mock/relative
82
+ http://www.redirect5.mock/
83
+ )
79
84
  end
80
85
  end
81
86
 
@@ -133,7 +138,30 @@ RSpec.shared_examples 'a single URL checker' do
133
138
  end
134
139
  end
135
140
 
136
- # -------------------------------------------------------------------------------------------------------- error -----
141
+ # ----------------------------------------------------------------------------------------------- expected error -----
142
+ context 'when there is an unexpected error' do
143
+ let!(:stub) { stub_request(:get, 'http://www.error.mock/').to_return(status: 400) }
144
+
145
+ describe '#check' do
146
+ let (:status) { subject.check('http://www.error.mock/') }
147
+
148
+ it 'returns a status with a :failed code' do
149
+ expect(status.code).to eq :failed
150
+ end
151
+ it 'returns a status with the requested URI' do
152
+ expect(status.uri).to eq 'http://www.error.mock/'
153
+ end
154
+ it 'returns a status with the raised error' do
155
+ expect(status.error).to be_a Net::HTTPBadRequest
156
+ end
157
+ end
158
+
159
+ after(:each) do
160
+ expect(stub).to have_been_requested
161
+ end
162
+ end
163
+
164
+ # --------------------------------------------------------------------------------------------- unexpected error -----
137
165
  context 'when there is an unexpected error' do
138
166
  let!(:stub) { stub_request(:get, 'http://www.error.mock/').to_raise('Some error') }
139
167
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndd-url_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David DIDIER
@@ -274,7 +274,9 @@ files:
274
274
  - lib/ndd/url_checker/blocking_url_checker.rb
275
275
  - lib/ndd/url_checker/forked_url_checker.rb
276
276
  - lib/ndd/url_checker/parallel_url_checker.rb
277
+ - lib/ndd/url_checker/reporting_url_checker.csv.erb
277
278
  - lib/ndd/url_checker/reporting_url_checker.html.erb
279
+ - lib/ndd/url_checker/reporting_url_checker.json.erb
278
280
  - lib/ndd/url_checker/reporting_url_checker.rb
279
281
  - lib/ndd/url_checker/status.rb
280
282
  - lib/ndd/url_checker/threaded_url_checker.rb
@@ -283,8 +285,15 @@ files:
283
285
  - spec/ndd/url_checker/blocking_url_checker_spec.rb
284
286
  - spec/ndd/url_checker/forked_url_checker_spec.rb
285
287
  - spec/ndd/url_checker/parallel_url_checker_spec.rb
288
+ - spec/ndd/url_checker/reporting_url_checker/custom.txt.erb
289
+ - spec/ndd/url_checker/reporting_url_checker/multiple_urls.csv
286
290
  - spec/ndd/url_checker/reporting_url_checker/multiple_urls.html
291
+ - spec/ndd/url_checker/reporting_url_checker/multiple_urls.json
292
+ - spec/ndd/url_checker/reporting_url_checker/multiple_urls.txt
293
+ - spec/ndd/url_checker/reporting_url_checker/single_url.csv
287
294
  - spec/ndd/url_checker/reporting_url_checker/single_url.html
295
+ - spec/ndd/url_checker/reporting_url_checker/single_url.json
296
+ - spec/ndd/url_checker/reporting_url_checker/single_url.txt
288
297
  - spec/ndd/url_checker/reporting_url_checker_spec.rb
289
298
  - spec/ndd/url_checker/status_spec.rb
290
299
  - spec/ndd/url_checker/threaded_url_checker_spec.rb