be_valid_asset 1.2.3 → 1.3.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +49 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/be_valid_asset.gemspec +2 -4
- data/lib/be_valid_asset/be_valid_base.rb +16 -7
- data/lib/be_valid_asset/be_valid_css.rb +6 -4
- data/lib/be_valid_asset/be_valid_feed.rb +4 -2
- data/lib/be_valid_asset/be_valid_markup.rb +13 -11
- data/lib/be_valid_asset/be_valid_xhtml.rb +3 -3
- data/lib/be_valid_asset/version.rb +1 -1
- data/spec/be_valid_asset/be_valid_css_spec.rb +66 -66
- data/spec/be_valid_asset/be_valid_feed_spec.rb +60 -60
- data/spec/be_valid_asset/be_valid_markup_spec.rb +151 -119
- data/spec/spec_helper.rb +4 -3
- metadata +12 -51
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f5e373c8a93d715175401ab7cf5957d0d25e0b2
|
4
|
+
data.tar.gz: af7fd77efaf14d9f6e7a7b66413ceedf5295dbfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 188b91cfa1a6efe8c6adbcd9e7f54bff0ee1994dbcf00c5fd60223004427a982a5bec7e64445ff400b38595dbdcf3ed95d9c24608d43d38cf6c85011c23bb50f
|
7
|
+
data.tar.gz: 45c68a7d767852433d7e452e596eacb2aba14a99f68e679b7a54252253774fcd186d177313f02b8a83faef08f9069cf5b539fc6542e4a4f30e9ad4d41ac4b656
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# 1.3.0
|
2
|
+
|
3
|
+
* Use RSpec 3 for development
|
4
|
+
* Remove RSpec 3 dep warnings at runtime, while still supporting older RSpecs
|
5
|
+
* Support ``BeValidAsset::Configuration.xxx_validator_host`` settings with a protocol
|
6
|
+
* Support ``https`` as a protocol for host config
|
7
|
+
|
8
|
+
# 1.2.3
|
9
|
+
|
10
|
+
* Use Bundler to manage gem
|
11
|
+
* Allow for markup to be modified prior to validation (e.g. to remove attributes you know won't pass)
|
12
|
+
|
13
|
+
# 1.2.2
|
14
|
+
|
15
|
+
* Turn off CSS validation warnings about vendor extensions
|
16
|
+
* Fix gemspec
|
17
|
+
|
18
|
+
# 1.2.1
|
19
|
+
|
20
|
+
* Is broken, use 1.2.2
|
21
|
+
* Deprecate ``be_valid_xhtml`` in favour of ``be_valid_markup``
|
22
|
+
* Use rspec 2 in development
|
23
|
+
|
24
|
+
# 1.1.2
|
25
|
+
|
26
|
+
* Fix because validator response html is different
|
27
|
+
|
28
|
+
# 1.1.1
|
29
|
+
|
30
|
+
* Option for displaying context around failed validation
|
31
|
+
* Handle empty CSS without getting a 500 from validator
|
32
|
+
|
33
|
+
# 1.1.0
|
34
|
+
|
35
|
+
* Added ``be_valid_feed`` for rss/atom by talking to w3c feed validator
|
36
|
+
|
37
|
+
# 1.0.1
|
38
|
+
|
39
|
+
* Allow ``be_valid_css`` to take a response object or a string (like ``be_valid_xhtml``).
|
40
|
+
|
41
|
+
# 1.0.0
|
42
|
+
|
43
|
+
* Allow to work with Merb
|
44
|
+
* Add rspec dependency
|
45
|
+
|
46
|
+
# 0.9.0
|
47
|
+
|
48
|
+
* Hello!
|
49
|
+
* Provides ``be_valid_css`` and ``be_valid_xhtml`` matchers for rspec to talk to w3c validators.
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/be_valid_asset.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'be_valid_asset/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "be_valid_asset"
|
8
8
|
gem.version = BeValidAsset::VERSION
|
9
|
-
gem.authors = ["Alex Tomlins", "Attila Gyorffy", "Ben Brinckerhoff", "Jolyon Pawlyn", "Sebastian de Castelberg"]
|
9
|
+
gem.authors = ["Alex Tomlins", "Attila Gyorffy", "Ben Brinckerhoff", "Jolyon Pawlyn", "Sebastian de Castelberg", "Zubair Chaudary", "Murray Steele"]
|
10
10
|
gem.email = ["github@unboxedconsulting.com"]
|
11
11
|
gem.description = %q{Provides be_valid_markup, be_valid_css and be_valid_feed matchers for RSpec controller and view tests.}
|
12
12
|
gem.summary = %q{Markup and asset validation for RSpec}
|
@@ -18,7 +18,5 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.
|
22
|
-
gem.add_development_dependency('rake')
|
23
|
-
gem.add_development_dependency('rspec', '>= 2.0')
|
21
|
+
gem.add_runtime_dependency('rspec')
|
24
22
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
module BeValidAsset
|
3
3
|
|
4
|
+
DontRunValidAssetSpecs = (defined? RSpec::Core::Pending::SkipDeclaredInExample) ? RSpec::Core::Pending::SkipDeclaredInExample : RSpec::Core::Pending::PendingDeclaredInExample
|
5
|
+
|
4
6
|
# Abstract base class for other matchers
|
5
7
|
class BeValidBase
|
6
8
|
|
@@ -8,7 +10,7 @@ module BeValidAsset
|
|
8
10
|
|
9
11
|
def check_net_enabled
|
10
12
|
if ENV["NONET"] == 'true'
|
11
|
-
raise
|
13
|
+
raise BeValidAsset::DontRunValidAssetSpecs.new('Network tests disabled')
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -84,14 +86,21 @@ module BeValidAsset
|
|
84
86
|
ret << "\r\n--#{boundary}--\r\n"
|
85
87
|
ret
|
86
88
|
end
|
87
|
-
|
89
|
+
|
88
90
|
def http_start(host)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Net::HTTP.
|
91
|
+
uri = URI.parse(host)
|
92
|
+
uri = URI.parse("http://#{host}") if uri.scheme.nil?
|
93
|
+
if uri.scheme == 'https'
|
94
|
+
http = Net::HTTP.new uri.host, uri.port
|
95
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
96
|
+
http.use_ssl = true
|
97
|
+
http.start
|
98
|
+
elsif ENV['http_proxy']
|
99
|
+
proxy_uri = URI.parse(ENV['http_proxy'])
|
100
|
+
proxy_user, proxy_pass = proxy_uri.userinfo.split(/:/) if proxy_uri.userinfo
|
101
|
+
Net::HTTP.start(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
|
93
102
|
else
|
94
|
-
Net::HTTP.start(host)
|
103
|
+
Net::HTTP.start(uri.host, uri.port)
|
95
104
|
end
|
96
105
|
end
|
97
106
|
end
|
@@ -29,13 +29,15 @@ module BeValidAsset
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def failure_message
|
32
|
-
|
32
|
+
" expected css to be valid, but validation produced these errors:\n#{@message}"
|
33
33
|
end
|
34
|
-
|
35
|
-
def
|
34
|
+
|
35
|
+
def failure_message_when_negated
|
36
36
|
" expected to not be valid, but was (missing validation?)"
|
37
37
|
end
|
38
|
-
|
38
|
+
# continue to support Rspec < 3
|
39
|
+
alias :negative_failure_message :failure_message_when_negated
|
40
|
+
|
39
41
|
private
|
40
42
|
|
41
43
|
def validator_host
|
@@ -25,12 +25,14 @@ module BeValidAsset
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def failure_message
|
28
|
-
|
28
|
+
" expected feed to be valid, but validation produced these errors:\n#{@message}"
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def failure_message_when_negated
|
32
32
|
" expected to not be valid, but was (missing validation?)"
|
33
33
|
end
|
34
|
+
# continue to support Rspec < 3
|
35
|
+
alias :negative_failure_message :failure_message_when_negated
|
34
36
|
|
35
37
|
private
|
36
38
|
|
@@ -12,13 +12,13 @@ module BeValidAsset
|
|
12
12
|
Configuration.markup_modifiers = []
|
13
13
|
|
14
14
|
class BeValidMarkup < BeValidBase
|
15
|
-
|
15
|
+
|
16
16
|
def initialize(options = {})
|
17
17
|
@fragment = options[:fragment]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# Assert that markup (html/xhtml) is valid according the W3C validator web service.
|
21
|
-
|
21
|
+
|
22
22
|
def matches?(fragment)
|
23
23
|
|
24
24
|
if fragment.respond_to? :source
|
@@ -39,22 +39,24 @@ module BeValidAsset
|
|
39
39
|
query_params[:prefill] = '1'
|
40
40
|
query_params[:prefill_doctype] = 'xhtml10'
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
return validate(query_params)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def description
|
47
47
|
"be valid markup"
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def failure_message
|
51
|
-
|
51
|
+
" expected markup to be valid, but validation produced these errors:\n#{@message}"
|
52
52
|
end
|
53
|
-
|
54
|
-
def
|
53
|
+
|
54
|
+
def failure_message_when_negated
|
55
55
|
" expected to not be valid, but was (missing validation?)"
|
56
56
|
end
|
57
|
-
|
57
|
+
# continue to support Rspec < 3
|
58
|
+
alias :negative_failure_message :failure_message_when_negated
|
59
|
+
|
58
60
|
private
|
59
61
|
|
60
62
|
def apply_modifiers_to_fragment(fragment)
|
@@ -92,7 +94,7 @@ module BeValidAsset
|
|
92
94
|
def be_valid_markup
|
93
95
|
BeValidMarkup.new
|
94
96
|
end
|
95
|
-
|
97
|
+
|
96
98
|
def be_valid_markup_fragment()
|
97
99
|
BeValidMarkup.new(:fragment => true)
|
98
100
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module BeValidAsset
|
2
|
-
|
2
|
+
|
3
3
|
class BeValidXhtml < BeValidMarkup
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(options = {})
|
6
6
|
super
|
7
7
|
Kernel.warn('[DEPRECATION] - `be_valid_xhtml` is deprecated, use `be_valid_markup` instead')
|
@@ -12,7 +12,7 @@ module BeValidAsset
|
|
12
12
|
BeValidXhtml.new
|
13
13
|
end
|
14
14
|
alias :be_valid_html :be_valid_xhtml
|
15
|
-
|
15
|
+
|
16
16
|
def be_valid_xhtml_fragment()
|
17
17
|
BeValidXhtml.new(:fragment => true)
|
18
18
|
end
|
@@ -4,55 +4,55 @@ unless defined?(SpecFailed)
|
|
4
4
|
SpecFailed = RSpec::Expectations::ExpectationNotMetError
|
5
5
|
end
|
6
6
|
|
7
|
-
describe 'be_valid_css' do
|
8
|
-
|
7
|
+
RSpec.describe 'be_valid_css' do
|
8
|
+
|
9
9
|
describe "without caching" do
|
10
10
|
it "should validate a valid string" do
|
11
11
|
css = get_file('valid.css')
|
12
|
-
css.
|
12
|
+
expect(css).to be_valid_css
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should validate an empty string" do
|
16
|
-
''.
|
16
|
+
expect('').to be_valid_css
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should validate a valid response" do
|
20
20
|
response = MockResponse.new(get_file('valid.css'))
|
21
|
-
response.
|
21
|
+
expect(response).to be_valid_css
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should validate if body is not a string but can be converted to valid string" do
|
25
|
-
response = MockResponse.new(
|
26
|
-
response.
|
25
|
+
response = MockResponse.new(double("CSS", :to_s => get_file('valid.css')))
|
26
|
+
expect(response).to be_valid_css
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should not validate an invalid string" do
|
30
30
|
css = get_file('invalid.css')
|
31
|
-
|
32
|
-
css.
|
33
|
-
}.
|
34
|
-
e.message.
|
35
|
-
e.message.
|
31
|
+
expect {
|
32
|
+
expect(css).to be_valid_css
|
33
|
+
}.to raise_error(SpecFailed) { |e|
|
34
|
+
expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
|
35
|
+
expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
|
36
36
|
}
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should not validate an invalid response" do
|
40
40
|
response = MockResponse.new(get_file('invalid.css'))
|
41
|
-
|
42
|
-
response.
|
43
|
-
}.
|
44
|
-
e.message.
|
45
|
-
e.message.
|
41
|
+
expect {
|
42
|
+
expect(response).to be_valid_css
|
43
|
+
}.to raise_error(SpecFailed) { |e|
|
44
|
+
expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
|
45
|
+
expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
|
46
46
|
}
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should display invalid content when requested" do
|
50
50
|
BeValidAsset::Configuration.display_invalid_content = true
|
51
51
|
css = get_file('invalid.css')
|
52
|
-
|
53
|
-
css.
|
54
|
-
}.
|
55
|
-
e.message.
|
52
|
+
expect {
|
53
|
+
expect(css).to be_valid_css
|
54
|
+
}.to raise_error(SpecFailed) { |e|
|
55
|
+
expect(e.message).to match(/wibble:0;/)
|
56
56
|
}
|
57
57
|
BeValidAsset::Configuration.display_invalid_content = false
|
58
58
|
end
|
@@ -62,21 +62,21 @@ describe 'be_valid_css' do
|
|
62
62
|
|
63
63
|
r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
|
64
64
|
h = Net::HTTP.new(BeValidAsset::Configuration.css_validator_host)
|
65
|
-
h.
|
66
|
-
Net::HTTP.
|
65
|
+
allow(h).to receive(:post2).and_return(r)
|
66
|
+
allow(Net::HTTP).to receive(:start).and_return(h)
|
67
67
|
|
68
|
-
|
69
|
-
css.
|
70
|
-
}.
|
68
|
+
expect {
|
69
|
+
expect(css).to be_valid_css
|
70
|
+
}.to raise_error
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should mark test as pending if ENV['NONET'] is true" do
|
74
74
|
ENV['NONET'] = 'true'
|
75
75
|
|
76
76
|
css = get_file('valid.css')
|
77
|
-
|
78
|
-
css.
|
79
|
-
}.
|
77
|
+
expect {
|
78
|
+
expect(css).to be_valid_css
|
79
|
+
}.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
|
80
80
|
|
81
81
|
ENV.delete('NONET')
|
82
82
|
end
|
@@ -90,13 +90,13 @@ describe 'be_valid_css' do
|
|
90
90
|
(1..3).each do |test_version|
|
91
91
|
if test_version < version
|
92
92
|
it "should not be valid css#{test_version.to_s}" do
|
93
|
-
|
94
|
-
@css.
|
95
|
-
|
93
|
+
expect {
|
94
|
+
expect(@css).to send("be_valid_css#{test_version.to_s}".to_sym)
|
95
|
+
}.to raise_error(SpecFailed)
|
96
96
|
end
|
97
97
|
else
|
98
98
|
it "should be valid css#{test_version.to_s}" do
|
99
|
-
@css.
|
99
|
+
expect(@css).to send("be_valid_css#{test_version.to_s}".to_sym)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -104,7 +104,7 @@ describe 'be_valid_css' do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
describe "with caching" do
|
109
109
|
before(:each) do
|
110
110
|
BeValidAsset::Configuration.enable_caching = true
|
@@ -117,40 +117,40 @@ describe 'be_valid_css' do
|
|
117
117
|
it "should validate valid css and cache the response" do
|
118
118
|
css = get_file('valid.css')
|
119
119
|
count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
|
120
|
-
css.
|
121
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
120
|
+
expect(css).to be_valid_css
|
121
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should validate valid css using the cached response" do
|
125
125
|
css = get_file('valid.css')
|
126
|
-
css.
|
126
|
+
expect(css).to be_valid_css
|
127
127
|
|
128
|
-
Net::HTTP.
|
129
|
-
css.
|
128
|
+
expect(Net::HTTP).not_to receive(:start)
|
129
|
+
expect(css).to be_valid_css
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should not validate invalid css, but still cache the response" do
|
133
133
|
css = get_file('invalid.css')
|
134
134
|
count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
|
135
|
-
|
136
|
-
css.
|
137
|
-
}.
|
138
|
-
e.message.
|
139
|
-
e.message.
|
135
|
+
expect {
|
136
|
+
expect(css).to be_valid_css
|
137
|
+
}.to raise_error(SpecFailed) { |e|
|
138
|
+
expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
|
139
|
+
expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
|
140
140
|
}
|
141
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
141
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should not validate invalid css, but use the cached response" do
|
145
145
|
css = get_file('invalid.css')
|
146
|
-
css.
|
147
|
-
|
148
|
-
Net::HTTP.
|
149
|
-
|
150
|
-
css.
|
151
|
-
}.
|
152
|
-
e.message.
|
153
|
-
e.message.
|
146
|
+
expect(css).not_to be_valid_css
|
147
|
+
|
148
|
+
expect(Net::HTTP).not_to receive(:start)
|
149
|
+
expect {
|
150
|
+
expect(css).to be_valid_css
|
151
|
+
}.to raise_error(SpecFailed) { |e|
|
152
|
+
expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
|
153
|
+
expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
|
154
154
|
}
|
155
155
|
end
|
156
156
|
|
@@ -160,23 +160,23 @@ describe 'be_valid_css' do
|
|
160
160
|
|
161
161
|
r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
|
162
162
|
h = Net::HTTP.new(BeValidAsset::Configuration.css_validator_host)
|
163
|
-
h.
|
164
|
-
Net::HTTP.
|
163
|
+
allow(h).to receive(:post2).and_return(r)
|
164
|
+
allow(Net::HTTP).to receive(:start).and_return(h)
|
165
165
|
|
166
|
-
|
167
|
-
css.
|
168
|
-
}.
|
169
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
166
|
+
expect {
|
167
|
+
expect(css).to be_valid_css
|
168
|
+
}.to raise_error
|
169
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count)
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should use the cached result (if available) when network tests disabled" do
|
173
173
|
css = get_file('valid.css')
|
174
|
-
css.
|
174
|
+
expect(css).to be_valid_css
|
175
175
|
|
176
176
|
ENV['NONET'] = 'true'
|
177
177
|
|
178
|
-
Net::HTTP.
|
179
|
-
css.
|
178
|
+
expect(Net::HTTP).not_to receive(:start)
|
179
|
+
expect(css).to be_valid_css
|
180
180
|
|
181
181
|
ENV.delete('NONET')
|
182
182
|
end
|
@@ -185,9 +185,9 @@ describe 'be_valid_css' do
|
|
185
185
|
ENV['NONET'] = 'true'
|
186
186
|
|
187
187
|
css = get_file('valid.css')
|
188
|
-
|
189
|
-
css.
|
190
|
-
}.
|
188
|
+
expect {
|
189
|
+
expect(css).to be_valid_css
|
190
|
+
}.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
|
191
191
|
|
192
192
|
ENV.delete('NONET')
|
193
193
|
end
|