w3c_validators 1.2 → 1.3

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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +7 -0
  4. data/CHANGELOG +14 -2
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +43 -0
  7. data/{README.rdoc → README.md} +41 -29
  8. data/Rakefile +64 -0
  9. data/lib/w3c_validators.rb +2 -1
  10. data/lib/w3c_validators/css_validator.rb +23 -16
  11. data/lib/w3c_validators/feed_validator.rb +4 -4
  12. data/lib/w3c_validators/markup_validator.rb +29 -29
  13. data/lib/w3c_validators/message.rb +6 -2
  14. data/lib/w3c_validators/nu_validator.rb +2 -2
  15. data/lib/w3c_validators/validator.rb +48 -43
  16. data/lib/w3c_validators/version.rb +3 -0
  17. data/test/fixtures/bootstrap.min.css +6 -0
  18. data/test/fixtures/invalid_css.css +2 -0
  19. data/test/fixtures/invalid_encoding.html +10 -0
  20. data/test/fixtures/invalid_feed.xml +19 -0
  21. data/test/fixtures/invalid_html5.html +16 -0
  22. data/test/fixtures/invalid_markup.html +11 -0
  23. data/test/fixtures/valid_css.css +2 -0
  24. data/test/fixtures/valid_feed.xml +20 -0
  25. data/test/fixtures/valid_html5.html +16 -0
  26. data/test/fixtures/valid_markup.html +11 -0
  27. data/test/http_recording/css_context.yml +72 -0
  28. data/test/http_recording/css_overriding_css_profile.yml +66 -0
  29. data/test/http_recording/css_skippedstring.yml +72 -0
  30. data/test/http_recording/css_validating_big_file.yml +1423 -0
  31. data/test/http_recording/css_validating_file.yml +72 -0
  32. data/test/http_recording/css_validating_text.yml +66 -0
  33. data/test/http_recording/css_validating_text_via_file.yml +72 -0
  34. data/test/http_recording/css_validating_uri.yml +65 -0
  35. data/test/http_recording/css_vendor_extensions_as_errors.yml +65 -0
  36. data/test/http_recording/css_vendor_extensions_as_warnings.yml +62 -0
  37. data/test/http_recording/css_vendor_extensions_default.yml +62 -0
  38. data/test/http_recording/feed_validating_file.yml +49 -0
  39. data/test/http_recording/feed_validating_text.yml +46 -0
  40. data/test/http_recording/feed_validating_text_via_file.yml +49 -0
  41. data/test/http_recording/feed_validating_uri_with_soap.yml +50 -0
  42. data/test/http_recording/html5_getting_request_data.yml +51 -0
  43. data/test/http_recording/html5_validating_uri.yml +74 -0
  44. data/test/http_recording/markup_debugging_uri.yml +83 -0
  45. data/test/http_recording/markup_overriding_charset.yml +125 -0
  46. data/test/http_recording/markup_overriding_charset_for_fallback_only.yml +76 -0
  47. data/test/http_recording/markup_overriding_doctype.yml +208 -0
  48. data/test/http_recording/markup_overriding_doctype_for_fallback_only.yml +84 -0
  49. data/test/http_recording/markup_validating_file.yml +93 -0
  50. data/test/http_recording/markup_validating_text.yml +67 -0
  51. data/test/http_recording/markup_validating_text_via_file.yml +93 -0
  52. data/test/http_recording/markup_validating_uri_with_head_request.yml +38 -0
  53. data/test/http_recording/markup_validating_uri_with_soap.yml +76 -0
  54. data/test/http_recording/markup_validator_abort.yml +50 -0
  55. data/test/http_recording/markup_validator_contains_details_of_error_conditions.yml +76 -0
  56. data/test/test_css_validator.rb +78 -17
  57. data/test/test_exceptions.rb +11 -8
  58. data/test/test_feed_validator.rb +42 -39
  59. data/test/test_helper.rb +7 -2
  60. data/test/test_html5_validator.rb +42 -34
  61. data/test/test_markup_validator.rb +75 -52
  62. data/test/test_proxy.rb +5 -2
  63. data/w3c_validators.gemspec +24 -0
  64. metadata +154 -68
