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
@@ -4,61 +4,61 @@ unless defined?(SpecFailed)
|
|
4
4
|
SpecFailed = RSpec::Expectations::ExpectationNotMetError
|
5
5
|
end
|
6
6
|
|
7
|
-
describe 'be_valid_feed' do
|
7
|
+
RSpec.describe 'be_valid_feed' do
|
8
8
|
|
9
9
|
describe "without caching" do
|
10
10
|
it "should validate a valid string" do
|
11
11
|
feed = get_file('valid_feed.xml')
|
12
|
-
feed.
|
12
|
+
expect(feed).to be_valid_feed
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should work when called as be_valid_rss" do
|
16
16
|
feed = get_file('valid_feed.xml')
|
17
|
-
feed.
|
17
|
+
expect(feed).to be_valid_rss
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should work when called as be_valid_atom" do
|
21
21
|
feed = get_file('valid_feed.xml')
|
22
|
-
feed.
|
22
|
+
expect(feed).to be_valid_atom
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should validate a valid response" do
|
26
26
|
response = MockResponse.new(get_file('valid_feed.xml'))
|
27
|
-
response.
|
27
|
+
expect(response).to be_valid_feed
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should validate if body is not a string but can be converted to valid string" do
|
31
|
-
response = MockResponse.new(
|
32
|
-
response.
|
31
|
+
response = MockResponse.new(double("Feed", :to_s => get_file('valid_feed.xml')))
|
32
|
+
expect(response).to be_valid_feed
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should not validate an invalid string" do
|
36
36
|
feed = get_file('invalid_feed.xml')
|
37
|
-
|
38
|
-
feed.
|
39
|
-
}.
|
40
|
-
e.message.
|
41
|
-
e.message.
|
37
|
+
expect {
|
38
|
+
expect(feed).to be_valid_feed
|
39
|
+
}.to raise_error(SpecFailed) { |e|
|
40
|
+
expect(e.message).to match(/expected feed to be valid, but validation produced these errors/)
|
41
|
+
expect(e.message).to match(/Invalid feed: line 12: Invalid email address/)
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should not validate an invalid response" do
|
46
46
|
response = MockResponse.new(get_file('invalid_feed.xml'))
|
47
|
-
|
48
|
-
response.
|
49
|
-
}.
|
50
|
-
e.message.
|
51
|
-
e.message.
|
47
|
+
expect {
|
48
|
+
expect(response).to be_valid_feed
|
49
|
+
}.to raise_error(SpecFailed) { |e|
|
50
|
+
expect(e.message).to match(/expected feed to be valid, but validation produced these errors/)
|
51
|
+
expect(e.message).to match(/Invalid feed: line 12: Invalid email address/)
|
52
52
|
}
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should display invalid content when requested" do
|
56
56
|
BeValidAsset::Configuration.display_invalid_content = true
|
57
57
|
feed = get_file('invalid_feed.xml')
|
58
|
-
|
59
|
-
feed.
|
60
|
-
}.
|
61
|
-
e.message.
|
58
|
+
expect {
|
59
|
+
expect(feed).to be_valid_feed
|
60
|
+
}.to raise_error(SpecFailed) { |e|
|
61
|
+
expect(e.message).to match(%r{<link>http://site.example.com/articles/article-1-title</link>})
|
62
62
|
}
|
63
63
|
BeValidAsset::Configuration.display_invalid_content = false
|
64
64
|
end
|
@@ -68,21 +68,21 @@ describe 'be_valid_feed' do
|
|
68
68
|
|
69
69
|
r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
|
70
70
|
h = Net::HTTP.new(BeValidAsset::Configuration.feed_validator_host)
|
71
|
-
h.
|
72
|
-
Net::HTTP.
|
71
|
+
allow(h).to receive(:post).and_return(r)
|
72
|
+
allow(Net::HTTP).to receive(:start).and_return(h)
|
73
73
|
|
74
|
-
|
75
|
-
feed.
|
76
|
-
}.
|
74
|
+
expect {
|
75
|
+
expect(feed).to be_valid_feed
|
76
|
+
}.to raise_error
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should mark test as pending if ENV['NONET'] is true" do
|
80
80
|
ENV['NONET'] = 'true'
|
81
81
|
|
82
82
|
feed = get_file('valid_feed.xml')
|
83
|
-
|
84
|
-
feed.
|
85
|
-
}.
|
83
|
+
expect {
|
84
|
+
expect(feed).to be_valid_feed
|
85
|
+
}.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
|
86
86
|
|
87
87
|
ENV.delete('NONET')
|
88
88
|
end
|
@@ -100,40 +100,40 @@ describe 'be_valid_feed' do
|
|
100
100
|
it "should validate valid feed and cache the response" do
|
101
101
|
feed = get_file('valid_feed.xml')
|
102
102
|
count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
|
103
|
-
feed.
|
104
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
103
|
+
expect(feed).to be_valid_feed
|
104
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should validate valid feed using the cached response" do
|
108
108
|
feed = get_file('valid_feed.xml')
|
109
|
-
feed.
|
109
|
+
expect(feed).to be_valid_feed
|
110
110
|
|
111
|
-
Net::HTTP.
|
112
|
-
feed.
|
111
|
+
expect(Net::HTTP).not_to receive(:start)
|
112
|
+
expect(feed).to be_valid_feed
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should not validate invalid feed, but still cache the response" do
|
116
116
|
feed = get_file('invalid_feed.xml')
|
117
117
|
count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
|
118
|
-
|
119
|
-
feed.
|
120
|
-
}.
|
121
|
-
e.message.
|
122
|
-
e.message.
|
118
|
+
expect {
|
119
|
+
expect(feed).to be_valid_feed
|
120
|
+
}.to raise_error(SpecFailed) { |e|
|
121
|
+
expect(e.message).to match(/expected feed to be valid, but validation produced these errors/)
|
122
|
+
expect(e.message).to match(/Invalid feed: line 12: Invalid email address/)
|
123
123
|
}
|
124
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
124
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should not validate invalid feed, but use the cached response" do
|
128
128
|
feed = get_file('invalid_feed.xml')
|
129
|
-
feed.
|
130
|
-
|
131
|
-
Net::HTTP.
|
132
|
-
|
133
|
-
feed.
|
134
|
-
}.
|
135
|
-
e.message.
|
136
|
-
e.message.
|
129
|
+
expect(feed).not_to be_valid_feed
|
130
|
+
|
131
|
+
expect(Net::HTTP).not_to receive(:start)
|
132
|
+
expect {
|
133
|
+
expect(feed).to be_valid_feed
|
134
|
+
}.to raise_error(SpecFailed) { |e|
|
135
|
+
expect(e.message).to match(/expected feed to be valid, but validation produced these errors/)
|
136
|
+
expect(e.message).to match(/Invalid feed: line 12: Invalid email address/)
|
137
137
|
}
|
138
138
|
end
|
139
139
|
|
@@ -143,23 +143,23 @@ describe 'be_valid_feed' do
|
|
143
143
|
|
144
144
|
r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
|
145
145
|
h = Net::HTTP.new(BeValidAsset::Configuration.feed_validator_host)
|
146
|
-
h.
|
147
|
-
Net::HTTP.
|
146
|
+
allow(h).to receive(:post).and_return(r)
|
147
|
+
allow(Net::HTTP).to receive(:start).and_return(h)
|
148
148
|
|
149
|
-
|
150
|
-
feed.
|
151
|
-
}.
|
152
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
149
|
+
expect {
|
150
|
+
expect(feed).to be_valid_feed
|
151
|
+
}.to raise_error
|
152
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should use the cached result (if available) when network tests disabled" do
|
156
156
|
feed = get_file('valid_feed.xml')
|
157
|
-
feed.
|
157
|
+
expect(feed).to be_valid_feed
|
158
158
|
|
159
159
|
ENV['NONET'] = 'true'
|
160
160
|
|
161
|
-
Net::HTTP.
|
162
|
-
feed.
|
161
|
+
expect(Net::HTTP).not_to receive(:start)
|
162
|
+
expect(feed).to be_valid_feed
|
163
163
|
|
164
164
|
ENV.delete('NONET')
|
165
165
|
end
|
@@ -168,9 +168,9 @@ describe 'be_valid_feed' do
|
|
168
168
|
ENV['NONET'] = 'true'
|
169
169
|
|
170
170
|
feed = get_file('valid_feed.xml')
|
171
|
-
|
172
|
-
feed.
|
173
|
-
}.
|
171
|
+
expect {
|
172
|
+
expect(feed).to be_valid_feed
|
173
|
+
}.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
|
174
174
|
|
175
175
|
ENV.delete('NONET')
|
176
176
|
end
|
@@ -4,72 +4,72 @@ unless defined?(SpecFailed)
|
|
4
4
|
SpecFailed = RSpec::Expectations::ExpectationNotMetError
|
5
5
|
end
|
6
6
|
|
7
|
-
describe 'be_valid_markup' do
|
7
|
+
RSpec.describe 'be_valid_markup' do
|
8
8
|
|
9
9
|
describe "without caching" do
|
10
10
|
it "should validate a valid string" do
|
11
11
|
html = get_file('valid.html')
|
12
|
-
html.
|
12
|
+
expect(html).to be_valid_markup
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should validate a valid xhtml response" do
|
16
16
|
response = MockResponse.new(get_file('valid.html'))
|
17
|
-
response.
|
17
|
+
expect(response).to be_valid_markup
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should validate a valid html5 response" do
|
21
21
|
response = MockResponse.new(get_file('valid.html5'))
|
22
|
-
response.
|
22
|
+
expect(response).to be_valid_markup
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should validate a valid html5 response when only 'source' is available" do
|
26
|
-
response =
|
27
|
-
response.
|
26
|
+
response = double(:source => get_file('valid.html5'))
|
27
|
+
expect(response).to be_valid_markup
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should validate a valid html5 response when only 'body' is available" do
|
31
|
-
response =
|
32
|
-
response.
|
31
|
+
response = double(:body => get_file('valid.html5'))
|
32
|
+
expect(response).to be_valid_markup
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should validate if body is not a string but can be converted to valid string" do
|
36
|
-
response = MockResponse.new(
|
37
|
-
response.
|
36
|
+
response = MockResponse.new(double("XHTML", :to_s => get_file('valid.html')))
|
37
|
+
expect(response).to be_valid_markup
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should validate a valid fragment" do
|
41
|
-
"<p>This is a Fragment</p>".
|
41
|
+
expect("<p>This is a Fragment</p>").to be_valid_markup_fragment
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not validate an invalid string" do
|
45
45
|
html = get_file('invalid.html')
|
46
|
-
|
47
|
-
html.
|
48
|
-
}.
|
49
|
-
e.message.
|
50
|
-
e.message.
|
51
|
-
e.message.
|
46
|
+
expect {
|
47
|
+
expect(html).to be_valid_markup
|
48
|
+
}.to raise_error(SpecFailed) { |e|
|
49
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
50
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
|
51
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for element "b" which is not open/)
|
52
52
|
}
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not validate an invalid response" do
|
56
56
|
response = MockResponse.new(get_file('invalid.html'))
|
57
|
-
|
58
|
-
response.
|
59
|
-
}.
|
60
|
-
e.message.
|
61
|
-
e.message.
|
62
|
-
e.message.
|
57
|
+
expect {
|
58
|
+
expect(response).to be_valid_markup
|
59
|
+
}.to raise_error(SpecFailed) { |e|
|
60
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
61
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
|
62
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for element "b" which is not open/)
|
63
63
|
}
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should display invalid content when requested" do
|
67
67
|
BeValidAsset::Configuration.display_invalid_content = true
|
68
68
|
html = get_file('invalid.html')
|
69
|
-
|
70
|
-
html.
|
71
|
-
}.
|
72
|
-
e.message.
|
69
|
+
expect {
|
70
|
+
expect(html).to be_valid_markup
|
71
|
+
}.to raise_error(SpecFailed) { |e|
|
72
|
+
expect(e.message).to match(/<p><b>This is an example invalid html file<\/p><\/b>/)
|
73
73
|
}
|
74
74
|
BeValidAsset::Configuration.display_invalid_content = false
|
75
75
|
end
|
@@ -85,67 +85,67 @@ describe 'be_valid_markup' do
|
|
85
85
|
|
86
86
|
it "should display invalid lines when requested" do
|
87
87
|
html = get_file('invalid.html')
|
88
|
-
|
89
|
-
html.
|
90
|
-
end.
|
91
|
-
e.message.
|
92
|
-
e.message.
|
93
|
-
e.message.
|
94
|
-
e.message.
|
95
|
-
e.message.
|
96
|
-
e.message.
|
97
|
-
e.message.
|
98
|
-
e.message.
|
88
|
+
expect do
|
89
|
+
expect(html).to be_valid_markup
|
90
|
+
end.to raise_error(SpecFailed) { |e|
|
91
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
92
|
+
expect(e.message).not_to match(/0009 :/)
|
93
|
+
expect(e.message).to match(/0010 :/)
|
94
|
+
expect(e.message).to match(/0011 :/)
|
95
|
+
expect(e.message).to match(/0012>>:/)
|
96
|
+
expect(e.message).to match(/0013 :/)
|
97
|
+
expect(e.message).to match(/0014 :/)
|
98
|
+
expect(e.message).not_to match(/0015 :/)
|
99
99
|
}
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should display specified invalid lines window when requested" do
|
103
103
|
BeValidAsset::Configuration.display_invalid_lines_count = 3
|
104
104
|
html = get_file('invalid.html')
|
105
|
-
|
106
|
-
html.
|
107
|
-
end.
|
108
|
-
e.message.
|
109
|
-
e.message.
|
110
|
-
e.message.
|
111
|
-
e.message.
|
112
|
-
e.message.
|
113
|
-
e.message.
|
105
|
+
expect do
|
106
|
+
expect(html).to be_valid_markup
|
107
|
+
end.to raise_error(SpecFailed) { |e|
|
108
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
109
|
+
expect(e.message).not_to match(/0010 :/)
|
110
|
+
expect(e.message).to match(/0011 :/)
|
111
|
+
expect(e.message).to match(/0012>>:/)
|
112
|
+
expect(e.message).to match(/0013 :/)
|
113
|
+
expect(e.message).not_to match(/0014 :/)
|
114
114
|
}
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should not underrun the beginning of the source" do
|
118
118
|
BeValidAsset::Configuration.display_invalid_lines_count = 7
|
119
119
|
html = get_file('invalid2.html')
|
120
|
-
|
121
|
-
html.
|
122
|
-
end.
|
123
|
-
e.message.
|
124
|
-
e.message.
|
125
|
-
e.message.
|
126
|
-
e.message.
|
120
|
+
expect do
|
121
|
+
expect(html).to be_valid_markup
|
122
|
+
end.to raise_error(SpecFailed) { |e|
|
123
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
124
|
+
expect(e.message).not_to match(/0000 :/)
|
125
|
+
expect(e.message).to match(/0001 :/)
|
126
|
+
expect(e.message).to match(/0003>>:/)
|
127
127
|
}
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should not overrun the end of the source" do
|
131
131
|
BeValidAsset::Configuration.display_invalid_lines_count = 11
|
132
132
|
html = get_file('invalid.html')
|
133
|
-
|
134
|
-
html.
|
135
|
-
end.
|
136
|
-
e.message.
|
137
|
-
e.message.
|
138
|
-
e.message.
|
139
|
-
e.message.
|
133
|
+
expect do
|
134
|
+
expect(html).to be_valid_markup
|
135
|
+
end.to raise_error(SpecFailed) { |e|
|
136
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
137
|
+
expect(e.message).to match(/0012>>:/)
|
138
|
+
expect(e.message).to match(/0015 :/)
|
139
|
+
expect(e.message).not_to match(/0016 :/)
|
140
140
|
}
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should fail when passed a response with a blank body" do
|
145
145
|
response = MockResponse.new('')
|
146
|
-
|
147
|
-
response.
|
148
|
-
}.
|
146
|
+
expect {
|
147
|
+
expect(response).to be_valid_markup
|
148
|
+
}.to raise_error(SpecFailed)
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should fail unless resposne is HTTP OK" do
|
@@ -153,21 +153,21 @@ describe 'be_valid_markup' do
|
|
153
153
|
|
154
154
|
r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
|
155
155
|
h = Net::HTTP.new(BeValidAsset::Configuration.markup_validator_host)
|
156
|
-
h.
|
157
|
-
Net::HTTP.
|
156
|
+
allow(h).to receive(:post2).and_return(r)
|
157
|
+
allow(Net::HTTP).to receive(:start).and_return(h)
|
158
158
|
|
159
|
-
|
160
|
-
html.
|
161
|
-
}.
|
159
|
+
expect {
|
160
|
+
expect(html).to be_valid_markup
|
161
|
+
}.to raise_error
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should mark test as pending if network tests are disabled" do
|
165
165
|
ENV['NONET'] = 'true'
|
166
166
|
|
167
167
|
html = get_file('valid.html')
|
168
|
-
|
169
|
-
html.
|
170
|
-
}.
|
168
|
+
expect {
|
169
|
+
expect(html).to be_valid_markup
|
170
|
+
}.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
|
171
171
|
|
172
172
|
ENV.delete('NONET')
|
173
173
|
end
|
@@ -185,42 +185,42 @@ describe 'be_valid_markup' do
|
|
185
185
|
it "should validate a valid string and cache the response" do
|
186
186
|
html = get_file('valid.html')
|
187
187
|
count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
|
188
|
-
html.
|
189
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
188
|
+
expect(html).to be_valid_markup
|
189
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should validate a valid string using the cached response" do
|
193
193
|
html = get_file('valid.html')
|
194
|
-
html.
|
194
|
+
expect(html).to be_valid_markup
|
195
195
|
|
196
|
-
Net::HTTP.
|
197
|
-
html.
|
196
|
+
expect(Net::HTTP).not_to receive(:start)
|
197
|
+
expect(html).to be_valid_markup
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should not validate an invalid response, but still cache the response" do
|
201
201
|
response = MockResponse.new(get_file('invalid.html'))
|
202
202
|
count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
|
203
|
-
|
204
|
-
response.
|
205
|
-
}.
|
206
|
-
e.message.
|
207
|
-
e.message.
|
208
|
-
e.message.
|
203
|
+
expect {
|
204
|
+
expect(response).to be_valid_markup
|
205
|
+
}.to raise_error(SpecFailed) { |e|
|
206
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
207
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
|
208
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for element "b" which is not open/)
|
209
209
|
}
|
210
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
210
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should not validate an invalid response, but use the cached response" do
|
214
214
|
response = MockResponse.new(get_file('invalid.html'))
|
215
|
-
response.
|
216
|
-
|
217
|
-
Net::HTTP.
|
218
|
-
|
219
|
-
response.
|
220
|
-
}.
|
221
|
-
e.message.
|
222
|
-
e.message.
|
223
|
-
e.message.
|
215
|
+
expect(response).not_to be_valid_markup
|
216
|
+
|
217
|
+
expect(Net::HTTP).not_to receive(:start)
|
218
|
+
expect {
|
219
|
+
expect(response).to be_valid_markup
|
220
|
+
}.to raise_error(SpecFailed) { |e|
|
221
|
+
expect(e.message).to match(/expected markup to be valid, but validation produced these errors/)
|
222
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
|
223
|
+
expect(e.message).to match(/Invalid markup: line 12: end tag for element "b" which is not open/)
|
224
224
|
}
|
225
225
|
end
|
226
226
|
|
@@ -230,23 +230,23 @@ describe 'be_valid_markup' do
|
|
230
230
|
|
231
231
|
r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
|
232
232
|
h = Net::HTTP.new(BeValidAsset::Configuration.markup_validator_host)
|
233
|
-
h.
|
234
|
-
Net::HTTP.
|
233
|
+
allow(h).to receive(:post2).and_return(r)
|
234
|
+
allow(Net::HTTP).to receive(:start).and_return(h)
|
235
235
|
|
236
|
-
|
237
|
-
html.
|
238
|
-
}.
|
239
|
-
Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.
|
236
|
+
expect {
|
237
|
+
expect(html).to be_valid_markup
|
238
|
+
}.to raise_error
|
239
|
+
expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count)
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should use the cached result (if available) when network tests disabled" do
|
243
243
|
html = get_file('valid.html')
|
244
|
-
html.
|
244
|
+
expect(html).to be_valid_markup
|
245
245
|
|
246
246
|
ENV['NONET'] = 'true'
|
247
247
|
|
248
|
-
Net::HTTP.
|
249
|
-
html.
|
248
|
+
expect(Net::HTTP).not_to receive(:start)
|
249
|
+
expect(html).to be_valid_markup
|
250
250
|
|
251
251
|
ENV.delete('NONET')
|
252
252
|
end
|
@@ -255,9 +255,9 @@ describe 'be_valid_markup' do
|
|
255
255
|
ENV['NONET'] = 'true'
|
256
256
|
|
257
257
|
html = get_file('valid.html')
|
258
|
-
|
259
|
-
html.
|
260
|
-
}.
|
258
|
+
expect {
|
259
|
+
expect(html).to be_valid_markup
|
260
|
+
}.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
|
261
261
|
|
262
262
|
ENV.delete('NONET')
|
263
263
|
end
|
@@ -267,7 +267,7 @@ describe 'be_valid_markup' do
|
|
267
267
|
html = get_file('valid_with_cache_busters.html')
|
268
268
|
html_modified = get_file('valid_without_cache_busters.html')
|
269
269
|
be_valid_markup = BeValidAsset::BeValidMarkup.new
|
270
|
-
be_valid_markup.
|
270
|
+
expect(be_valid_markup).to receive(:validate).with({:fragment => html_modified})
|
271
271
|
be_valid_markup.matches?(html)
|
272
272
|
end
|
273
273
|
|
@@ -275,7 +275,7 @@ describe 'be_valid_markup' do
|
|
275
275
|
BeValidAsset::Configuration.enable_caching = false
|
276
276
|
html = get_file('valid_with_cache_busters.html')
|
277
277
|
be_valid_markup = BeValidAsset::BeValidMarkup.new
|
278
|
-
be_valid_markup.
|
278
|
+
expect(be_valid_markup).to receive(:validate).with({:fragment => html})
|
279
279
|
be_valid_markup.matches?(html)
|
280
280
|
end
|
281
281
|
end
|
@@ -292,39 +292,71 @@ describe 'be_valid_markup' do
|
|
292
292
|
html = get_file('html_with_srcset.html')
|
293
293
|
html_modified = get_file('html_without_srcset.html')
|
294
294
|
be_valid_markup = BeValidAsset::BeValidMarkup.new
|
295
|
-
be_valid_markup.
|
295
|
+
expect(be_valid_markup).to receive(:validate).with({:fragment => html_modified})
|
296
296
|
be_valid_markup.matches?(html)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
+
describe 'host and path configuration' do
|
301
|
+
let(:response) { Net::HTTPSuccess.new('1.1', 200, 'HTTPOK').tap { |r| r['x-w3c-validator-status'] = 'Valid' } }
|
302
|
+
let(:http) { double('HTTP', :post2 => response) }
|
303
|
+
let(:html) { MockResponse.new(get_file('valid.html')) }
|
304
|
+
|
305
|
+
it "parses the domain and port out of the host configuration" do
|
306
|
+
allow(BeValidAsset::Configuration).to receive_messages(:markup_validator_host => 'http://validator.example.com:1234')
|
307
|
+
|
308
|
+
expect(Net::HTTP).to receive(:start).with('validator.example.com', 1234).and_return(http)
|
309
|
+
expect(html).to be_valid_markup
|
310
|
+
end
|
311
|
+
|
312
|
+
it "forces http if no protocol is specificed in the host configuration" do
|
313
|
+
allow(BeValidAsset::Configuration).to receive_messages(:markup_validator_host => 'validator.example.com')
|
314
|
+
|
315
|
+
expect(Net::HTTP).to receive(:start).with('validator.example.com', 80).and_return(http)
|
316
|
+
expect(html).to be_valid_markup
|
317
|
+
end
|
318
|
+
|
319
|
+
it "configures net/http to use ssl if https is specificed in the host configuration" do
|
320
|
+
allow(BeValidAsset::Configuration).to receive_messages(:markup_validator_host => 'https://validator.example.com')
|
321
|
+
|
322
|
+
ssl_connection = double('Net/HTTP SSL')
|
323
|
+
expect(Net::HTTP).to receive(:new).with('validator.example.com', 443).and_return(ssl_connection)
|
324
|
+
expect(ssl_connection).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
325
|
+
expect(ssl_connection).to receive(:use_ssl=).with(true)
|
326
|
+
expect(ssl_connection).to receive(:start).and_return(http)
|
327
|
+
expect(html).to be_valid_markup
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
300
331
|
describe "Proxying" do
|
301
332
|
before :each do
|
302
333
|
r = Net::HTTPSuccess.new('1.1', 200, 'HTTPOK')
|
303
334
|
r['x-w3c-validator-status'] = 'Valid'
|
304
|
-
@http =
|
305
|
-
@http.
|
335
|
+
@http = double('HTTP')
|
336
|
+
allow(@http).to receive(:post2).and_return(r)
|
306
337
|
|
307
338
|
@html = MockResponse.new(get_file('valid.html'))
|
339
|
+
allow(BeValidAsset::Configuration).to receive_messages(:markup_validator_host => 'http://validator.example.com:1234')
|
308
340
|
end
|
309
341
|
|
310
342
|
it "should use direct http without ENV['http_proxy']" do
|
311
343
|
ENV.delete('http_proxy')
|
312
|
-
Net::HTTP.
|
313
|
-
@html.
|
344
|
+
expect(Net::HTTP).to receive(:start).with('validator.example.com', 1234).and_return(@http)
|
345
|
+
expect(@html).to be_valid_markup
|
314
346
|
end
|
315
347
|
|
316
348
|
it "should use proxied http connection with ENV['http_proxy']" do
|
317
349
|
ENV['http_proxy'] = "http://user:pw@localhost:3128"
|
318
|
-
Net::HTTP.
|
319
|
-
@html.
|
350
|
+
expect(Net::HTTP).to receive(:start).with('validator.example.com', 1234, 'localhost', 3128, "user", "pw").and_return(@http)
|
351
|
+
expect(@html).to be_valid_markup
|
320
352
|
ENV.delete('http_proxy')
|
321
353
|
end
|
322
354
|
|
323
355
|
it "should raise exception with invalid http_proxy" do
|
324
356
|
ENV['http_proxy'] = "http://invalid:uri"
|
325
|
-
|
326
|
-
@html.
|
327
|
-
}.
|
357
|
+
expect {
|
358
|
+
expect(@html).to be_valid_markup
|
359
|
+
}.to raise_error(URI::InvalidURIError)
|
328
360
|
ENV.delete('http_proxy')
|
329
361
|
end
|
330
362
|
end
|