be_valid_asset 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.should be_valid_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.should be_valid_rss
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.should be_valid_atom
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.should be_valid_feed
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(stub("Feed", :to_s => get_file('valid_feed.xml')))
32
- response.should be_valid_feed
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
- lambda {
38
- feed.should be_valid_feed
39
- }.should raise_error(SpecFailed) { |e|
40
- e.message.should match(/expected feed to be valid, but validation produced these errors/)
41
- e.message.should match(/Invalid feed: line 12: Invalid email address/)
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
- lambda {
48
- response.should be_valid_feed
49
- }.should raise_error(SpecFailed) { |e|
50
- e.message.should match(/expected feed to be valid, but validation produced these errors/)
51
- e.message.should match(/Invalid feed: line 12: Invalid email address/)
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
- lambda {
59
- feed.should be_valid_feed
60
- }.should raise_error(SpecFailed) { |e|
61
- e.message.should match(%r{<link>http://site.example.com/articles/article-1-title</link>})
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.stub!(:post).and_return(r)
72
- Net::HTTP.stub!(:start).and_return(h)
71
+ allow(h).to receive(:post).and_return(r)
72
+ allow(Net::HTTP).to receive(:start).and_return(h)
73
73
 
74
- lambda {
75
- feed.should be_valid_feed
76
- }.should raise_error
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
- lambda {
84
- feed.should be_valid_feed
85
- }.should raise_error(RSpec::Core::Pending::PendingDeclaredInExample)
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.should be_valid_feed
104
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count + 1)
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.should be_valid_feed
109
+ expect(feed).to be_valid_feed
110
110
 
111
- Net::HTTP.should_not_receive(:start)
112
- feed.should be_valid_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
- lambda {
119
- feed.should be_valid_feed
120
- }.should raise_error(SpecFailed) { |e|
121
- e.message.should match(/expected feed to be valid, but validation produced these errors/)
122
- e.message.should match(/Invalid feed: line 12: Invalid email address/)
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.should eql(count + 1)
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.should_not be_valid_feed
130
-
131
- Net::HTTP.should_not_receive(:start)
132
- lambda {
133
- feed.should be_valid_feed
134
- }.should raise_error(SpecFailed) { |e|
135
- e.message.should match(/expected feed to be valid, but validation produced these errors/)
136
- e.message.should match(/Invalid feed: line 12: Invalid email address/)
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.stub!(:post).and_return(r)
147
- Net::HTTP.stub!(:start).and_return(h)
146
+ allow(h).to receive(:post).and_return(r)
147
+ allow(Net::HTTP).to receive(:start).and_return(h)
148
148
 
149
- lambda {
150
- feed.should be_valid_feed
151
- }.should raise_error
152
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count)
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.should be_valid_feed
157
+ expect(feed).to be_valid_feed
158
158
 
159
159
  ENV['NONET'] = 'true'
160
160
 
161
- Net::HTTP.should_not_receive(:start)
162
- feed.should be_valid_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
- lambda {
172
- feed.should be_valid_feed
173
- }.should raise_error(RSpec::Core::Pending::PendingDeclaredInExample)
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.should be_valid_markup
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.should be_valid_markup
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.should be_valid_markup
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 = mock(:source => get_file('valid.html5'))
27
- response.should be_valid_markup
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 = mock(:body => get_file('valid.html5'))
32
- response.should be_valid_markup
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(stub("XHTML", :to_s => get_file('valid.html')))
37
- response.should be_valid_markup
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>".should be_valid_markup_fragment
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
- lambda {
47
- html.should be_valid_markup
48
- }.should raise_error(SpecFailed) { |e|
49
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
50
- e.message.should match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
51
- e.message.should match(/Invalid markup: line 12: end tag for element "b" which is not open/)
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
- lambda {
58
- response.should be_valid_markup
59
- }.should raise_error(SpecFailed) { |e|
60
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
61
- e.message.should match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
62
- e.message.should match(/Invalid markup: line 12: end tag for element "b" which is not open/)
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
- lambda {
70
- html.should be_valid_markup
71
- }.should raise_error(SpecFailed) { |e|
72
- e.message.should match(/<p><b>This is an example invalid html file<\/p><\/b>/)
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
- lambda do
89
- html.should be_valid_markup
90
- end.should raise_error(SpecFailed) { |e|
91
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
92
- e.message.should_not match(/0009 :/)
93
- e.message.should match(/0010 :/)
94
- e.message.should match(/0011 :/)
95
- e.message.should match(/0012>>:/)
96
- e.message.should match(/0013 :/)
97
- e.message.should match(/0014 :/)
98
- e.message.should_not match(/0015 :/)
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
- lambda do
106
- html.should be_valid_markup
107
- end.should raise_error(SpecFailed) { |e|
108
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
109
- e.message.should_not match(/0010 :/)
110
- e.message.should match(/0011 :/)
111
- e.message.should match(/0012>>:/)
112
- e.message.should match(/0013 :/)
113
- e.message.should_not match(/0014 :/)
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
- lambda do
121
- html.should be_valid_markup
122
- end.should raise_error(SpecFailed) { |e|
123
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
124
- e.message.should_not match(/0000 :/)
125
- e.message.should match(/0001 :/)
126
- e.message.should match(/0003>>:/)
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
- lambda do
134
- html.should be_valid_markup
135
- end.should raise_error(SpecFailed) { |e|
136
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
137
- e.message.should match(/0012>>:/)
138
- e.message.should match(/0015 :/)
139
- e.message.should_not match(/0016 :/)
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
- lambda {
147
- response.should be_valid_markup
148
- }.should raise_error(SpecFailed)
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.stub!(:post2).and_return(r)
157
- Net::HTTP.stub!(:start).and_return(h)
156
+ allow(h).to receive(:post2).and_return(r)
157
+ allow(Net::HTTP).to receive(:start).and_return(h)
158
158
 
159
- lambda {
160
- html.should be_valid_markup
161
- }.should raise_error
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
- lambda {
169
- html.should be_valid_markup
170
- }.should raise_error(RSpec::Core::Pending::PendingDeclaredInExample)
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.should be_valid_markup
189
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count + 1)
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.should be_valid_markup
194
+ expect(html).to be_valid_markup
195
195
 
196
- Net::HTTP.should_not_receive(:start)
197
- html.should be_valid_markup
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
- lambda {
204
- response.should be_valid_markup
205
- }.should raise_error(SpecFailed) { |e|
206
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
207
- e.message.should match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
208
- e.message.should match(/Invalid markup: line 12: end tag for element "b" which is not open/)
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.should eql(count + 1)
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.should_not be_valid_markup
216
-
217
- Net::HTTP.should_not_receive(:start)
218
- lambda {
219
- response.should be_valid_markup
220
- }.should raise_error(SpecFailed) { |e|
221
- e.message.should match(/expected markup to be valid, but validation produced these errors/)
222
- e.message.should match(/Invalid markup: line 12: end tag for "b" omitted, but OMITTAG NO was specified/)
223
- e.message.should match(/Invalid markup: line 12: end tag for element "b" which is not open/)
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.stub!(:post2).and_return(r)
234
- Net::HTTP.stub!(:start).and_return(h)
233
+ allow(h).to receive(:post2).and_return(r)
234
+ allow(Net::HTTP).to receive(:start).and_return(h)
235
235
 
236
- lambda {
237
- html.should be_valid_markup
238
- }.should raise_error
239
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count)
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.should be_valid_markup
244
+ expect(html).to be_valid_markup
245
245
 
246
246
  ENV['NONET'] = 'true'
247
247
 
248
- Net::HTTP.should_not_receive(:start)
249
- html.should be_valid_markup
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
- lambda {
259
- html.should be_valid_markup
260
- }.should raise_error(RSpec::Core::Pending::PendingDeclaredInExample)
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.should_receive(:validate).with({:fragment => html_modified})
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.should_receive(:validate).with({:fragment => html})
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.should_receive(:validate).with({:fragment => html_modified})
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 = mock('HTTP')
305
- @http.stub!(:post2).and_return(r)
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.should_receive(:start).with(BeValidAsset::Configuration.markup_validator_host).and_return(@http)
313
- @html.should be_valid_markup
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.should_receive(:start).with(BeValidAsset::Configuration.markup_validator_host, nil, 'localhost', 3128, "user", "pw").and_return(@http)
319
- @html.should be_valid_markup
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
- lambda {
326
- @html.should be_valid_markup
327
- }.should raise_error(URI::InvalidURIError)
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