validate-website 1.1.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +0,0 @@
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>
@@ -1,22 +0,0 @@
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/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # encoding: UTF-8
2
- require 'minitest/autorun'
3
- require_relative 'webmock_helper'
4
- require 'spidr'
5
-
6
- require 'validate_website/core'
7
-
8
- ENV['LC_ALL'] = 'C.UTF-8' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
9
-
10
- SPEC_DOMAIN = 'http://www.example.com/'
data/spec/static_spec.rb DELETED
@@ -1,38 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe ValidateWebsite::Static do
4
- before do
5
- @validate_website = ValidateWebsite::Static.new(color: false)
6
- end
7
-
8
- it 'no space in directory name' do
9
- pattern = File.join(File.dirname(__FILE__), 'example/**/*.html')
10
- @validate_website.crawl(pattern: pattern,
11
- site: 'http://dev.af83.com/',
12
- markup: false,
13
- not_found: false)
14
- @validate_website.not_founds_count.must_equal 0
15
- end
16
-
17
- it 'not found' do
18
- pattern = File.join(File.dirname(__FILE__), '**/*.html')
19
- Dir.chdir('spec/data') do
20
- @validate_website.crawl(pattern: pattern,
21
- site: 'https://linuxfr.org/',
22
- markup: false,
23
- not_found: true)
24
- @validate_website.not_founds_count.must_equal 503
25
- end
26
- end
27
-
28
- it 'ignore' do
29
- pattern = File.join(File.dirname(__FILE__), 'data',
30
- 'w3.org-xhtml1-strict-errors.html')
31
- Dir.chdir('spec/data') do
32
- @validate_website.crawl(pattern: pattern,
33
- site: 'http://w3.org/',
34
- ignore: /height|width|Length/)
35
- @validate_website.errors_count.must_equal 0
36
- end
37
- end
38
- end
@@ -1,137 +0,0 @@
1
- # encoding: UTF-8
2
- require File.expand_path('../spec_helper', __FILE__)
3
-
4
- describe ValidateWebsite::Validator do
5
- let(:subject) { ValidateWebsite::Validator }
6
-
7
- before do
8
- WebMock.reset!
9
- @http = Spidr::Agent.new
10
- end
11
-
12
- describe('xhtml1') do
13
- it 'can ignore' do
14
- name = 'w3.org-xhtml1-strict-errors'
15
- file = File.join('spec', 'data', "#{name}.html")
16
- page = FakePage.new(name,
17
- body: open(file).read,
18
- content_type: 'text/html')
19
- @xhtml1_page = @http.get_page(page.url)
20
- ignore = /width|height|Length/
21
- validator = subject.new(@xhtml1_page.doc,
22
- @xhtml1_page.body,
23
- ignore)
24
- validator.valid?.must_equal true
25
- validator.errors.size.must_equal 0
26
- end
27
-
28
- it 'xhtml1-strict should be valid' do
29
- name = 'xhtml1-strict'
30
- dtd_uri = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
31
- file = File.join('spec', 'data', "#{name}.html")
32
- page = FakePage.new(name,
33
- body: open(file).read,
34
- content_type: 'text/html')
35
- @xhtml1_page = @http.get_page(page.url)
36
- validator = subject.new(@xhtml1_page.doc,
37
- @xhtml1_page.body)
38
- validator.dtd.system_id.must_equal dtd_uri
39
- validator.namespace.must_equal name
40
- validator.valid?.must_equal true
41
- end
42
- end
43
-
44
- describe('html5') do
45
- describe('when valid') do
46
- before do
47
- validator_res = File.join('spec', 'data', 'validator.nu-success.html')
48
- stub_request(:any, subject.html5_validator_service_url)
49
- .to_return(body: open(validator_res).read)
50
- end
51
- it 'html5 should be valid' do
52
- name = 'html5'
53
- file = File.join('spec', 'data', "#{name}.html")
54
- page = FakePage.new(name,
55
- body: open(file).read,
56
- content_type: 'text/html')
57
- @html5_page = @http.get_page(page.url)
58
- validator = subject.new(@html5_page.doc,
59
- @html5_page.body)
60
- validator.valid?.must_equal true
61
- end
62
- it 'with DLFP' do
63
- name = 'html5'
64
- file = File.join('spec', 'data', "#{name}-linuxfr.html")
65
- page = FakePage.new(name,
66
- body: open(file).read,
67
- content_type: 'text/html')
68
- @html5_page = @http.get_page(page.url)
69
- validator = subject.new(@html5_page.doc,
70
- @html5_page.body)
71
- validator.valid?.must_equal true
72
- end
73
- end
74
- describe('when not valid') do
75
- before do
76
- validator_res = File.join('spec', 'data', 'validator.nu-failure.html')
77
- stub_request(:any, subject.html5_validator_service_url)
78
- .to_return(body: open(validator_res).read)
79
- name = 'html5'
80
- file = File.join('spec', 'data', "#{name}-linuxfr.html")
81
- page = FakePage.new(name,
82
- body: open(file).read,
83
- content_type: 'text/html')
84
- @html5_page = @http.get_page(page.url)
85
- end
86
-
87
- it 'should have an array of errors' do
88
- validator = subject.new(@html5_page.doc,
89
- @html5_page.body)
90
- validator.valid?.must_equal false
91
- validator.errors.size.must_equal 38
92
- end
93
-
94
- it 'should exclude errors ignored by :ignore option' do
95
- ignore = /The nowrap attribute on the td element is obsolete/
96
- validator = subject.new(@html5_page.doc,
97
- @html5_page.body,
98
- ignore)
99
- validator.valid?.must_equal false
100
- validator.errors.size.must_equal 36
101
- end
102
- end
103
-
104
- describe('excessive') do
105
- before do
106
- validator_res = File.join('spec', 'data', 'validator.nu-excessive.html')
107
- stub_request(:any, subject.html5_validator_service_url)
108
- .to_return(body: open(validator_res).read)
109
- end
110
- it 'html5 should have errors' do
111
- name = 'html5'
112
- file = File.join('spec', 'data', "#{name}.html")
113
- page = FakePage.new(name,
114
- body: open(file).read,
115
- content_type: 'text/html')
116
- @html5_page = @http.get_page(page.url)
117
- validator = subject.new(@html5_page.doc,
118
- @html5_page.body)
119
- validator.valid?.must_equal false
120
- end
121
- end
122
- end
123
-
124
- describe('html4') do
125
- it 'should validate html4' do
126
- name = 'html4-strict'
127
- file = File.join('spec', 'data', "#{name}.html")
128
- page = FakePage.new(name,
129
- body: open(file).read,
130
- content_type: 'text/html')
131
- @html4_strict_page = @http.get_page(page.url)
132
- validator = subject.new(@html4_strict_page.doc,
133
- @html4_strict_page.body)
134
- validator.valid?.must_equal true
135
- end
136
- end
137
- end
@@ -1,40 +0,0 @@
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
- SPEC_DOMAIN + @name
25
- end
26
-
27
- private
28
-
29
- def create_body
30
- @body = '<html><body>'
31
- @links.each { |l| @body += "<a href=\"#{SPEC_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