@@ -14,22 +14,25 @@ class ExceptionTests < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_bad_validator_uri
17
- skip("Pending, broken")
18
- ['http://noexist/', 'http://noexist.badtld/',
19
- 'http://example.com/noexist'].each do |uri|
20
- v = MarkupValidator.new(:validator_uri => uri)
21
- assert_raise ValidatorUnavailable do
22
- r = v.validate_text(@valid_fragment)
17
+ VCR.turned_off do
18
+ WebMock.allow_net_connect!
19
+ ['http://noexist/', 'http://noexist.badtld/',
20
+ 'http://example.com/noexist'].each do |uri|
21
+ v = MarkupValidator.new(:validator_uri => uri)
22
+ assert_raise ValidatorUnavailable do
23
+ v.validate_text(@valid_fragment)
24
+ end
23
25
  end
26
+ WebMock.disable_net_connect!
24
27
  end
25
28
  end
26
29
 
27
30
  def test_bad_soap_response
28
- skip("Pending, broken")
31
+ omit("Pending, broken")
29
32
  [].each do |uri|
30
33
  v = MarkupValidator.new(:validator_uri => uri)
31
34
  assert_raise ParsingError do
32
- r = v.validate_text(@valid_fragment)
35
+ v.validate_text(@valid_fragment)
33
36
  end
34
37
  end
35
38
  end
@@ -9,57 +9,60 @@ class FeedValidatorTests < Test::Unit::TestCase
9
9
  end
10
10
 
11
11
  def test_validating_uri_with_soap
12
- skip("Pending, broken")
13
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_feed.xml')
14
- assert_errors r, 1
15
- assert_warnings r, 1
12
+ VCR.use_cassette('feed_validating_uri_with_soap') do
13
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_feed.xml')
14
+ assert_errors r, 1
15
+ assert_warnings r, 1
16
+ end
16
17
  end
17
18
 
18
19
  def test_validating_file
19
- skip("Pending, broken")
20
- file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
21
- r = @v.validate_file(file_path)
22
- assert_errors r, 1
20
+ VCR.use_cassette('feed_validating_file') do
21
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
22
+ r = @v.validate_file(file_path)
23
+ assert_errors r, 1
24
+ end
23
25
  end
24
26
 
25
27
  def test_validating_text
26
- skip("Pending, broken")
27
- fragment = <<-EOT
28
- <?xml version="1.0" encoding="utf-8"?>
29
- <feed xmlns="http://www.w3.org/2005/Atom">
30
- <title>Example Feed</title>
31
- <subtitle>A subtitle.</subtitle>
32
- <link href="http://example.org/feed/" rel="self"/>
33
- <link href="http://example.org/"/>
34
- <updated>2003-12-13T18:30:02Z</updated>
35
- <author>
36
- <email>johndoe@example.com</email>
37
- </author>
38
- <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
39
- <entry>
40
- <title>Atom-Powered Robots Run Amok</title>
41
- <link href="http://example.org/2003/12/13/atom03"/>
42
- <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
28
+ VCR.use_cassette('feed_validating_text') do
29
+ fragment = <<-EOT
30
+ <?xml version="1.0" encoding="utf-8"?>
31
+ <feed xmlns="http://www.w3.org/2005/Atom">
32
+ <title>Example Feed</title>
33
+ <subtitle>A subtitle.</subtitle>
34
+ <link href="http://example.org/feed/" rel="self"/>
35
+ <link href="http://example.org/"/>
43
36
  <updated>2003-12-13T18:30:02Z</updated>
44
- <summary>Some text.</summary>
45
- </entry>
46
- </feed>
47
- EOT
37
+ <author>
38
+ <email>johndoe@example.com</email>
39
+ </author>
40
+ <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
41
+ <entry>
42
+ <title>Atom-Powered Robots Run Amok</title>
43
+ <link href="http://example.org/2003/12/13/atom03"/>
44
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
45
+ <updated>2003-12-13T18:30:02Z</updated>
46
+ <summary>Some text.</summary>
47
+ </entry>
48
+ </feed>
49
+ EOT
48
50
 
49
- r = @v.validate_text(fragment)
50
- assert_equal 1, r.errors.length
51
+ r = @v.validate_text(fragment)
52
+ assert_equal 1, r.errors.length
53
+ end
51
54
  end
