utterson 0.2.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -1
- data/bin/utterson +2 -2
- data/lib/utterson/base.rb +4 -1
- data/lib/utterson/html_check.rb +13 -16
- data/lib/utterson/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/utterson/base_spec.rb +8 -7
- data/spec/utterson/html_check_spec.rb +20 -22
- metadata +56 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f068f678f7ad3eace6ba4083e1fab800e571165483fd366b80807620776063ed
|
4
|
+
data.tar.gz: d20d1495a36de95ae1212e11b18f06b926da37351ef72cf06fa6ccabb7ebf20f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424f2cdbdfa9f56bbb92b64baff326b3722ca1ec8d6c97db0f176c70ad5066918696595364544f6cf283a616f38eabdb2d4a69d68beb5235eced8ed703727234
|
7
|
+
data.tar.gz: a5ee5b1682da10e1953f5de0addc9231179d3d00fc4fd5f9877b0352d2cd1615fcf91d73b87afa74081d47f4ee76e0a9866a66450c618de990f15603ad471ba1
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
Simple utility to traverse directory of html files and check links in them.
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/utterson.png)](http://badge.fury.io/rb/utterson)
|
4
|
-
[![
|
4
|
+
[![Tests](https://github.com/iiska/utterson/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/iiska/utterson/actions/workflows/ci.yml)
|
5
|
+
|
5
6
|
|
6
7
|
## Getting started
|
7
8
|
|
data/bin/utterson
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'optimist'
|
6
6
|
require 'utterson'
|
7
7
|
|
8
|
-
opts =
|
8
|
+
opts = Optimist::options do
|
9
9
|
opt :root, "Root directory for the site if it differs from target dir", type: :string
|
10
10
|
end
|
11
11
|
|
data/lib/utterson/base.rb
CHANGED
@@ -3,6 +3,8 @@ require 'ruby-progressbar'
|
|
3
3
|
require 'utterson/html_check'
|
4
4
|
|
5
5
|
module Utterson
|
6
|
+
# Base implements initialization of the checking process and handles
|
7
|
+
# outputting final results.
|
6
8
|
class Base
|
7
9
|
attr_reader :errors
|
8
10
|
|
@@ -45,7 +47,8 @@ module Utterson
|
|
45
47
|
if count == 0
|
46
48
|
puts "#{@stats[:files]} files with #{@stats[:urls]} urls checked."
|
47
49
|
else
|
48
|
-
puts "#{@stats[:files]} files with #{@stats[:urls]} urls checked
|
50
|
+
puts "Q{#{@stats[:files]} files with #{@stats[:urls]} urls checked "+
|
51
|
+
"and #{count} errors found."
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|
data/lib/utterson/html_check.rb
CHANGED
@@ -5,6 +5,8 @@ require 'timeout'
|
|
5
5
|
require 'thread'
|
6
6
|
|
7
7
|
module Utterson
|
8
|
+
# Handle collecting URIs from HTML documents and both remote and
|
9
|
+
# local checking of them.
|
8
10
|
class HtmlCheck
|
9
11
|
attr_reader :errors
|
10
12
|
|
@@ -61,23 +63,18 @@ module Utterson
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def check_remote_uri(url, file)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
uri = URI(url.gsub(/^\/\//, 'http://'))
|
67
|
+
|
68
|
+
response = Net::HTTP.start(uri.host, uri.port,
|
69
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
70
|
+
http.head uri.path.empty? ? "/" : uri.path
|
68
71
|
end
|
69
|
-
|
70
|
-
|
71
|
-
:use_ssl => uri.scheme == 'https') do |http|
|
72
|
-
p = uri.path.empty? ? "/" : uri.path
|
73
|
-
http.head(p)
|
74
|
-
end
|
75
|
-
if response.code =~ /^[^23]/
|
76
|
-
add_error(file, uri.to_s, response)
|
77
|
-
end
|
78
|
-
rescue => e
|
79
|
-
add_error(file, uri.to_s, e.message)
|
72
|
+
if response.code =~ /^[^23]/
|
73
|
+
add_error(file, uri.to_s, response)
|
80
74
|
end
|
75
|
+
|
76
|
+
rescue => e
|
77
|
+
add_error(file, uri.to_s, e.message)
|
81
78
|
end
|
82
79
|
|
83
80
|
def check_local_uri(url, file)
|
@@ -87,7 +84,7 @@ module Utterson
|
|
87
84
|
else
|
88
85
|
path = File.expand_path(url, File.dirname(file))
|
89
86
|
end
|
90
|
-
add_error(file, url, "File not found") unless File.
|
87
|
+
add_error(file, url, "File not found") unless File.exist? path
|
91
88
|
end
|
92
89
|
|
93
90
|
def add_error(file, url, response)
|
data/lib/utterson/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/utterson/base_spec.rb
CHANGED
@@ -11,7 +11,7 @@ module Utterson
|
|
11
11
|
"spec/fixtures/dir-structure/2.html",
|
12
12
|
"spec/fixtures/dir-structure/a/3.htm",
|
13
13
|
"spec/fixtures/dir-structure/a/b/4.html"].each do |file|
|
14
|
-
HtmlCheck.
|
14
|
+
expect(HtmlCheck).to receive(:new).with(file: file, root: dir)
|
15
15
|
end
|
16
16
|
|
17
17
|
u.check
|
@@ -23,7 +23,7 @@ module Utterson
|
|
23
23
|
output = capture_stdout do
|
24
24
|
u.check
|
25
25
|
end
|
26
|
-
output.
|
26
|
+
expect(output).to match(/4 files with 0 urls checked/)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should output error information" do
|
@@ -34,11 +34,12 @@ module Utterson
|
|
34
34
|
output = capture_stdout do
|
35
35
|
u.check
|
36
36
|
end
|
37
|
-
output.
|
38
|
-
|
39
|
-
output.
|
40
|
-
output.
|
41
|
-
output.
|
37
|
+
expect(output).to match("spec/fixtures/sample.html\n\tstyle.css\n"+
|
38
|
+
"\t\tFile not found")
|
39
|
+
expect(output).to match("script.js\n\t\tFile not found")
|
40
|
+
expect(output).to match("image.jpg\n\t\tFile not found")
|
41
|
+
expect(output).to match("http://example.com\n\t\tHTTP 404")
|
42
|
+
expect(output).to match("5 files with 4 urls checked and 4 errors found")
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -18,10 +18,10 @@ module Utterson
|
|
18
18
|
it "should find all uris from sample document" do
|
19
19
|
h = HtmlCheck.new(file: sample_file)
|
20
20
|
uris = h.collect_uris_from(sample_file)
|
21
|
-
uris.
|
22
|
-
uris.
|
23
|
-
uris.
|
24
|
-
uris.
|
21
|
+
expect(uris).to include("script.js")
|
22
|
+
expect(uris).to include("style.css")
|
23
|
+
expect(uris).to include("http://example.com")
|
24
|
+
expect(uris).to include("image.jpg")
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#check_uri" do
|
@@ -65,36 +65,36 @@ module Utterson
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe "#
|
68
|
+
describe "#check_relative_uri" do
|
69
69
|
let(:h) {HtmlCheck.new(root: "spec/fixtures/dir-structure")}
|
70
70
|
let(:html_file) {"spec/fixtures/dir-structure/1.htm"}
|
71
71
|
|
72
72
|
it "should not assign error info if file exists" do
|
73
73
|
h.check_local_uri("../sample.html", html_file)
|
74
|
-
h.errors.
|
74
|
+
expect(h.errors).to be_empty
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should assign error info if file doesn't exist" do
|
78
78
|
url = "../sample_not_found.html"
|
79
79
|
h.check_local_uri(url, html_file)
|
80
|
-
h.errors[html_file].
|
80
|
+
expect(h.errors[html_file]).to eq({url => "File not found"})
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should use root directory when urls start with /" do
|
84
84
|
h2 = HtmlCheck.new(file: html_file,
|
85
85
|
root: "spec/fixtures")
|
86
86
|
h2.check_local_uri("/sample.html", html_file)
|
87
|
-
h2.errors.
|
87
|
+
expect(h2.errors).to be_empty
|
88
88
|
end
|
89
89
|
|
90
|
-
it "
|
90
|
+
it "uses target directory as root if undefined when url starts with /" do
|
91
91
|
h.check_local_uri("/2.html", html_file)
|
92
|
-
h.errors.
|
92
|
+
expect(h.errors).to be_empty
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should ignore query string when checking local files" do
|
96
96
|
h.check_local_uri("2.html?queryparam=value", html_file)
|
97
|
-
h.errors.
|
97
|
+
expect(h.errors).to be_empty
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -108,7 +108,7 @@ module Utterson
|
|
108
108
|
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
109
109
|
to_return(:status => 200, :body => "", :headers => {})
|
110
110
|
h.check_remote_uri(url, html_file)
|
111
|
-
h.errors.
|
111
|
+
expect(h.errors).to be_empty
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should assign error info if there is error response" do
|
@@ -116,40 +116,38 @@ module Utterson
|
|
116
116
|
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
117
117
|
to_return(:status => 404, :body => "", :headers => {})
|
118
118
|
h.check_remote_uri(url, html_file)
|
119
|
-
|
120
|
-
h.errors[html_file].
|
121
|
-
h.errors[html_file][url].instance_of?(Net::HTTPNotFound).should be_true
|
119
|
+
expect(h.errors[html_file]).not_to be_empty
|
120
|
+
expect(h.errors[html_file][url].instance_of?(Net::HTTPNotFound)).to be_truthy
|
122
121
|
end
|
123
122
|
|
124
123
|
it "should add error status from buffer timeouts" do
|
125
124
|
stub_request(:head, url).to_timeout
|
126
125
|
h.check_remote_uri(url, html_file)
|
127
|
-
h.errors.
|
126
|
+
expect(h.errors).not_to be_empty
|
128
127
|
end
|
129
128
|
|
130
129
|
it "should add error status from connection timeouts" do
|
131
130
|
stub_request(:head, url).to_raise(Errno::ETIMEDOUT)
|
132
131
|
h.check_remote_uri(url, html_file)
|
133
|
-
h.errors.
|
132
|
+
expect(h.errors).not_to be_empty
|
134
133
|
end
|
135
134
|
|
136
135
|
it "should add error status from 'No route to host' errors" do
|
137
136
|
stub_request(:head, url).to_raise(Errno::EHOSTUNREACH)
|
138
137
|
h.check_remote_uri(url, html_file)
|
139
|
-
h.errors.
|
138
|
+
expect(h.errors).not_to be_empty
|
140
139
|
end
|
141
140
|
|
142
141
|
it "shoud add error status from name resolution errors" do
|
143
142
|
stub_request(:head, url).
|
144
143
|
to_raise(SocketError.new('getaddrinfo: Name or service not known'))
|
145
144
|
h.check_remote_uri(url, html_file)
|
146
|
-
h.errors.
|
145
|
+
expect(h.errors).not_to be_empty
|
147
146
|
end
|
148
147
|
|
149
148
|
it "shoud add error status when invalid URI" do
|
150
|
-
|
151
|
-
h.
|
152
|
-
h.errors.should_not be_empty
|
149
|
+
h.check_remote_uri(":", html_file)
|
150
|
+
expect(h.errors).not_to be_empty
|
153
151
|
end
|
154
152
|
end
|
155
153
|
end
|
metadata
CHANGED
@@ -1,113 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utterson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juhamatti Niemelä
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: optimist
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.14.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.14.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ruby-progressbar
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.13.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- -
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- -
|
101
|
+
- - ">="
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- -
|
108
|
+
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: webmock
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- - ~>
|
115
|
+
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: 3.18.0
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- - ~>
|
122
|
+
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 3.18.0
|
111
125
|
description: Traverses all HTML files from given directory and checks links found
|
112
126
|
in them.
|
113
127
|
email: iiska@iki.fi
|
@@ -116,20 +130,20 @@ executables:
|
|
116
130
|
extensions: []
|
117
131
|
extra_rdoc_files: []
|
118
132
|
files:
|
133
|
+
- README.md
|
119
134
|
- bin/utterson
|
135
|
+
- lib/utterson.rb
|
136
|
+
- lib/utterson/base.rb
|
120
137
|
- lib/utterson/html_check.rb
|
121
138
|
- lib/utterson/version.rb
|
122
|
-
-
|
123
|
-
-
|
124
|
-
- README.md
|
125
|
-
- spec/utterson/base_spec.rb
|
126
|
-
- spec/utterson/html_check_spec.rb
|
127
|
-
- spec/spec_helper.rb
|
139
|
+
- spec/fixtures/dir-structure/1.htm
|
140
|
+
- spec/fixtures/dir-structure/2.html
|
128
141
|
- spec/fixtures/dir-structure/a/3.htm
|
129
142
|
- spec/fixtures/dir-structure/a/b/4.html
|
130
|
-
- spec/fixtures/dir-structure/2.html
|
131
|
-
- spec/fixtures/dir-structure/1.htm
|
132
143
|
- spec/fixtures/sample.html
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- spec/utterson/base_spec.rb
|
146
|
+
- spec/utterson/html_check_spec.rb
|
133
147
|
homepage: https://github.com/iiska/utterson
|
134
148
|
licenses:
|
135
149
|
- MIT
|
@@ -140,27 +154,25 @@ require_paths:
|
|
140
154
|
- lib
|
141
155
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- -
|
157
|
+
- - ">="
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 2.7.0
|
146
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
161
|
requirements:
|
148
|
-
- -
|
162
|
+
- - ">="
|
149
163
|
- !ruby/object:Gem::Version
|
150
164
|
version: '0'
|
151
165
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 2.0.3
|
166
|
+
rubygems_version: 3.4.10
|
154
167
|
signing_key:
|
155
168
|
specification_version: 4
|
156
169
|
summary: Friendly HTML crawler and url checker
|
157
170
|
test_files:
|
158
|
-
- spec/
|
159
|
-
- spec/
|
160
|
-
- spec/spec_helper.rb
|
171
|
+
- spec/fixtures/dir-structure/1.htm
|
172
|
+
- spec/fixtures/dir-structure/2.html
|
161
173
|
- spec/fixtures/dir-structure/a/3.htm
|
162
174
|
- spec/fixtures/dir-structure/a/b/4.html
|
163
|
-
- spec/fixtures/dir-structure/2.html
|
164
|
-
- spec/fixtures/dir-structure/1.htm
|
165
175
|
- spec/fixtures/sample.html
|
166
|
-
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- spec/utterson/base_spec.rb
|
178
|
+
- spec/utterson/html_check_spec.rb
|