w3c_validators 0.9.3 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,28 @@
1
+ = CHANGELOG
2
+
3
+ == Version 0.9.0
4
+ * initial version
5
+
6
+ == Version 0.9.1
7
+ * fixed include path bug
8
+
9
+ == Version 0.9.2 (the Ryan King edition)
10
+ * added check for HTML validator being unable to parse a file
11
+
12
+ == Version 0.9.3 (the Ryan King/Jonathan Julian/Sylvain LaFleur edition)
13
+ * MarkupValidator::validate_file now returns file path as Results.uri
14
+ * All validate_file methods now allow a file path or an IO object (e.g. File)
15
+
16
+ == Version 1.0.0 (the GitHub edition)
17
+ * Gemspec is now generated by a rake task to allow dynamic file lists
18
+ * Updated docs
19
+
20
+ == Version 1.0.1 (the Roman Shterenzon and James Rosen edition)
21
+ * Fixed CSS profile constants
22
+ * DRY unit tests
23
+ * GET should be used only for queries with URI
24
+ * Bugfix - file doesn't need to be writeable
25
+
26
+ == Version 1.0.2
27
+ * Added support for proxy servers
28
+ * Fixed to minor unit test errors
@@ -7,7 +7,8 @@ It supports the markup validator, the feed validator and the CSS validator.
7
7
 
8
8
  === Installation
9
9
 
10
- gem install w3c_validators
10
+ gem sources -a http://gems.github.com
11
+ gem install alexdunae-w3c_validators
11
12
 
12
13
  === Usage
13
14
 
@@ -32,6 +33,15 @@ validator. You can set your own validator like this:
32
33
 
33
34
  validator = MarkupValidator.new(:validator_uri => 'http://localhost/check')
34
35
 
36
+ ==== Using a proxy server
37
+
38
+ You can use a proxy server by passing in its information in the contructor.
39
+
40
+ validator = MarkupValidator.new(:proxy_server => 'proxy.example.com',
41
+ :proxy_port => 80,
42
+ :proxy_user => 'optional',
43
+ :proxy_pass => 'optional')
44
+
35
45
  === Examples
36
46
 
37
47
  ==== Example #1: Markup validator, local file
@@ -110,11 +120,14 @@ between each call to the W3C's validators per their request.
110
120
 
111
121
  === Credits and code
112
122
 