52
55
 
53
56
 
54
57
  def test_validating_text_via_file
55
- skip("Pending, broken")
56
- file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
57
- fh = File.new(file_path, 'r+')
58
- r = @v.validate_file(fh)
59
- fh.close
60
- assert_errors r, 1
58
+ VCR.use_cassette('feed_validating_text_via_file') do
59
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
60
+ fh = File.new(file_path, 'r+')
61
+ r = @v.validate_file(fh)
62
+ fh.close
63
+ assert_errors r, 1
64
+ end
61
65
  end
62
66
 
63
-
64
-
65
67
  end
68
+
@@ -1,8 +1,13 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'iconv'
3
2
  require 'rubygems'
4
3
  require 'test/unit'
5
4
  require 'w3c_validators'
5
+ require 'vcr'
6
+
7
+ VCR.configure do |config|
8
+ config.cassette_library_dir = "test/http_recording"
9
+ config.hook_into :webmock # or :fakeweb
10
+ end
6
11
 
7
12
  class Test::Unit::TestCase
8
13
 
@@ -36,4 +41,4 @@ class Test::Unit::TestCase
36
41
  end
37
42
  end
38
43
 
39
- end
44
+ end
@@ -9,50 +9,58 @@ class HTML5ValidatorTests < Test::Unit::TestCase
9
9
  end
10
10
 
11
11
  def test_getting_request_data
12
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/valid_html5.html')
13
- assert_equal :html5, r.doctype
14
- assert_equal 'http://code.dunae.ca/w3c_validators/test/valid_html5.html', r.uri
15
- assert_no_errors r
16
- assert_no_warnings r
17
- assert r.is_valid?
12
+ VCR.use_cassette('html5_getting_request_data') do
13
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/valid_html5.html')
14
+ assert_equal :html5, r.doctype
15
+ assert_equal 'https://doc75.github.io/w3c_validators_tests/valid_html5.html', r.uri
16
+ assert_no_errors r
17
+ assert_no_warnings r
18
+ assert r.is_valid?
19
+ end
18
20
  end
19
21
 
20
22
  def test_validating_uri
21
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_html5.html')
22
- assert_errors r, 2
23
- assert_warnings r, 1
24
- assert !r.is_valid?
23
+ VCR.use_cassette('html5_validating_uri') do
24
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_html5.html')
25
+ assert_errors r, 2
26
+ assert_no_warnings r
27
+ assert !r.is_valid?
28
+ end
25
29
  end
26
30
 
27
31
  def test_validating_file
28
- skip("Pending, broken")
29
- file = File.dirname(__FILE__) + '/fixtures/invalid_html5.html'
30
- r = @v.validate_file(file)
31
- assert_errors r, 1
32
+ omit('Pending, broken')
33
+ VCR.use_cassette('html5_validating_file') do
34
+ file = File.dirname(__FILE__) + '/fixtures/invalid_html5.html'
35
+ r = @v.validate_file(file)
36
+ assert_errors r, 1
37
+ end
32
38
  end
33
39
 
34
40
  def test_validating_text
35
- skip("Pending, broken")
36
- valid_fragment = <<-EOV
37
- <!DOCTYPE html>
38
- <html lang="en-ca">
39
- <head>
40
- <title>HTML 5 Example</title>
41
- </head>
42
- <body>
43
- <!-- should have one error (missing </section>) -->
44
- <p>This is a sample HTML 5 document.</p>
45
- <section>
46
- <h1>Example of paragraphs</h1>
47
- This is the <em>first</em> paragraph in this example.
48
- <p>This is the second.</p>
49
- <p>Test<br>test</p>
50
- </body>
51
- </html>
52
- EOV
41
+ omit('Pending, broken')
42
+ VCR.use_cassette('html5_validating_text') do
43
+ valid_fragment = <<-EOV
44
+ <!DOCTYPE html>
45
+ <html lang="en-ca">
46
+ <head>
47
+ <title>HTML 5 Example</title>
48
+ </head>
49
+ <body>
50
+ <!-- should have one error (missing </section>) -->
51
+ <p>This is a sample HTML 5 document.</p>
52
+ <section>
53
+ <h1>Example of paragraphs</h1>
54
+ This is the <em>first</em> paragraph in this example.
55
+ <p>This is the second.</p>
56
+ <p>Test<br>test</p>
57
+ </body>
58
+ </html>
59
+ EOV
53
60
 
