ndd-url_checker 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -2
- data/Guardfile +1 -1
- data/README.md +63 -3
- data/VERSION +1 -1
- data/lib/ndd/url_checker/abstract_url_checker.rb +5 -14
- data/lib/ndd/url_checker/blocking_url_checker.rb +18 -37
- data/lib/ndd/url_checker/forked_url_checker.rb +25 -29
- data/lib/ndd/url_checker/parallel_url_checker.rb +12 -11
- data/lib/ndd/url_checker/reporting_url_checker.html.erb +97 -0
- data/lib/ndd/url_checker/reporting_url_checker.rb +83 -0
- data/lib/ndd/url_checker/status.rb +20 -20
- data/lib/ndd/url_checker/threaded_url_checker.rb +10 -8
- data/ndd-url_checker.gemspec +123 -0
- data/spec/ndd/url_checker/abstract_url_checker_spec.rb +0 -6
- data/spec/ndd/url_checker/reporting_url_checker/multiple_urls.html +111 -0
- data/spec/ndd/url_checker/reporting_url_checker/single_url.html +97 -0
- data/spec/ndd/url_checker/reporting_url_checker_spec.rb +70 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/multiple_url_checker_spec.rb +3 -11
- data/spec/support/single_url_checker_spec.rb +0 -36
- metadata +8 -2
@@ -4,7 +4,7 @@ module NDD
|
|
4
4
|
# The result of a URI test.
|
5
5
|
# @author David DIDIER
|
6
6
|
# @attr_reader code [String] the state
|
7
|
-
# @attr_reader error [String
|
7
|
+
# @attr_reader error [String, StandardError] the last error if any
|
8
8
|
# @attr_reader uris [Array<String>] the list of requested URI
|
9
9
|
class Status
|
10
10
|
|
@@ -12,46 +12,45 @@ module NDD
|
|
12
12
|
attr_reader :error
|
13
13
|
attr_reader :uris
|
14
14
|
|
15
|
-
#
|
16
|
-
# @param uri [String
|
15
|
+
# Creates a new instance in the :unknown state.
|
16
|
+
# @param uri [String, URI::HTTP] the requested URI.
|
17
17
|
def initialize(uri)
|
18
18
|
@uris = [uri.to_s]
|
19
19
|
@code = :unknown
|
20
20
|
end
|
21
21
|
|
22
|
-
#
|
23
|
-
# @return [String] the first requested URI.
|
22
|
+
# @return [String] the first requested URI.
|
24
23
|
def uri
|
25
24
|
uris.first
|
26
25
|
end
|
27
26
|
|
28
|
-
#
|
29
|
-
#
|
27
|
+
# Note that the :unknown code is neither valid nor invalid.
|
28
|
+
# @return [Boolean] true if valid, false otherwise.
|
30
29
|
def valid?
|
31
30
|
VALID_CODES.include? @code
|
32
31
|
end
|
33
32
|
|
34
|
-
#
|
35
|
-
#
|
33
|
+
# Note that the :unknown code is neither valid nor invalid.
|
34
|
+
# @return [Boolean] true if invalid, false otherwise.
|
36
35
|
def invalid?
|
37
36
|
INVALID_CODES.include? @code
|
38
37
|
end
|
39
38
|
|
40
|
-
#
|
39
|
+
# @return [Boolean] true if redirected, false otherwise.
|
41
40
|
def redirected?
|
42
41
|
@code == :redirected
|
43
42
|
end
|
44
43
|
|
45
44
|
|
46
45
|
# When the URI is valid without any redirect.
|
47
|
-
#
|
46
|
+
# @return [self]
|
48
47
|
def direct
|
49
48
|
update_code(:direct, %i(unknown))
|
50
49
|
end
|
51
50
|
|
52
|
-
#
|
51
|
+
# When a generic error is raised.
|
53
52
|
# @param error [StandardError|String] the generic error.
|
54
|
-
#
|
53
|
+
# @return [self]
|
55
54
|
def failed(error)
|
56
55
|
@error = error
|
57
56
|
update_code(:failed, %i(unknown redirected))
|
@@ -59,20 +58,20 @@ module NDD
|
|
59
58
|
|
60
59
|
# Adds a new URI to the redirected URI list.
|
61
60
|
# @param uri [String|URI::HTTP] the redirection URI.
|
62
|
-
#
|
61
|
+
# @return [self]
|
63
62
|
def redirected(uri)
|
64
63
|
@uris << uri.to_s
|
65
64
|
update_code(:redirected, %i(unknown redirected))
|
66
65
|
end
|
67
66
|
|
68
|
-
#
|
69
|
-
#
|
67
|
+
# When there are too many redirects.
|
68
|
+
# @return [self]
|
70
69
|
def too_many_redirects
|
71
70
|
update_code(:too_many_redirects, %i(unknown redirected))
|
72
71
|
end
|
73
72
|
|
74
|
-
#
|
75
|
-
#
|
73
|
+
# When the host cannot be resolved.
|
74
|
+
# @return [self]
|
76
75
|
def unknown_host
|
77
76
|
update_code(:unknown_host, %i(unknown redirected))
|
78
77
|
end
|
@@ -82,15 +81,16 @@ module NDD
|
|
82
81
|
end
|
83
82
|
|
84
83
|
|
84
|
+
# -------------------------------------------------------------------------------------------------- private -----
|
85
85
|
private
|
86
86
|
|
87
87
|
VALID_CODES = %i(direct redirected).freeze
|
88
88
|
INVALID_CODES = %i(failed too_many_redirects unknown_host).freeze
|
89
89
|
|
90
|
-
#
|
90
|
+
# Updates the code if the transition is valid.
|
91
91
|
# @param code [Symbol] the new code.
|
92
92
|
# @param valid_source_codes [Array<Symbol>] the codes from which the transition can happen.
|
93
|
-
#
|
93
|
+
# @return [NDD::UrlChecker::Status] self.
|
94
94
|
def update_code(code, valid_source_codes)
|
95
95
|
unless valid_source_codes.include?(@code)
|
96
96
|
raise "Changing the status code from :#{@code} to :#{code} is forbidden"
|
@@ -8,29 +8,31 @@ module NDD
|
|
8
8
|
|
9
9
|
# An URL checker using threads to parallelize processing. Does not work on MRI.
|
10
10
|
# @author David DIDIER
|
11
|
+
# @attr_reader delegate [#check] the delegate URL checker.
|
12
|
+
# @attr_reader parallelism [Fixnum] the number of threads.
|
11
13
|
class ThreadedUrlChecker < AbstractUrlChecker
|
12
14
|
|
13
15
|
attr_reader :delegate
|
16
|
+
attr_reader :parallelism
|
14
17
|
|
15
18
|
# Create a new instance.
|
16
|
-
# @param [AbstractUrlChecker]
|
17
|
-
# @param [Fixnum]
|
18
|
-
def initialize(delegate_checker
|
19
|
+
# @param delegate_checker [AbstractUrlChecker] defaults to {NDD::UrlChecker::BlockingUrlChecker}.
|
20
|
+
# @param parallelism [Fixnum] the number of threads.
|
21
|
+
def initialize(delegate_checker: nil, parallelism: 10)
|
19
22
|
@logger = Logging.logger[self]
|
20
23
|
@delegate = delegate_checker || BlockingUrlChecker.new
|
21
24
|
@parallelism = parallelism
|
22
25
|
end
|
23
26
|
|
27
|
+
# Checks that the given URLs are valid.
|
28
|
+
# @param urls [String, Array<String>] the URLs to check
|
29
|
+
# @return [NDD::UrlChecker::Status, Array<NDD::UrlChecker::Status>] a single status for a single URL, an array
|
30
|
+
# of status for multiple parameters
|
24
31
|
def check(*urls)
|
25
32
|
# delegate.check(*urls)
|
26
33
|
raise 'TODO'
|
27
34
|
end
|
28
35
|
|
29
|
-
def validate(*urls)
|
30
|
-
# delegate.validate(*urls)
|
31
|
-
raise 'TODO'
|
32
|
-
end
|
33
|
-
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: ndd-url_checker 0.2.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "ndd-url_checker"
|
9
|
+
s.version = "0.2.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["David DIDIER"]
|
14
|
+
s.date = "2014-12-15"
|
15
|
+
s.description = "Validate URLs"
|
16
|
+
s.email = "c_inconnu2@yahoo.fr"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
".ruby-gemset",
|
25
|
+
".ruby-version",
|
26
|
+
".travis.yml",
|
27
|
+
"CHANGELOG.md",
|
28
|
+
"Gemfile",
|
29
|
+
"Gemfile.lock",
|
30
|
+
"Guardfile",
|
31
|
+
"LICENSE.txt",
|
32
|
+
"README.md",
|
33
|
+
"Rakefile",
|
34
|
+
"VERSION",
|
35
|
+
"lib/ndd/url_checker.rb",
|
36
|
+
"lib/ndd/url_checker/abstract_url_checker.rb",
|
37
|
+
"lib/ndd/url_checker/blocking_url_checker.rb",
|
38
|
+
"lib/ndd/url_checker/forked_url_checker.rb",
|
39
|
+
"lib/ndd/url_checker/parallel_url_checker.rb",
|
40
|
+
"lib/ndd/url_checker/reporting_url_checker.html.erb",
|
41
|
+
"lib/ndd/url_checker/reporting_url_checker.rb",
|
42
|
+
"lib/ndd/url_checker/status.rb",
|
43
|
+
"lib/ndd/url_checker/threaded_url_checker.rb",
|
44
|
+
"ndd-url_checker.gemspec",
|
45
|
+
"spec/ndd/url_checker/abstract_url_checker_spec.rb",
|
46
|
+
"spec/ndd/url_checker/blocking_url_checker_spec.rb",
|
47
|
+
"spec/ndd/url_checker/forked_url_checker_spec.rb",
|
48
|
+
"spec/ndd/url_checker/parallel_url_checker_spec.rb",
|
49
|
+
"spec/ndd/url_checker/reporting_url_checker/multiple_urls.html",
|
50
|
+
"spec/ndd/url_checker/reporting_url_checker/single_url.html",
|
51
|
+
"spec/ndd/url_checker/reporting_url_checker_spec.rb",
|
52
|
+
"spec/ndd/url_checker/status_spec.rb",
|
53
|
+
"spec/ndd/url_checker/threaded_url_checker_spec.rb",
|
54
|
+
"spec/spec_helper.rb",
|
55
|
+
"spec/support/multiple_url_checker_spec.rb",
|
56
|
+
"spec/support/single_url_checker_spec.rb"
|
57
|
+
]
|
58
|
+
s.homepage = "http://github.com/ddidier/ndd-url_checker"
|
59
|
+
s.licenses = ["MIT"]
|
60
|
+
s.rubygems_version = "2.4.4"
|
61
|
+
s.summary = "Validate URLs"
|
62
|
+
|
63
|
+
if s.respond_to? :specification_version then
|
64
|
+
s.specification_version = 4
|
65
|
+
|
66
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
67
|
+
s.add_runtime_dependency(%q<cod>, ["~> 0.6"])
|
68
|
+
s.add_runtime_dependency(%q<logging>, ["~> 1.8"])
|
69
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.7"])
|
70
|
+
s.add_development_dependency(%q<guard>, ["~> 2.8"])
|
71
|
+
s.add_development_dependency(%q<guard-bundler>, ["~> 2.0"])
|
72
|
+
s.add_development_dependency(%q<guard-rspec>, ["~> 4.3"])
|
73
|
+
s.add_development_dependency(%q<guard-spork>, ["~> 2.0"])
|
74
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
75
|
+
s.add_development_dependency(%q<rdoc>, ["~> 4.1"])
|
76
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.1"])
|
77
|
+
s.add_development_dependency(%q<rspec-collection_matchers>, ["~> 1.1"])
|
78
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0.9"])
|
79
|
+
s.add_development_dependency(%q<spork>, ["~> 0.9"])
|
80
|
+
s.add_development_dependency(%q<webmock>, ["~> 1.20"])
|
81
|
+
s.add_development_dependency(%q<yard>, ["~> 0.8"])
|
82
|
+
s.add_development_dependency(%q<libnotify>, [">= 0"])
|
83
|
+
s.add_development_dependency(%q<rb-inotify>, [">= 0"])
|
84
|
+
else
|
85
|
+
s.add_dependency(%q<cod>, ["~> 0.6"])
|
86
|
+
s.add_dependency(%q<logging>, ["~> 1.8"])
|
87
|
+
s.add_dependency(%q<bundler>, ["~> 1.7"])
|
88
|
+
s.add_dependency(%q<guard>, ["~> 2.8"])
|
89
|
+
s.add_dependency(%q<guard-bundler>, ["~> 2.0"])
|
90
|
+
s.add_dependency(%q<guard-rspec>, ["~> 4.3"])
|
91
|
+
s.add_dependency(%q<guard-spork>, ["~> 2.0"])
|
92
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
93
|
+
s.add_dependency(%q<rdoc>, ["~> 4.1"])
|
94
|
+
s.add_dependency(%q<rspec>, ["~> 3.1"])
|
95
|
+
s.add_dependency(%q<rspec-collection_matchers>, ["~> 1.1"])
|
96
|
+
s.add_dependency(%q<simplecov>, ["~> 0.9"])
|
97
|
+
s.add_dependency(%q<spork>, ["~> 0.9"])
|
98
|
+
s.add_dependency(%q<webmock>, ["~> 1.20"])
|
99
|
+
s.add_dependency(%q<yard>, ["~> 0.8"])
|
100
|
+
s.add_dependency(%q<libnotify>, [">= 0"])
|
101
|
+
s.add_dependency(%q<rb-inotify>, [">= 0"])
|
102
|
+
end
|
103
|
+
else
|
104
|
+
s.add_dependency(%q<cod>, ["~> 0.6"])
|
105
|
+
s.add_dependency(%q<logging>, ["~> 1.8"])
|
106
|
+
s.add_dependency(%q<bundler>, ["~> 1.7"])
|
107
|
+
s.add_dependency(%q<guard>, ["~> 2.8"])
|
108
|
+
s.add_dependency(%q<guard-bundler>, ["~> 2.0"])
|
109
|
+
s.add_dependency(%q<guard-rspec>, ["~> 4.3"])
|
110
|
+
s.add_dependency(%q<guard-spork>, ["~> 2.0"])
|
111
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
112
|
+
s.add_dependency(%q<rdoc>, ["~> 4.1"])
|
113
|
+
s.add_dependency(%q<rspec>, ["~> 3.1"])
|
114
|
+
s.add_dependency(%q<rspec-collection_matchers>, ["~> 1.1"])
|
115
|
+
s.add_dependency(%q<simplecov>, ["~> 0.9"])
|
116
|
+
s.add_dependency(%q<spork>, ["~> 0.9"])
|
117
|
+
s.add_dependency(%q<webmock>, ["~> 1.20"])
|
118
|
+
s.add_dependency(%q<yard>, ["~> 0.8"])
|
119
|
+
s.add_dependency(%q<libnotify>, [">= 0"])
|
120
|
+
s.add_dependency(%q<rb-inotify>, [">= 0"])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
@@ -2,12 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe NDD::UrlChecker::AbstractUrlChecker do
|
4
4
|
|
5
|
-
context '#validate' do
|
6
|
-
it 'is not implemented' do
|
7
|
-
expect { subject.validate('http://www.valid.mock/') }.to raise_error /must be implemented/
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
5
|
context '#check' do
|
12
6
|
it 'is not implemented' do
|
13
7
|
expect { subject.check('http://www.valid.mock/') }.to raise_error /must be implemented/
|
@@ -0,0 +1,111 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
|
7
|
+
<style>
|
8
|
+
body {
|
9
|
+
padding: 1em;
|
10
|
+
}
|
11
|
+
</style>
|
12
|
+
|
13
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
14
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
|
15
|
+
<script language="JavaScript">
|
16
|
+
$(document).ready(function() {
|
17
|
+
$('input[type=radio][name=urlsFilter]').change(function() {
|
18
|
+
if (this.value == 'all') {
|
19
|
+
$('tr').show();
|
20
|
+
}
|
21
|
+
else if (this.value == 'invalid') {
|
22
|
+
$('tr').not('.danger').hide();
|
23
|
+
}
|
24
|
+
});
|
25
|
+
});
|
26
|
+
</script>
|
27
|
+
</head>
|
28
|
+
|
29
|
+
<body>
|
30
|
+
|
31
|
+
<h1>URL Checker Report</h1>
|
32
|
+
|
33
|
+
<table class="table table-condensed table-hover" style="width: auto">
|
34
|
+
<tbody>
|
35
|
+
<tr>
|
36
|
+
<td>User CPU time</td>
|
37
|
+
<td>XXX second(s)</td>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<td>System CPU time</td>
|
41
|
+
<td>XXX second(s)</td>
|
42
|
+
</tr>
|
43
|
+
<tr>
|
44
|
+
<td>Total time</td>
|
45
|
+
<td>XXX second(s)</td>
|
46
|
+
</tr>
|
47
|
+
<tr>
|
48
|
+
<td>Elapsed real time</td>
|
49
|
+
<td>XXX second(s)</td>
|
50
|
+
</tr>
|
51
|
+
<tr>
|
52
|
+
<td>Number of URLs</td>
|
53
|
+
<td>3</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>Average time for 1 URL</td>
|
57
|
+
<td>XXX second(s)</td>
|
58
|
+
</tr>
|
59
|
+
</tbody>
|
60
|
+
</table>
|
61
|
+
|
62
|
+
<div class="radio">
|
63
|
+
<label>
|
64
|
+
<input type="radio" name="urlsFilter" id="showAllUrls" value="all" checked="true" />
|
65
|
+
Show all URLs
|
66
|
+
</label>
|
67
|
+
</div>
|
68
|
+
<div class="radio">
|
69
|
+
<label>
|
70
|
+
<input type="radio" name="urlsFilter" id="showInvalidUrls" value="invalid" />
|
71
|
+
Show invalid URLs
|
72
|
+
</label>
|
73
|
+
</div>
|
74
|
+
|
75
|
+
<table class="table table-condensed table-hover" style="width: auto">
|
76
|
+
<thead>
|
77
|
+
<tr>
|
78
|
+
<th>#</th>
|
79
|
+
<th>URL</th>
|
80
|
+
<th>Result</th>
|
81
|
+
<th>Comment</th>
|
82
|
+
</tr>
|
83
|
+
</thead>
|
84
|
+
<tbody>
|
85
|
+
|
86
|
+
<tr class="">
|
87
|
+
<td>1</td>
|
88
|
+
<td><a href="http://www.google.com" target="_blank">http://www.google.com</a></td>
|
89
|
+
<td>NDD::UrlChecker::Status</td>
|
90
|
+
<td></td>
|
91
|
+
</tr>
|
92
|
+
|
93
|
+
<tr class="danger">
|
94
|
+
<td>2</td>
|
95
|
+
<td><a href="http://www.google.de" target="_blank">http://www.google.de</a></td>
|
96
|
+
<td>NDD::UrlChecker::Status</td>
|
97
|
+
<td>some error</td>
|
98
|
+
</tr>
|
99
|
+
|
100
|
+
<tr class="">
|
101
|
+
<td>3</td>
|
102
|
+
<td><a href="http://www.google.fr" target="_blank">http://www.google.fr</a></td>
|
103
|
+
<td>NDD::UrlChecker::Status</td>
|
104
|
+
<td></td>
|
105
|
+
</tr>
|
106
|
+
|
107
|
+
</tbody>
|
108
|
+
</table>
|
109
|
+
|
110
|
+
</body>
|
111
|
+
</html>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
|
7
|
+
<style>
|
8
|
+
body {
|
9
|
+
padding: 1em;
|
10
|
+
}
|
11
|
+
</style>
|
12
|
+
|
13
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
14
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
|
15
|
+
<script language="JavaScript">
|
16
|
+
$(document).ready(function() {
|
17
|
+
$('input[type=radio][name=urlsFilter]').change(function() {
|
18
|
+
if (this.value == 'all') {
|
19
|
+
$('tr').show();
|
20
|
+
}
|
21
|
+
else if (this.value == 'invalid') {
|
22
|
+
$('tr').not('.danger').hide();
|
23
|
+
}
|
24
|
+
});
|
25
|
+
});
|
26
|
+
</script>
|
27
|
+
</head>
|
28
|
+
|
29
|
+
<body>
|
30
|
+
|
31
|
+
<h1>URL Checker Report</h1>
|
32
|
+
|
33
|
+
<table class="table table-condensed table-hover" style="width: auto">
|
34
|
+
<tbody>
|
35
|
+
<tr>
|
36
|
+
<td>User CPU time</td>
|
37
|
+
<td>XXX second(s)</td>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<td>System CPU time</td>
|
41
|
+
<td>XXX second(s)</td>
|
42
|
+
</tr>
|
43
|
+
<tr>
|
44
|
+
<td>Total time</td>
|
45
|
+
<td>XXX second(s)</td>
|
46
|
+
</tr>
|
47
|
+
<tr>
|
48
|
+
<td>Elapsed real time</td>
|
49
|
+
<td>XXX second(s)</td>
|
50
|
+
</tr>
|
51
|
+
<tr>
|
52
|
+
<td>Number of URLs</td>
|
53
|
+
<td>1</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>Average time for 1 URL</td>
|
57
|
+
<td>XXX second(s)</td>
|
58
|
+
</tr>
|
59
|
+
</tbody>
|
60
|
+
</table>
|
61
|
+
|
62
|
+
<div class="radio">
|
63
|
+
<label>
|
64
|
+
<input type="radio" name="urlsFilter" id="showAllUrls" value="all" checked="true" />
|
65
|
+
Show all URLs
|
66
|
+
</label>
|
67
|
+
</div>
|
68
|
+
<div class="radio">
|
69
|
+
<label>
|
70
|
+
<input type="radio" name="urlsFilter" id="showInvalidUrls" value="invalid" />
|
71
|
+
Show invalid URLs
|
72
|
+
</label>
|
73
|
+
</div>
|
74
|
+
|
75
|
+
<table class="table table-condensed table-hover" style="width: auto">
|
76
|
+
<thead>
|
77
|
+
<tr>
|
78
|
+
<th>#</th>
|
79
|
+
<th>URL</th>
|
80
|
+
<th>Result</th>
|
81
|
+
<th>Comment</th>
|
82
|
+
</tr>
|
83
|
+
</thead>
|
84
|
+
<tbody>
|
85
|
+
|
86
|
+
<tr class="">
|
87
|
+
<td>1</td>
|
88
|
+
<td><a href="http://www.google.fr" target="_blank">http://www.google.fr</a></td>
|
89
|
+
<td>NDD::UrlChecker::Status</td>
|
90
|
+
<td></td>
|
91
|
+
</tr>
|
92
|
+
|
93
|
+
</tbody>
|
94
|
+
</table>
|
95
|
+
|
96
|
+
</body>
|
97
|
+
</html>
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
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
|
+
it 'creates an HTML report' 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
|
+
|
27
|
+
actual_report = actual_report(report_checker, 'single_url.html')
|
28
|
+
expected_report = expected_report('single_url.html')
|
29
|
+
expect(actual_report).to eq expected_report
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when checking multiple URLs' do
|
34
|
+
it 'creates an HTML report' do
|
35
|
+
expected_results = [
|
36
|
+
NDD::UrlChecker::Status.new('http://www.google.fr').direct,
|
37
|
+
NDD::UrlChecker::Status.new('http://www.google.com').direct,
|
38
|
+
NDD::UrlChecker::Status.new('http://www.google.de').failed('some error')
|
39
|
+
]
|
40
|
+
checker = double
|
41
|
+
expect(checker).to receive(:check).and_return(expected_results)
|
42
|
+
|
43
|
+
report_checker = NDD::UrlChecker::ReportingUrlChecker.new(checker)
|
44
|
+
report_checker.check(*expected_results.map { |status| status.uri })
|
45
|
+
|
46
|
+
actual_report = actual_report(report_checker, 'multiple_urls.html')
|
47
|
+
expected_report = expected_report('multiple_urls.html')
|
48
|
+
expect(actual_report).to eq expected_report
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# ------------------------------------------------------------------------------------------------------ private -----
|
55
|
+
private
|
56
|
+
|
57
|
+
def actual_report(report_checker, output_file_name)
|
58
|
+
# actual_file = '/tmp/multiple_urls.html'
|
59
|
+
actual_file = Tempfile.new(output_file_name)
|
60
|
+
actual_report = report_checker.report(:html, actual_file)
|
61
|
+
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>')
|
63
|
+
end
|
64
|
+
|
65
|
+
def expected_report(expected_file_name)
|
66
|
+
expected_path = File.expand_path(File.join(File.dirname(__FILE__), 'reporting_url_checker/' + expected_file_name))
|
67
|
+
expected_report = File.new(expected_path).read
|
68
|
+
expected_report.gsub(/^\s+/, '')
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,6 +27,7 @@ Spork.prefork do
|
|
27
27
|
require 'logging'
|
28
28
|
require 'rspec'
|
29
29
|
require 'rspec/collection_matchers'
|
30
|
+
require 'tempfile'
|
30
31
|
require 'webmock/rspec'
|
31
32
|
|
32
33
|
# ----- code coverage
|
@@ -79,5 +80,4 @@ Spork.each_run do
|
|
79
80
|
Dir["#{lib_path}/**/*.rb"].each { |file| require file }
|
80
81
|
Dir["#{spec_dir}/support/**/*.rb"].each { |file| require file }
|
81
82
|
|
82
|
-
require 'ndd/url_checker'
|
83
83
|
end
|
@@ -17,26 +17,18 @@ RSpec.shared_examples 'a multiple URL checker' do |skip_verify|
|
|
17
17
|
let!(:stub1) { stub_request(:get, 'http://www.valid.mock/').to_return(status: 200) }
|
18
18
|
let!(:stub2) { stub_request(:get, 'http://www.invalid.mock/').to_raise(SocketError) }
|
19
19
|
|
20
|
-
describe '#validate' do
|
21
|
-
it 'returns a map of the results indexed by the URI' do
|
22
|
-
results = subject.validate('http://www.valid.mock/', 'http://www.invalid.mock/')
|
23
|
-
expect(results).to have(2).items
|
24
|
-
expect(results['http://www.valid.mock/']).to be_truthy
|
25
|
-
expect(results['http://www.invalid.mock/']).to be_falsey
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
20
|
describe '#check' do
|
30
21
|
it 'returns a map of the results indexed by the URI' do
|
31
22
|
results = subject.check('http://www.valid.mock/', 'http://www.invalid.mock/')
|
32
23
|
expect(results).to have(2).items
|
24
|
+
results_hash = results.reduce({}) { |hash, result| hash[result.uri] = result; hash }
|
33
25
|
|
34
|
-
status1 =
|
26
|
+
status1 = results_hash['http://www.valid.mock/']
|
35
27
|
expect(status1.code).to eq :direct
|
36
28
|
expect(status1.uri).to eq 'http://www.valid.mock/'
|
37
29
|
expect(status1.error).to be_nil
|
38
30
|
|
39
|
-
status2 =
|
31
|
+
status2 = results_hash['http://www.invalid.mock/']
|
40
32
|
expect(status2.code).to eq :failed
|
41
33
|
expect(status2.uri).to eq 'http://www.invalid.mock/'
|
42
34
|
expect(status2.error).to be_a StandardError
|