validate-website 1.5.0 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +3 -2
- data/lib/validate_website/core.rb +7 -2
- data/lib/validate_website/version.rb +1 -1
- data/test/core_test.rb +10 -0
- data/test/crawler_test.rb +163 -0
- data/test/data/assets/application-92f19110a9d47a56d2ebe744e15af301.css +2 -0
- data/test/data/html4-strict.html +239 -0
- data/test/data/html5-linuxfr.html +1286 -0
- data/test/data/html5.html +46 -0
- data/test/data/news/ryzom-naissance-du-projet-libre-ryzom-forge.md +0 -0
- data/test/data/validator.nu-excessive.html +118 -0
- data/test/data/validator.nu-failure.html +10 -0
- data/test/data/validator.nu-success.html +2 -0
- data/test/data/w3.org-xhtml1-strict-errors.html +544 -0
- data/test/data/xhtml1-strict.html +22 -0
- data/test/example/ruby smalltalk/blockcamp-paris-le-28-novembre.html +22 -0
- data/test/static_test.rb +61 -0
- data/test/test_helper.rb +9 -0
- data/test/validator_test.rb +136 -0
- data/test/webmock_helper.rb +40 -0
- metadata +29 -8
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
5
|
+
<head>
|
6
|
+
<title>title</title>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<h1>Title 1</h1>
|
10
|
+
<p>Paragraphe.</p>
|
11
|
+
|
12
|
+
<h2>Title 2</h2>
|
13
|
+
<ul>
|
14
|
+
<li><a href="/my-url1" title="title">my url</a></li>
|
15
|
+
<li><a href="/my-url2" title="title">my url</a></li>
|
16
|
+
<li><a href="/my-url1" title="title">my url</a></li>
|
17
|
+
</ul>
|
18
|
+
<p><img src="http://test.com/img.png" alt="non local img" /></p>
|
19
|
+
<p><img src="http://www.example.com/img1.png" alt="local img with absolute uri" /></p>
|
20
|
+
<p><img src="/img2.png" alt="local img with non absolute uri" /></p>
|
21
|
+
</body>
|
22
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
5
|
+
<head>
|
6
|
+
<title>title</title>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<h1>Title 1</h1>
|
10
|
+
<p>Paragraphe.</p>
|
11
|
+
|
12
|
+
<h2>Title 2</h2>
|
13
|
+
<ul>
|
14
|
+
<li><a href="/my-url1" title="title">my url</a></li>
|
15
|
+
<li><a href="/my-url2" title="title">my url</a></li>
|
16
|
+
<li><a href="/my-url1" title="title">my url</a></li>
|
17
|
+
</ul>
|
18
|
+
<p><img src="http://test.com/img.png" alt="non local img" /></p>
|
19
|
+
<p><img src="http://www.example.com/img1.png" alt="local img with absolute uri" /></p>
|
20
|
+
<p><img src="/img2.png" alt="local img with non absolute uri" /></p>
|
21
|
+
</body>
|
22
|
+
</html>
|
data/test/static_test.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe ValidateWebsite::Static do
|
4
|
+
before do
|
5
|
+
_out, _err = capture_io do
|
6
|
+
@validate_website = ValidateWebsite::Static.new(color: false)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'no space in directory name' do
|
11
|
+
pattern = File.join(File.dirname(__FILE__), 'example/**/*.html')
|
12
|
+
_out, _err = capture_io do
|
13
|
+
@validate_website.crawl(pattern: pattern,
|
14
|
+
site: 'http://dev.af83.com/',
|
15
|
+
markup: false,
|
16
|
+
not_found: false)
|
17
|
+
end
|
18
|
+
@validate_website.not_founds_count.must_equal 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'not found' do
|
22
|
+
pattern = File.join(File.dirname(__FILE__), '**/*.html')
|
23
|
+
Dir.chdir('test/data') do
|
24
|
+
_out, _err = capture_io do
|
25
|
+
@validate_website.crawl(pattern: pattern,
|
26
|
+
site: 'https://linuxfr.org/',
|
27
|
+
markup: false,
|
28
|
+
not_found: true)
|
29
|
+
end
|
30
|
+
@validate_website.not_founds_count.must_equal 503
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'ignore' do
|
35
|
+
pattern = File.join(File.dirname(__FILE__), 'data',
|
36
|
+
'w3.org-xhtml1-strict-errors.html')
|
37
|
+
Dir.chdir('test/data') do
|
38
|
+
_out, _err = capture_io do
|
39
|
+
@validate_website.crawl(pattern: pattern,
|
40
|
+
site: 'http://w3.org/',
|
41
|
+
ignore: /height|width|Length/)
|
42
|
+
end
|
43
|
+
@validate_website.errors_count.must_equal 0
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'css' do
|
48
|
+
it 'validate' do
|
49
|
+
pattern = File.join(File.dirname(__FILE__), '**/*.{html,css}')
|
50
|
+
Dir.chdir('test/data') do
|
51
|
+
_out, _err = capture_io do
|
52
|
+
@validate_website.crawl(pattern: pattern,
|
53
|
+
site: 'https://linuxfr.org/',
|
54
|
+
markup: false,
|
55
|
+
css_syntax: true)
|
56
|
+
end
|
57
|
+
@validate_website.errors_count.must_equal 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe ValidateWebsite::Validator do
|
4
|
+
let(:subject) { ValidateWebsite::Validator }
|
5
|
+
|
6
|
+
before do
|
7
|
+
WebMock.reset!
|
8
|
+
@http = Spidr::Agent.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe('xhtml1') do
|
12
|
+
it 'can ignore' do
|
13
|
+
name = 'w3.org-xhtml1-strict-errors'
|
14
|
+
file = File.join('test', 'data', "#{name}.html")
|
15
|
+
page = FakePage.new(name,
|
16
|
+
body: open(file).read,
|
17
|
+
content_type: 'text/html')
|
18
|
+
@xhtml1_page = @http.get_page(page.url)
|
19
|
+
ignore = /width|height|Length/
|
20
|
+
validator = subject.new(@xhtml1_page.doc,
|
21
|
+
@xhtml1_page.body,
|
22
|
+
ignore)
|
23
|
+
validator.valid?.must_equal true
|
24
|
+
validator.errors.size.must_equal 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'xhtml1-strict should be valid' do
|
28
|
+
name = 'xhtml1-strict'
|
29
|
+
dtd_uri = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
30
|
+
file = File.join('test', 'data', "#{name}.html")
|
31
|
+
page = FakePage.new(name,
|
32
|
+
body: open(file).read,
|
33
|
+
content_type: 'text/html')
|
34
|
+
@xhtml1_page = @http.get_page(page.url)
|
35
|
+
validator = subject.new(@xhtml1_page.doc,
|
36
|
+
@xhtml1_page.body)
|
37
|
+
validator.dtd.system_id.must_equal dtd_uri
|
38
|
+
validator.namespace.must_equal name
|
39
|
+
validator.valid?.must_equal true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe('html5') do
|
44
|
+
describe('when valid') do
|
45
|
+
before do
|
46
|
+
validator_res = File.join('test', 'data', 'validator.nu-success.html')
|
47
|
+
stub_request(:any, subject.html5_validator_service_url)
|
48
|
+
.to_return(body: open(validator_res).read)
|
49
|
+
end
|
50
|
+
it 'html5 should be valid' do
|
51
|
+
name = 'html5'
|
52
|
+
file = File.join('test', 'data', "#{name}.html")
|
53
|
+
page = FakePage.new(name,
|
54
|
+
body: open(file).read,
|
55
|
+
content_type: 'text/html')
|
56
|
+
@html5_page = @http.get_page(page.url)
|
57
|
+
validator = subject.new(@html5_page.doc,
|
58
|
+
@html5_page.body)
|
59
|
+
validator.valid?.must_equal true
|
60
|
+
end
|
61
|
+
it 'with DLFP' do
|
62
|
+
name = 'html5'
|
63
|
+
file = File.join('test', 'data', "#{name}-linuxfr.html")
|
64
|
+
page = FakePage.new(name,
|
65
|
+
body: open(file).read,
|
66
|
+
content_type: 'text/html')
|
67
|
+
@html5_page = @http.get_page(page.url)
|
68
|
+
validator = subject.new(@html5_page.doc,
|
69
|
+
@html5_page.body)
|
70
|
+
validator.valid?.must_equal true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
describe('when not valid') do
|
74
|
+
before do
|
75
|
+
validator_res = File.join('test', 'data', 'validator.nu-failure.html')
|
76
|
+
stub_request(:any, subject.html5_validator_service_url)
|
77
|
+
.to_return(body: open(validator_res).read)
|
78
|
+
name = 'html5'
|
79
|
+
file = File.join('test', 'data', "#{name}-linuxfr.html")
|
80
|
+
page = FakePage.new(name,
|
81
|
+
body: open(file).read,
|
82
|
+
content_type: 'text/html')
|
83
|
+
@html5_page = @http.get_page(page.url)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should have an array of errors' do
|
87
|
+
validator = subject.new(@html5_page.doc,
|
88
|
+
@html5_page.body)
|
89
|
+
validator.valid?.must_equal false
|
90
|
+
validator.errors.size.must_equal 38
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should exclude errors ignored by :ignore option' do
|
94
|
+
ignore = /The nowrap attribute on the td element is obsolete/
|
95
|
+
validator = subject.new(@html5_page.doc,
|
96
|
+
@html5_page.body,
|
97
|
+
ignore)
|
98
|
+
validator.valid?.must_equal false
|
99
|
+
validator.errors.size.must_equal 36
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe('excessive') do
|
104
|
+
before do
|
105
|
+
validator_res = File.join('test', 'data', 'validator.nu-excessive.html')
|
106
|
+
stub_request(:any, subject.html5_validator_service_url)
|
107
|
+
.to_return(body: open(validator_res).read)
|
108
|
+
end
|
109
|
+
it 'html5 should have errors' do
|
110
|
+
name = 'html5'
|
111
|
+
file = File.join('test', 'data', "#{name}.html")
|
112
|
+
page = FakePage.new(name,
|
113
|
+
body: open(file).read,
|
114
|
+
content_type: 'text/html')
|
115
|
+
@html5_page = @http.get_page(page.url)
|
116
|
+
validator = subject.new(@html5_page.doc,
|
117
|
+
@html5_page.body)
|
118
|
+
validator.valid?.must_equal false
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe('html4') do
|
124
|
+
it 'should validate html4' do
|
125
|
+
name = 'html4-strict'
|
126
|
+
file = File.join('test', 'data', "#{name}.html")
|
127
|
+
page = FakePage.new(name,
|
128
|
+
body: open(file).read,
|
129
|
+
content_type: 'text/html')
|
130
|
+
@html4_strict_page = @http.get_page(page.url)
|
131
|
+
validator = subject.new(@html4_strict_page.doc,
|
132
|
+
@html4_strict_page.body)
|
133
|
+
validator.valid?.must_equal true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'webmock/minitest'
|
3
|
+
|
4
|
+
# FakePage html helper for webmock
|
5
|
+
class FakePage
|
6
|
+
include WebMock::API
|
7
|
+
|
8
|
+
attr_accessor :links
|
9
|
+
attr_accessor :hrefs
|
10
|
+
attr_accessor :body
|
11
|
+
|
12
|
+
def initialize(name = '', options = {})
|
13
|
+
@name = name
|
14
|
+
@links = [options[:links]].flatten if options.key?(:links)
|
15
|
+
@hrefs = [options[:hrefs]].flatten if options.key?(:hrefs)
|
16
|
+
@content_type = options[:content_type] || 'text/html'
|
17
|
+
@body = options[:body]
|
18
|
+
|
19
|
+
create_body unless @body
|
20
|
+
add_to_webmock
|
21
|
+
end
|
22
|
+
|
23
|
+
def url
|
24
|
+
TEST_DOMAIN + @name
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_body
|
30
|
+
@body = '<html><body>'
|
31
|
+
@links.each { |l| @body += "<a href=\"#{TEST_DOMAIN}#{l}\"></a>" } if @links
|
32
|
+
@hrefs.each { |h| @body += "<a href=\"#{h}\"></a>" } if @hrefs
|
33
|
+
@body += '</body></html>'
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_to_webmock
|
37
|
+
options = { body: @body, headers: { 'Content-Type' => @content_type } }
|
38
|
+
stub_request(:get, url).to_return(options)
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate-website
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent Arnoud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spidr
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '5.
|
103
|
+
version: '5.6'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '5.
|
110
|
+
version: '5.6'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: minitest-line
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1.
|
131
|
+
version: '1.21'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '1.
|
138
|
+
version: '1.21'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rubocop
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -265,6 +265,23 @@ files:
|
|
265
265
|
- lib/validate_website/version.rb
|
266
266
|
- man/man1/validate-website-static.1
|
267
267
|
- man/man1/validate-website.1
|
268
|
+
- test/core_test.rb
|
269
|
+
- test/crawler_test.rb
|
270
|
+
- test/data/assets/application-92f19110a9d47a56d2ebe744e15af301.css
|
271
|
+
- test/data/html4-strict.html
|
272
|
+
- test/data/html5-linuxfr.html
|
273
|
+
- test/data/html5.html
|
274
|
+
- test/data/news/ryzom-naissance-du-projet-libre-ryzom-forge.md
|
275
|
+
- test/data/validator.nu-excessive.html
|
276
|
+
- test/data/validator.nu-failure.html
|
277
|
+
- test/data/validator.nu-success.html
|
278
|
+
- test/data/w3.org-xhtml1-strict-errors.html
|
279
|
+
- test/data/xhtml1-strict.html
|
280
|
+
- test/example/ruby smalltalk/blockcamp-paris-le-28-novembre.html
|
281
|
+
- test/static_test.rb
|
282
|
+
- test/test_helper.rb
|
283
|
+
- test/validator_test.rb
|
284
|
+
- test/webmock_helper.rb
|
268
285
|
homepage: http://github.com/spk/validate-website
|
269
286
|
licenses:
|
270
287
|
- MIT
|
@@ -288,9 +305,13 @@ requirements:
|
|
288
305
|
- rainbow
|
289
306
|
- multipart_body
|
290
307
|
rubyforge_project:
|
291
|
-
rubygems_version: 2.4.5
|
308
|
+
rubygems_version: 2.4.5.1
|
292
309
|
signing_key:
|
293
310
|
specification_version: 4
|
294
311
|
summary: Web crawler for checking the validity of your documents
|
295
|
-
test_files:
|
312
|
+
test_files:
|
313
|
+
- test/static_test.rb
|
314
|
+
- test/core_test.rb
|
315
|
+
- test/crawler_test.rb
|
316
|
+
- test/validator_test.rb
|
296
317
|
has_rdoc:
|