54
- r = @v.validate_text(valid_fragment)
55
- assert_errors r, 1
61
+ r = @v.validate_text(valid_fragment)
62
+ assert_errors r, 1
63
+ end
56
64
  end
57
65
 
58
66
  #def test_validating_text_via_file
@@ -1,5 +1,4 @@
1
1
  require File.expand_path('test_helper', File.dirname(__FILE__))
2
- require 'ruby-debug'
3
2
 
4
3
  # Test cases for the MarkupValidator.
5
4
  class MarkupValidatorTests < Test::Unit::TestCase
@@ -10,91 +9,115 @@ class MarkupValidatorTests < Test::Unit::TestCase
10
9
  end
11
10
 
12
11
  def test_overriding_doctype
13
- @v.set_doctype!(:html32, false)
14
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
15
- assert_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
12
+ VCR.use_cassette('markup_overriding_doctype') do
13
+ @v.set_doctype!(:html32, false)
14
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup.html')
15
+ assert_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
16
+ end
16
17
  end
17
18
 
18
19
  def test_overriding_doctype_for_fallback_only
19
- @v.set_doctype!(:html32, true)
20
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
21
- assert_not_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
20
+ VCR.use_cassette('markup_overriding_doctype_for_fallback_only') do
21
+ @v.set_doctype!(:html32, true)
22
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_1.html')
23
+ assert_not_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
24
+ end
22
25
  end
23
26
 
24
27
  def test_overriding_charset
25
- @v.set_charset!(:utf_16, false)
26
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
27
- assert_equal 'utf-16', r.charset
28
+ VCR.use_cassette('markup_overriding_charset') do
29
+ @v.set_charset!(:utf_16, false)
30
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_2.html')
31
+ assert_equal 'utf-16', r.charset
32
+ end
28
33
  end
29
34
 
30
35
  def test_overriding_charset_for_fallback_only
31
- @v.set_doctype!(:utf_16, true)
32
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
33
- assert_not_equal 'utf-16', r.charset
36
+ VCR.use_cassette('markup_overriding_charset_for_fallback_only') do
37
+ @v.set_doctype!(:utf_16, true)
38
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/markup_overriding_charset_for_fallback_only.html')
39
+ assert_not_equal 'utf-16', r.charset
40
+ end
34
41
  end
35
42
 
36
43
  def test_validating_uri_with_head_request
