w3c_validators 0.9.2 → 0.9.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.
data/README CHANGED
@@ -18,7 +18,7 @@ W3CValidators::CSSValidator.
18
18
  Each validator has offers three different validation methods.
19
19
 
20
20
  * +validate_text+ methods take a string
21
- * +validate_file+ methods take a path to a file
21
+ * +validate_file+ methods take a path to a file or an IO object
22
22
  * +validate_uri+ methods take a published URL
23
23
 
24
24
  In addition, the W3CValidators::MarkupValidator has a validate_uri_quickly method, which
@@ -114,5 +114,7 @@ Documentation and the source code are available at http://code.dunae.ca/w3c_vali
114
114
 
115
115
  Written by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007.
116
116
 
117
- Thanks to Ryan King (http://theryanking.com/) for creating the 0.9.1 update.
117
+ Thanks to Ryan King (http://theryanking.com/) for creating the 0.9.2 update.
118
+
119
+ Thanks to Ryan King (http://theryanking.com/) and Jonathan Julian for creating the 0.9.3 update.
118
120
 
@@ -64,11 +64,16 @@ module W3CValidators
64
64
 
65
65
  # Validate the CSS of a local file.
66
66
  #
67
- # +file_path+ must be the fully-expanded path to the file.
67
+ # +file_path+ may be either the fully-expanded path to the file or
68
+ # an IO object (like File).
68
69
  #
69
70
  # Returns W3CValidators::Results.
70
71
  def validate_file(file_path)
71
- src = read_local_file(file_path)
72
+ if file_path.respond_to? :read
73
+ src = file_path.read
74
+ else
75
+ src = read_local_file(file_path)
76
+ end
72
77
  return validate_text(src)
73
78
  end
74
79
 
@@ -76,10 +81,8 @@ module W3CValidators
76
81
  protected
77
82
  def validate(options) # :nodoc:
78
83
  options = get_request_options(options)
79
- #puts options.inspect
80
84
  response = send_request(options, :get)
81
85
  @results = parse_soap_response(response.body)
82
- #puts response.body
83
86
  @results
84
87
  end
85
88
 
@@ -33,11 +33,16 @@ module W3CValidators
33
33
 
34
34
  # Validate a local feed file.
35
35
  #
36
- # +file_path+ must be the fully-expanded path to the file.
36
+ # +file_path+ may be either the fully-expanded path to the file or
37
+ # an IO object (like File).
37
38
  #
38
39
  # Returns W3CValidators::Results.
39
40
  def validate_file(file_path)
40
- src = read_local_file(file_path)
41
+ if file_path.respond_to? :read
42
+ src = file_path.read
43
+ else
44
+ src = read_local_file(file_path)
45
+ end
41
46
  return validate_text(src)
42
47
  end
43
48
 
@@ -101,12 +101,18 @@ module W3CValidators
101
101
 
102
102
  # Validate the markup of a local file.
103
103
  #
104
- # +file_path+ must be the fully-expanded path to the file.
104
+ # +file_path+ may be either the fully-expanded path to the file or
105
+ # an IO object (like File).
105
106
  #
106
107
  # Returns W3CValidators::Results.
107
108
  def validate_file(file_path)
108
- src = read_local_file(file_path)
109
- return validate({:uploaded_file => src}, false)
109
+ if file_path.respond_to? :read
110
+ src = file_path.read
111
+ else
112
+ src = read_local_file(file_path)
113
+ end
114
+
115
+ return validate({:uploaded_file => src, :file_path => file_path}, false)
110
116
  end
111
117
 
112
118
  protected
@@ -38,5 +38,14 @@ class CSSValidatorTests < Test::Unit::TestCase
38
38
  assert_equal 1, r.errors.length
39
39
  end
40
40
 
41
+ def test_validating_text_via_file
42
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_css.css')
43
+ fh = File.new(file_path, 'r+')
44
+ r = @v.validate_file(fh)
45
+ fh.close
46
+ assert_equal 1, r.errors.length
47
+ end
48
+
49
+
41
50
 
42
51
  end
@@ -47,5 +47,15 @@ class FeedValidatorTests < Test::Unit::TestCase
47
47
  assert_equal 1, r.errors.length
48
48
  end
49
49
 
50
+
51
+ def test_validating_text_via_file
52
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
53
+ fh = File.new(file_path, 'r+')
54
+ r = @v.validate_file(fh)
55
+ fh.close
56
+ assert_equal 1, r.errors.length
57
+ end
58
+
59
+
50
60
 
51
61
  end
@@ -54,6 +54,8 @@ class MarkupValidatorTests < Test::Unit::TestCase
54
54
  file = File.dirname(__FILE__) + '/fixtures/invalid_markup.html'
55
55
  r = @v.validate_file(file)
56
56
  assert_equal 1, r.errors.length
57
+
58
+ assert r.uri =~ /fixtures\/invalid_markup\.html$/
57
59
  end
58
60
 
59
61
  def test_validating_text
@@ -70,6 +72,14 @@ class MarkupValidatorTests < Test::Unit::TestCase
70
72
  assert_equal 0, r.warnings.length
71
73
  end
72
74
 
75
+ def test_validating_text_via_file
76
+ fh = File.new(File.dirname(__FILE__) + '/fixtures/invalid_markup.html', 'r+')
77
+ r = @v.validate_file(fh)
78
+ fh.close
79
+ assert_equal 1, r.errors.length
80
+ end
81
+
82
+
73
83
  def test_validator_abort
74
84
  @v.set_debug!
75
85
  assert_nothing_raised do
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: w3c_validators
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.2
7
- date: 2008-02-08 00:00:00 -08:00
6
+ version: 0.9.3
7
+ date: 2008-03-11 00:00:00 -07:00
8
8
  summary: Wrapper for the World Wide Web Consortium's online validation services.
9
9
  require_paths:
10
10
  - lib