113
- Documentation and the source code are available at http://code.dunae.ca/w3c_validators.
123
+ Documentation is available at {http://code.dunae.ca/w3c_validators}[http://code.dunae.ca/w3c_validators].
124
+
125
+ Source is available on {GitHub}[https://github.com/alexdunae/w3c-validators]
126
+
127
+ Written by Alex Dunae ({dunae.ca}[http://dunae.ca/], e-mail 'code' at the same domain), 2007.
114
128
 
115
- Written by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007.
129
+ Thanks to {Ryan King}[http://theryanking.com/] for creating the 0.9.2 update.
116
130
 
117
- Thanks to Ryan King (http://theryanking.com/) for creating the 0.9.2 update.
131
+ Thanks to {Ryan King}[http://theryanking.com/], {Jonathan Julian}[http://jonathanjulian.org/] and Sylvain LaFleur for creating the 0.9.3 update.
118
132
 
119
- Thanks to Ryan King (http://theryanking.com/) and Jonathan Julian for creating the 0.9.3 update.
120
-
133
+ Thanks to {James Rosen}[http://github.com/jamesarosen] and {Roman Shterenzon}[http://github.com/romanbsd] for creating the 1.0.1 update.
@@ -1,5 +1,6 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
  require 'w3c_validators/validator'
3
3
  require 'w3c_validators/markup_validator'
4
+ require 'w3c_validators/nu_validator'
4
5
  require 'w3c_validators/feed_validator'
5
6
  require 'w3c_validators/css_validator'
@@ -1,14 +1,15 @@
1
1
  module W3CValidators
2
- CSS_PROFILES = { :css1 => 'CSS 1',
3
- :css2 => 'CSS 2.0',
4
- :css21 => 'CSS 1.0',
5
- :css3 => 'CSS 3.0',
6
- :svg => 'SVG',
7
- :svgbasic => 'SVG Basic',
8
- :svgtiny => 'SVG Tiny',
9
- :mobile => 'Mobile',
10
- :atsc_tv => 'ATSC TV',
11
- :tv => 'TV'
2
+
3
+ CSS_PROFILES = { :css1 => 'css1',
4
+ :css2 => 'css2',
5
+ :css21 => 'css21',
6
+ :css3 => 'css3',
7
+ :svg => 'svg',
8
+ :svgbasic => 'svgbasic',
9
+ :svgtiny => 'svgtiny',
10
+ :mobile => 'mobile',
11
+ :atsc_tv => 'atsc-tv',
12
+ :tv => 'tv'
12
13
  }
13
14
 
14
15
  DOCTYPES = { :xhtml10_strict => 'XHTML 1.0 Strict',
@@ -17,6 +18,7 @@ module W3CValidators
17
18
  :xhtml401_strict => 'HTML 4.01 Strict',
18
19
  :xhtml401_transitional => 'HTML 4.01 Transitional',
19
20
  :xhtml401_framest => 'HTML 4.01 Frameset',
21
+ :html5 => 'HTML 5',
20
22
  :html32 => 'HTML 3.2',
21
23
  :html20 => 'HTML 2.0',
22
24
  :iso_html => 'ISO/IEC 15445:2000 ("ISO HTML")',
@@ -7,6 +7,8 @@ module W3CValidators
7
7
  # ==== Options
8
8
  # You can pass in your own validator's URI (i.e.
9
9
  # <tt>CSSValidator.new(:validator_uri => 'http://localhost/check')</tt>).
10
+ #
11
+ # See Validator#new for proxy server options.
10
12
  def initialize(options = {})
11
13
  if options[:validator_uri]
12
14
  @validator_uri = URI.parse(options[:validator_uri])
@@ -7,6 +7,8 @@ module W3CValidators
7
7
  # ==== Options
8
8
  # You can pass in your own validator's URI (i.e.
9
9
  # <tt>FeedValidator.new(:validator_uri => 'http://localhost/check')</tt>).
10
+ #
11
+ # See Validator#new for proxy server options.
10
12
  def initialize(options = {})
11
13
  if options[:validator_uri]
12
14
  @validator_uri = URI.parse(options[:validator_uri])
@@ -11,6 +11,8 @@ module W3CValidators
11
11
  #
12
12
  # You can pass in your own validator's URI (i.e.
13
13
  # <tt>MarkupValidator.new(:validator_uri => 'http://localhost/check')</tt>).
14
+ #
15
+ # See Validator#new for proxy server options.
14
16
  def initialize(options = {})
15
17
  if options[:validator_uri]
16
18
  @validator_uri = URI.parse(options[:validator_uri])
@@ -123,7 +125,7 @@ protected
123
125
  response = send_request(options, :head)
124
126
  @results = parse_head_response(response, options[:uri])
125
127
  else
126
- if options.has_key?(:uri) or options.has_key?(:fragment)
128
+ if options.has_key?(:uri)
127
129
  response = send_request(options, :get)
128
130
  else
129
131
  response = send_request(options, :post)
@@ -224,4 +226,4 @@ protected
224
226
 
225
227
 
226
228
  end
227
- end
229
+ end
@@ -0,0 +1,146 @@
1
+ require 'json'
2
+
3
+ module W3CValidators
4
+ class NuValidator < Validator
5
+ MARKUP_VALIDATOR_URI = 'http://validator.nu/'
6
+
7
+ # Create a new instance of the NuValidator.
8
+ #
9
+ # ==== Options
10
+ # The +options+ hash allows you to set request parameters (see
11
+ # http://wiki.whatwg.org/wiki/Validator.nu_Common_Input_Parameters) quickly. Request
12
+ # parameters can also be set using set_charset! and set_doctype!.
13
+ #
14
+ # You can pass in your own validator's URI (i.e.
15
+ # <tt>NuValidator.new(:validator_uri => 'http://localhost/check')</tt>).
16
+ #
17
+ # See Validator#new for proxy server options.
18
+ def initialize(options = {})
19
+ if options[:validator_uri]
20
+ @validator_uri = URI.parse(options[:validator_uri])
21
+ options.delete(options[:validator_uri])
22
+ else
23
+ @validator_uri = URI.parse(MARKUP_VALIDATOR_URI)
24
+ end
25
+ super(options)
26
+ end
27
+
28
+
29
+ # Validate the markup of an URI.
30
+ #
31
+ # Returns W3CValidators::Results.
32
+ def validate_uri(uri)
33
+ return validate({:doc => uri})
34
+ end
35
+
36
+
37
+ # Validate the markup of a string.
38
+ #
39
+ # Returns W3CValidators::Results.
40
+ def validate_text(text)
41
+ return validate({:content => text})
42
+ end
43
+
44
+ # Validate the markup of a local file.
45
+ #
46
+ # +file_path+ may be either the fully-expanded path to the file or
47
+ # an IO object (like File).
48
+ #
49
+ # Returns W3CValidators::Results.
50
+ def validate_file(file)
51
+ if file.respond_to? :read
52
+ src = file.read
53
+ file_path = file.path ||= nil
54
+ else
55
+ src = read_local_file(file)
56
+ file_path = file
57
+ end
58
+
59
+ return validate({:file => src, :file_path => file_path})
60
+ end
61
+
62
+ protected
63
+ def validate(options) # :nodoc:
64
+ options = get_request_options(options)
65
+
66
+ if options.has_key?(:doc)
67
+ response = send_request(options, :get)
68
+ else
69
+ response = send_request(options, :post)
70
+ end
71
+
72
+ @results = parse_json_response(response.body)
73
+ @results
74
+ end
75
+
76
+ # Perform sanity checks on request params
77
+ def get_request_options(options) # :nodoc:
78
+ options = @options.merge(options)
79
+
80
+ options[:out] = 'json'
81
+
82
+ # only option that is currently supported
83
+ options[:showsource] = 'yes'
84
+
85
+ unless options[:doc] or options[:file] or options[:content]
86
+ raise ArgumentError, "an uri, file or block of text is required."
87
+ end
88
+
89
+ # URI should be a string. If it is a URI object, .to_s will
90
+ # be seamless; if it is not an exception will be raised.
91
+ if options[:doc] and not options[:doc].kind_of?(String)
92
+ options[:doc] = options[:doc].to_s
93
+ end
94
+ options
95
+ end
96
+
97
+
98
+ # Parse the JSON response.
99
+ #
100
+ # +response+ must be a Net::HTTPResponse.
101
+ #
102
+ # Returns W3CValidators::Results.
103
+ def parse_json_response(response) # :nodoc:
104
+ doc = JSON.parse(response)
105
+
106
+ result_params = {
107
+ :doctype => :html5,
108
+ :checked_by => MARKUP_VALIDATOR_URI
109
+ }
110
+
111
+ result_params[:uri] = doc['url'] ||= nil
112
+ if doc['source']
113
+ result_params[:charset] = doc['source']['encoding'] ||= nil
114
+ end
115
+
116
+ result_params[:validity] = !doc['messages'].any? { |msg| msg['type'] =~ /^error$/i }
117
+
118
+ results = Results.new(result_params)
119
+
120
+ doc['messages'].each do |msg|
121
+ if msg['type'] =~ /^error$/i
122
+ msg_type = :error
123
+ elsif msg['subType'] =~ /^warning$/
124
+ msg_type = :warning
125
+ else
126
+ next
127
+ # TODO: should throw exceptions here
128
+ end
129
+
130
+ message_params = {
131
+ :line => msg['firstLine'],
132
+ :col => msg['firstColumn'],
133
+ :message => msg['message'],
134
+ :source => msg['extract']
135
+ }
136
+
137
+ results.add_message(msg_type, message_params)
138
+ end
139
+
140
+ return results
141
+
142
+ rescue Exception => e
143
+ handle_exception e
144
+ end
145
+ end
146
+ end
@@ -9,7 +9,11 @@ module W3CValidators
9
9
  @doctype = options[:doctype]
10
10
  @css_level = options[:css_level]
11
11
  @charset = options[:charset]
12
- @validity = options[:validity]
12
+ if options[:validity].kind_of?(String)
13
+ @validity = options[:validity].downcase.strip == 'true'
14
+ else
15
+ @validity = options[:validity]
16
+ end
13
17
  @debug_messages = {}
14
18
  end
15
19
 
@@ -23,7 +27,7 @@ module W3CValidators
23
27
  end
24
28
 
25
29
  def add_warning(params = {})
26
- add_message(:warnings, params)
30
+ add_message(:warning, params)
27
31
  end
28
32
 
29
33
  def add_debug_message(key, val)
@@ -38,7 +42,7 @@ module W3CValidators
38
42
  end
39
43
 
40
44
  def is_valid?
41
- @validity && @validity.downcase.strip == 'true'
45
+ @validity
42
46
  end
43
47
 
44
48
  # Returns an array of Message objects.
@@ -11,8 +11,8 @@ require 'w3c_validators/message'
11
11
  module W3CValidators
12
12
  # Base class for MarkupValidator and FeedValidator.
13
13
  class Validator
14
- USER_AGENT = 'Ruby W3C Validators/0.9 (http://code.dunae.ca/w3c_validators/)'
15
- VERSION = '0.9'
14
+ VERSION = '1.0.2'
15
+ USER_AGENT = "Ruby W3C Validators/#{Validator::VERSION} (http://code.dunae.ca/w3c_validators/)"
16
16
  HEAD_STATUS_HEADER = 'X-W3C-Validator-Status'
17
17
  HEAD_ERROR_COUNT_HEADER = 'X-W3C-Validator-Errors'
18
18
  SOAP_OUTPUT_PARAM = 'soap12'
@@ -20,8 +20,17 @@ module W3CValidators
20
20
  attr_reader :results, :validator_uri
21
21
 
22
22
  # Create a new instance of the Validator.
23
+ #
24
+ # +options+ Hash can optionally include
25
+ # - +proxy_host+
26
+ # - +proxy_port+
27
+ # - +proxy_user+
28
+ # - +proxy_pass+
23
29
  def initialize(options = {})
24
- @options = options
30
+ @options = {:proxy_host => nil,
31
+ :proxy_port => nil,
32
+ :proxy_user => nil,
33
+ :proxy_pass => nil}.merge(options)
25
34
  end
26
35
 
27
36
  protected
@@ -34,7 +43,11 @@ module W3CValidators
34
43
  response = nil
35
44
  results = nil
36
45
 
37
- Net::HTTP.start(@validator_uri.host, @validator_uri.port) do |http|
46
+ r = Net::HTTP::Proxy(@options[:proxy_host],
47
+ @options[:proxy_port],
48
+ @options[:proxy_user],
49
+ @options[:proxy_pass]).start(@validator_uri.host, @validator_uri.port) do |http|
50
+
38
51
  case request_mode
39
52
  when :head
40
53
  # perform a HEAD request
@@ -63,21 +76,37 @@ module W3CValidators
63
76
 
64
77
  def create_multipart_data(options) # :nodoc:
65
78
  boundary = '349832898984244898448024464570528145'
66
- params = []
79
+
80
+ # added 2008-03-12: HTML5 validator expects 'file' and 'content' to be the last fields so
81
+ # we process those params separately
82
+ last_params = []
83
+
84
+ # added 2008-03-12: HTML5 validator expects 'file' instead of 'uploaded_file'
85
+ if options[:file] and !options[:uploaded_file]
86
+ options[:uploaded_file] = options[:file]
87
+ end
88
+
67
89
  if options[:uploaded_file]
68
90
  filename = options[:file_path] ||= 'temp.html'
69
91
  content = options[:uploaded_file]
70
- params << "Content-Disposition: form-data; name=\"uploaded_file\"; filename=\"#{filename}\"\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "#{content}\r\n"
92
+ last_params << "Content-Disposition: form-data; name=\"uploaded_file\"; filename=\"#{filename}\"\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "#{content}\r\n"
71
93
  options.delete(:uploaded_file)
72
94
  options.delete(:file_path)
73
95
  end
96
+
97
+ if options[:content]
98
+ last_params << "Content-Disposition: form-data; name=\"#{CGI::escape('content')}\"\r\n" + "\r\n" + "#{options[:content]}\r\n"
99
+ end
74
100
 
101
+ misc_params = []
75
102
  options.each do |key, value|
76
103
  if value
77
- params << "Content-Disposition: form-data; name=\"#{CGI::escape(key.to_s)}\"\r\n" + "\r\n" + "#{value}\r\n"
104
+ misc_params << "Content-Disposition: form-data; name=\"#{CGI::escape(key.to_s)}\"\r\n" + "\r\n" + "#{value}\r\n"
78
105
  end
79
106
  end
80
107
 
108
+ params = misc_params + last_params
109
+
81
110
  multipart_query = params.collect {|p| '--' + boundary + "\r\n" + p}.join('') + "--" + boundary + "--\r\n"
82
111
 
83
112
  [multipart_query, boundary]
@@ -94,10 +123,7 @@ module W3CValidators
94
123
  end
95
124
 
96
125
  def read_local_file(file_path) # :nodoc:
97
- fh = File.new(file_path, 'r+')
98
- src = fh.read
99
- fh.close
100
- src
126
+ IO.read(file_path)
101
127
  end
102
128
 
103
129
  private
@@ -24,18 +24,18 @@ class CSSValidatorTests < Test::Unit::TestCase
24
24
  def test_validating_file
25
25
  file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_css.css')
26
26
  r = @v.validate_file(file_path)
27
- assert_equal 1, r.errors.length
27
+ assert_errors r, 1
28
28
  end
29
29
 
30
30
  def test_validating_uri
31
31
  @v.set_profile!(:svgbasic)
32
32
  r = @v.validate_text(@invalid_fragment)
33
- assert_equal 1, r.errors.length
33
+ assert_errors r, 1
34
34
  end
35
35
 
36
36
  def test_validating_text
37
37
  r = @v.validate_text(@invalid_fragment)
38
- assert_equal 1, r.errors.length
38
+ assert_errors r, 1
39
39
  end
40
40
 
41
41
  def test_validating_text_via_file
@@ -43,7 +43,7 @@ class CSSValidatorTests < Test::Unit::TestCase
43
43
  fh = File.new(file_path, 'r+')
44
44
  r = @v.validate_file(fh)
45
45
  fh.close
46
- assert_equal 1, r.errors.length
46
+ assert_errors r, 1
47
47
  end
48
48
 
49
49
 
@@ -10,14 +10,14 @@ class FeedValidatorTests < Test::Unit::TestCase
10
10
 
11
11
  def test_validating_uri_with_soap
12
12
  r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_feed.xml')
13
- assert_equal 1, r.errors.length
14
- assert_equal 1, r.warnings.length
13
+ assert_errors r, 1
14
+ assert_warnings r, 1
15
15
  end
16
16
 
17
17
  def test_validating_file
18
18
  file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
19
19
  r = @v.validate_file(file_path)
20
- assert_equal 1, r.errors.length
20
+ assert_errors r, 1
21
21
  end
22
22
 
23
23
  def test_validating_text
@@ -53,7 +53,7 @@ class FeedValidatorTests < Test::Unit::TestCase
53
53
  fh = File.new(file_path, 'r+')
54
54
  r = @v.validate_file(fh)
55
55
  fh.close
56
- assert_equal 1, r.errors.length
56
+ assert_errors r, 1
57
57
  end
58
58
 
59
59
 
data/test/test_helper.rb CHANGED
@@ -4,3 +4,37 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../lib/'))
4
4
  require 'rubygems'
5
5
  require 'test/unit'
6
6
  require 'w3c_validators'
7
+
8
+ class Test::Unit::TestCase
9
+
10
+ def assert_no_errors(response)
11
+ assert response.errors.empty?, response.errors.map { |e| e.to_s }.join('. ')
12
+ end
13
+
14
+ def assert_no_warnings(response)
15
+ assert response.warnings.empty?, response.warnings.map { |w| w.to_s }.join('. ')
16
+ end
17
+
18
+ def assert_errors(response, quantity = nil)
19
+ case quantity
20
+ when 0
21
+ assert_no_errors response
22
+ when nil
23
+ assert response.errors.any?
24
+ else
25
+ assert_equal quantity, response.errors.length
26
+ end
27
+ end
28
+
29
+ def assert_warnings(response, quantity = nil)
30
+ case quantity
31
+ when 0
32
+ assert_no_warnings response
33
+ when nil
34
+ assert response.warnings.any?
35
+ else
36
+ assert_equal quantity, response.warnings.length
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ # Test cases for the HTML5Validator.
4
+ class HTML5ValidatorTests < Test::Unit::TestCase
5
+ include W3CValidators
6
+ def setup
7
+ @v = NuValidator.new
8
+ sleep 1
9
+ end
10
+
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?
18
+ end
19
+
20
+ def test_validating_uri
21
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_html5.html')
22
+ assert_errors r, 1
23
+ assert_warnings r, 1
24
+ assert !r.is_valid?
25
+ end
26
+
27
+ def test_validating_file
28
+ file = File.dirname(__FILE__) + '/fixtures/invalid_html5.html'
29
+ r = @v.validate_file(file)
30
+ assert_errors r, 1
31
+ end
32
+
33
+ def test_validating_text
34
+ valid_fragment = <<-EOV
35
+ <!DOCTYPE html>
36
+ <html lang="en-ca">
37
+ <head>
38
+ <title>HTML 5 Example</title>
39
+ </head>
40
+ <body>
41
+ <!-- should have one error (missing </section>) -->
42
+ <p>This is a sample HTML 5 document.</p>
43
+ <section>
44
+ <h1>Example of paragraphs</h1>
45
+ This is the <em>first</em> paragraph in this example.
46
+ <p>This is the second.</p>
47
+ <p>Test<br>test</p>
48
+ </body>
49
+ </html>
50
+ EOV
51
+
52
+ r = @v.validate_text(valid_fragment)
53
+ assert_errors r, 1
54
+ end
55
+
56
+ #def test_validating_text_via_file
57
+ # fh = File.new(File.dirname(__FILE__) + '/fixtures/invalid_html5.html', 'r+')
58
+ # r = @v.validate_file(fh)
59
+ # fh.close
60
+ # assert_equal 1, r.errors.length
61
+ #end
62
+
63
+
64
+ end
@@ -34,14 +34,13 @@ class MarkupValidatorTests < Test::Unit::TestCase
34
34
 
35
35
  def test_validating_uri_with_head_request
36
36
  r = @v.validate_uri_quickly('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
37
- assert_equal 1, r.errors.length
38
- assert_equal 0, r.warnings.length
37
+ assert_errors r, 1
39
38
  end
40
39
 
41
40
  def test_validating_uri_with_soap
42
41
  r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_markup.html')
43
- assert_equal 1, r.errors.length
44
- assert_equal 0, r.warnings.length
42
+ assert_errors r, 1
43
+ assert_no_warnings r
45
44
  end
46
45
 
47
46
  def test_debugging_uri
@@ -53,7 +52,7 @@ class MarkupValidatorTests < Test::Unit::TestCase
53
52
  def test_validating_file
54
53
  file = File.dirname(__FILE__) + '/fixtures/invalid_markup.html'
55
54
  r = @v.validate_file(file)
56
- assert_equal 1, r.errors.length
55
+ assert_errors r, 1
57
56
 
58
57
  assert r.uri =~ /fixtures\/invalid_markup\.html$/
59
58
  end
@@ -68,15 +67,15 @@ class MarkupValidatorTests < Test::Unit::TestCase
68
67
  EOV
69
68
 
70
69
  r = @v.validate_text(valid_fragment)
71
- assert_equal 0, r.errors.length
72
- assert_equal 0, r.warnings.length
70
+ assert_no_errors r
71
+ assert_no_warnings r
73
72
  end
74
73
 
75
74
  def test_validating_text_via_file
76
75
  fh = File.new(File.dirname(__FILE__) + '/fixtures/invalid_markup.html', 'r+')
77
76
  r = @v.validate_file(fh)
78
77
  fh.close
79
- assert_equal 1, r.errors.length
78
+ assert_errors r, 1
80
79
  end
81
80
 
82
81
 
@@ -85,8 +84,8 @@ class MarkupValidatorTests < Test::Unit::TestCase
85
84
  assert_nothing_raised do
86
85
  r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid_encoding.html')
87
86
  assert !r.is_valid?
88
- assert_equal 1, r.errors.length
89
- assert_equal [], r.warnings
87
+ assert_errors r, 1
88
+ assert_no_warnings r
90
89
  end
91
90
  end
92
91
 
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ require 'webrick'
4
+ require 'webrick/httpproxy'
5
+
6
+ # Test cases for the ProxyTests.
7
+ class ProxyTests < Test::Unit::TestCase
8
+ include W3CValidators
9
+
10
+ def setup
11
+ @ps = WEBrick::HTTPProxyServer.new(:Port => 9999, :ServerType => Thread, :RequestCallback => Proc.new{|req,res| puts req.request_line, req.raw_header})
12
+
13
+ ['TERM', 'INT'].each do |signal|
14
+ trap(signal){ @ps.shutdown }
15
+ end
16
+
17
+ @ps.start
18
+
19
+ @v = MarkupValidator.new({:proxy_server => 'localhost', :proxy_port => 9999})
20
+ sleep 1
21
+ end
22
+
23
+
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
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: w3c_validators
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.3
7
- date: 2008-03-11 00:00:00 -07:00
6
+ version: 1.0.2
7
+ date: 2009-11-20 00:00:00 -08:00
8
8
  summary: Wrapper for the World Wide Web Consortium's online validation services.
9
9
  require_paths:
10
10
  - lib
11
- email:
11
+ email: code@dunae.ca
12
12
  homepage: http://code.dunae.ca/w3c_validators
13
13
  rubyforge_project:
14
14
  description: W3C Validators is a Ruby wrapper for the World Wide Web Consortium's online validation services.
@@ -30,29 +30,36 @@ authors:
30
30
  - Alex Dunae
31
31
  files:
32
32
  - lib/w3c_validators
33
+ - lib/w3c_validators.rb
33
34
  - lib/w3c_validators/constants.rb
34
35
  - lib/w3c_validators/css_validator.rb
35
36
  - lib/w3c_validators/exceptions.rb
36
37
  - lib/w3c_validators/feed_validator.rb
37
38
  - lib/w3c_validators/markup_validator.rb
38
39
  - lib/w3c_validators/message.rb
40
+ - lib/w3c_validators/nu_validator.rb
39
41
  - lib/w3c_validators/results.rb
40
42
  - lib/w3c_validators/validator.rb
41
- - lib/w3c_validators.rb
42
- - README
43
+ - README.rdoc
44
+ - CHANGELOG
43
45
  - LICENSE
44
46
  test_files:
45
47
  - test/test_css_validator.rb
46
48
  - test/test_exceptions.rb
47
49
  - test/test_feed_validator.rb
48
50
  - test/test_helper.rb
51
+ - test/test_html5_validator.rb
49
52
  - test/test_markup_validator.rb
53
+ - test/test_proxy.rb
50
54
  rdoc_options:
51
55
  - --all
52
56
  - --inline-source
53
57
  - --line-numbers
58
+ - --charset
59
+ - utf-8
54
60
  extra_rdoc_files:
55
- - README
61
+ - README.rdoc
62
+ - CHANGELOG
56
63
  - LICENSE
57
64
  executables: []
58
65