be_valid_asset 1.2.0 → 1.2.1
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/lib/be_valid_asset/be_valid_markup.rb +76 -0
- metadata +4 -3
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'cgi'
|
4
|
+
require 'digest/md5'
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
module BeValidAsset
|
8
|
+
|
9
|
+
Configuration.markup_validator_host = 'validator.w3.org'
|
10
|
+
Configuration.markup_validator_path = '/check'
|
11
|
+
|
12
|
+
class BeValidMarkup < BeValidBase
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@fragment = options[:fragment]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Assert that markup (html/xhtml) is valid according the W3C validator web service.
|
19
|
+
|
20
|
+
def matches?(fragment)
|
21
|
+
|
22
|
+
if fragment.respond_to? :source
|
23
|
+
fragment = fragment.source.to_s
|
24
|
+
elsif fragment.respond_to? :body
|
25
|
+
fragment = fragment.body.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
if fragment.empty?
|
29
|
+
@message = "Response was blank (maybe a missing integrate_views)"
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
|
33
|
+
query_params = { :fragment => fragment }
|
34
|
+
if @fragment
|
35
|
+
query_params[:prefill] = '1'
|
36
|
+
query_params[:prefill_doctype] = 'xhtml10'
|
37
|
+
end
|
38
|
+
|
39
|
+
return validate(query_params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def description
|
43
|
+
"be valid markup"
|
44
|
+
end
|
45
|
+
|
46
|
+
def failure_message
|
47
|
+
" expected markup to be valid, but validation produced these errors:\n#{@message}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def negative_failure_message
|
51
|
+
" expected to not be valid, but was (missing validation?)"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def validator_host
|
57
|
+
Configuration.markup_validator_host
|
58
|
+
end
|
59
|
+
|
60
|
+
def validator_path
|
61
|
+
Configuration.markup_validator_path
|
62
|
+
end
|
63
|
+
|
64
|
+
def error_line_prefix
|
65
|
+
'Invalid markup'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def be_valid_markup
|
70
|
+
BeValidMarkup.new
|
71
|
+
end
|
72
|
+
|
73
|
+
def be_valid_markup_fragment()
|
74
|
+
BeValidMarkup.new(:fragment => true)
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: be_valid_asset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Tomlins
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/be_valid_asset/be_valid_base.rb
|
50
50
|
- lib/be_valid_asset/be_valid_css.rb
|
51
51
|
- lib/be_valid_asset/be_valid_feed.rb
|
52
|
+
- lib/be_valid_asset/be_valid_markup.rb
|
52
53
|
- lib/be_valid_asset/be_valid_xhtml.rb
|
53
54
|
- lib/be_valid_asset.rb
|
54
55
|
- spec/be_valid_asset/be_valid_css_spec.rb
|