37
- r = @v.validate_uri_quickly('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
38
- assert_errors r, 1
44
+ VCR.use_cassette('markup_validating_uri_with_head_request') do
45
+ r = @v.validate_uri_quickly('https://doc75.github.io/w3c_validators_tests/invalid_markup_4.html')
46
+ assert_errors r, 1
47
+ end
39
48
  end
40
49
 
41
50
  def test_validating_uri_with_soap
42
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
43
- assert_errors r, 1
44
- assert_no_warnings r
51
+ VCR.use_cassette('markup_validating_uri_with_soap') do
52
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_5.html')
53
+ assert_errors r, 1
54
+ assert_no_warnings r
55
+ end
45
56
  end
46
57
 
47
58
  def test_debugging_uri
48
- @v.set_debug!
49
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
50
- assert r.debug_messages.length > 0
59
+ VCR.use_cassette('markup_debugging_uri') do
60
+ @v.set_debug!
61
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_6.html')
62
+ assert r.debug_messages.length > 0
63
+ end
51
64
  end
52
65
 
53
66
  def test_validating_file
54
- file = File.dirname(__FILE__) + '/fixtures/invalid_markup.html'
55
- r = @v.validate_file(file)
56
- assert_errors r, 1
67
+ VCR.use_cassette('markup_validating_file') do
68
+ file = File.dirname(__FILE__) + '/fixtures/invalid_markup.html'
69
+ r = @v.validate_file(file)
70
+ assert_errors r, 1
57
71
 
58
- assert r.uri =~ /fixtures\/invalid_markup\.html$/
72
+ assert r.uri =~ /fixtures\/invalid_markup\.html$/
73
+ end
59
74
  end
60
75
 
61
76
  def test_validating_text
62
- skip("Pending, broken")
63
- valid_fragment = <<-EOV
64
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
65
- <title>Test</title>
66
- <body>
67
- <div class="example">This is a test</div>
68
- </body>
69
- EOV
70
-
71
- r = @v.validate_text(valid_fragment)
72
- assert_no_errors r
73
- assert_no_warnings r
77
+ VCR.use_cassette('markup_validating_text') do
78
+ valid_fragment = <<-EOV
79
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
80
+ <title>Test</title>
81
+ <body>
82
+ <div class="example">This is a test</div>
83
+ </body>
84
+ EOV
85
+
86
+ r = @v.validate_text(valid_fragment)
87
+ assert_no_errors r
88
+ assert_warnings r, 2
89
+ end
74
90
  end
75
91
 
76
92
  def test_validating_text_via_file
77
- fh = File.new(File.dirname(__FILE__) + '/fixtures/invalid_markup.html', 'r+')
78
- r = @v.validate_file(fh)
79
- fh.close
80
- assert_errors r, 1
93
+ VCR.use_cassette('markup_validating_text_via_file') do
94
+ fh = File.new(File.dirname(__FILE__) + '/fixtures/invalid_markup.html', 'r+')
95
+ r = @v.validate_file(fh)
96
+ fh.close
97
+ assert_errors r, 1
98
+ end
81
99
  end
82
100
 
83
101
 
84
102
  def test_validator_abort
85
- @v.set_debug!
86
- assert_nothing_raised do
87
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_encoding.html')
88
- assert !r.is_valid?
89
- assert_errors r, 1
90
- assert_no_warnings r
103
+ VCR.use_cassette('markup_validator_abort') do
104
+ @v.set_debug!
105
+ assert_nothing_raised do
106
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_encoding.html')
107
+ assert !r.is_valid?
108
+ assert_errors r, 1
109
+ assert_no_warnings r
110
+ end
91
111
  end
92
112
  end
93
113
 
94
- def test_validator_contains_details_of_error_conditions
95
- r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
96
- assert_not_nil r.errors[0].col
97
- assert_not_nil r.errors[0].line
98
- assert_not_nil r.errors[0].message
114
+ def test_validator_contains_details_of_error_conditions
115
+ VCR.use_cassette('markup_validator_contains_details_of_error_conditions') do
116
+ r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_7.html')
117
+ assert_not_nil r.errors[0].col
118
+ assert_not_nil r.errors[0].line
119
+ assert_not_nil r.errors[0].message
120
+ end
99
121
  end
100
122
  end
123
+
@@ -22,7 +22,10 @@ class ProxyTests < Test::Unit::TestCase
22
22
 
23
23
 
24
24
  def test_validating_uri_with_head_request
25
- r = @v.validate_uri_quickly('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
26
- assert_errors r, 1
25
+ omit("Pending, to prevent w3.org abuse")
26
+ VCR.use_cassette('markup_overriding_doctype') do
27
+ r = @v.validate_uri_quickly('https://doc75.github.io/w3c_validators_tests/invalid_markup_8.html')
28
+ assert_errors r, 1
29
+ end
27
30
  end
28
31
  end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/w3c_validators/version.rb', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alex Dunae"]
6
+ gem.summary = "A Ruby wrapper for the World Wide Web Consortium’s online validation services."
7
+ gem.homepage = "https://github.com/w3c-validators/w3c_validators"
8
+
9
+ gem.files = `git ls-files`.split("\n")
10
+ gem.test_files = `git ls-files -- {test}/*`.split("\n")
11
+ gem.name = "w3c_validators"
12
+ gem.require_paths = ["lib"]
13
+ gem.version = W3CValidators::VERSION
14
+
15
+ gem.required_ruby_version = '~>2.0'
16
+
17
+ gem.add_dependency 'nokogiri', '~> 1.6'
18
+ gem.add_dependency 'json', '~> 2.0'
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'vcr'
22
+ gem.add_development_dependency 'webmock'
23
+ gem.add_development_dependency 'test-unit'
24
+ end