@@ -122,6 +122,19 @@ def test_counts
122
122
end
123
123
end
124
124
125
+ def test_zero_counts_with_block
126
+ render_html "<div>foo</div>"
127
+
128
+ errors = [
129
+ assert_raises ( ArgumentError ) { assert_select ( "p" , false ) { nil } } ,
130
+ assert_raises ( ArgumentError ) { assert_select ( "p" , 0 ) { nil } } ,
131
+ assert_raises ( ArgumentError ) { assert_select ( "p" , count : 0 ) { nil } } ,
132
+ assert_raises ( ArgumentError ) { assert_select ( "p" , 0 ..0 ) { nil } } ,
133
+ assert_raises ( ArgumentError ) { assert_select ( "p" , minimum : 0 , maximum : 0 ) { nil } }
134
+ ]
135
+ assert_equal [ "Cannot be called with a block when asserting that a selector does not match" ] , errors . map ( &:message ) . uniq
136
+ end
137
+
125
138
def test_substitution_values
126
139
render_html '<div id="1">foo</div><div id="2">foo</div>'
127
140
assert_select "div:match('id', ?)" , /\d +/ do |elements |
@@ -214,46 +227,59 @@ def test_assert_select_text_match
214
227
# Test assert_not_select.
215
228
#
216
229
217
- def test_not_select
230
+ def test_assert_not_select
218
231
render_html '<div id="1"></div>'
219
232
assert_not_select "p"
220
233
assert_failure ( /Expected exactly 0 elements matching "div", found 1/ ) { assert_not_select "div" }
221
234
assert_failure ( /Expected exactly 0 elements matching "div#1", found 1/ ) { assert_not_select "div#1" }
222
235
end
223
236
224
- def test_not_select_with_true
237
+ def test_assert_not_select_with_true
225
238
render_html '<div id="1"></div>'
226
- assert_raises ( ArgumentError ) { assert_not_select "div" , true }
239
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , true }
240
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
227
241
end
228
242
229
- def test_not_select_with_false
243
+ def test_assert_not_select_with_false
230
244
render_html '<div id="1"></div>'
231
- assert_raises ( ArgumentError ) { assert_not_select "div" , false }
245
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , false }
246
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
232
247
end
233
248
234
- def test_not_select_with_integer
249
+ def test_assert_not_select_with_integer
235
250
render_html '<div id="1"></div>'
236
- assert_raises ( ArgumentError ) { assert_not_select "div" , 1 }
251
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , 1 }
252
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
237
253
end
238
254
239
- def test_not_select_with_range
255
+ def test_assert_not_select_with_range
240
256
render_html '<div id="1"></div>'
241
- assert_raises ( ArgumentError ) { assert_not_select "div" , 1 ..5 }
257
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , 1 ..5 }
258
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
242
259
end
243
260
244
- def test_not_select_with_count
261
+ def test_assert_not_select_with_count
245
262
render_html '<div id="1"></div>'
246
- assert_raises ( ArgumentError ) { assert_not_select "div" , count : 1 }
263
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , count : 1 }
264
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
247
265
end
248
266
249
- def test_not_select_with_minimum
267
+ def test_assert_not_select_with_minimum
250
268
render_html '<div id="1"></div>'
251
- assert_raises ( ArgumentError ) { assert_not_select "div" , minimum : 1 }
269
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , minimum : 1 }
270
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
252
271
end
253
272
254
- def test_not_select_with_maximum
273
+ def test_assert_not_select_with_maximum
255
274
render_html '<div id="1"></div>'
256
- assert_raises ( ArgumentError ) { assert_not_select "div" , maximum : 1 }
275
+ error = assert_raises ( ArgumentError ) { assert_not_select "div" , maximum : 1 }
276
+ assert_equal "Cannot use true, false, Integer, Range, :count, :minimum and :maximum when asserting that a selector does not match" , error . message
277
+ end
278
+
279
+ def test_assert_not_select_with_block
280
+ render_html "<div>foo</div>"
281
+ error = assert_raises ( ArgumentError ) { assert_not_select ( "p" ) { nil } }
282
+ assert_equal "Cannot be called with a block when asserting that a selector does not match" , error . message
257
283
end
258
284
259
285
#
0 commit comments