@@ -227,47 +227,58 @@ def test_enumerator_nonempty
227227 end
228228 end
229229
230+ def with_value_exception ( &block )
231+ # Raise synthetic exception to test error handling because there is no known way to cause it naturally
232+ CssParser ::RuleSet ::Declarations ::Value . stub :new , -> { raise ArgumentError . new , 'stub' } , &block
233+ end
234+
230235 def test_catching_argument_exceptions_for_add_rule
231- cp_with_exceptions = Parser . new ( rule_set_exceptions : true )
232- assert_raises ArgumentError , 'background-color value is empty' do
233- cp_with_exceptions . add_rule! ( selectors : 'body' , block : 'background-color: !important' )
234- end
236+ with_value_exception do
237+ cp_with_exceptions = Parser . new ( rule_set_exceptions : true )
238+ assert_raises ArgumentError , 'stub' do
239+ cp_with_exceptions . add_rule! ( selectors : 'body' , block : 'background-color: blue' )
240+ end
235241
236- cp_without_exceptions = Parser . new ( rule_set_exceptions : false )
237- cp_without_exceptions . add_rule! ( selectors : 'body' , block : 'background-color: !important' )
242+ cp_without_exceptions = Parser . new ( rule_set_exceptions : false )
243+ cp_without_exceptions . add_rule! ( selectors : 'body' , block : 'background-color: blue' )
244+ end
238245 end
239246
240247 def test_catching_argument_exceptions_for_add_rule_positional
241- cp_with_exceptions = Parser . new ( rule_set_exceptions : true )
248+ with_value_exception do
249+ cp_with_exceptions = Parser . new ( rule_set_exceptions : true )
250+
251+ assert_raises ArgumentError , 'stub' do
252+ _ , err = capture_io do
253+ cp_with_exceptions . add_rule! ( 'body' , 'background-color: blue' )
254+ end
255+ assert_includes err , "DEPRECATION"
256+ end
242257
243- assert_raises ArgumentError , 'background-color value is empty' do
258+ cp_without_exceptions = Parser . new ( rule_set_exceptions : false )
244259 _ , err = capture_io do
245- cp_with_exceptions . add_rule! ( 'body' , 'background-color: !important ' )
260+ cp_without_exceptions . add_rule! ( 'body' , 'background-color: blue ' )
246261 end
247262 assert_includes err , "DEPRECATION"
248263 end
249-
250- cp_without_exceptions = Parser . new ( rule_set_exceptions : false )
251- _ , err = capture_io do
252- cp_without_exceptions . add_rule! ( 'body' , 'background-color: !important' )
253- end
254- assert_includes err , "DEPRECATION"
255264 end
256265
257266 def test_catching_argument_exceptions_for_add_rule_with_offsets
258- cp_with_exceptions = Parser . new ( capture_offsets : true , rule_set_exceptions : true )
267+ with_value_exception do
268+ cp_with_exceptions = Parser . new ( capture_offsets : true , rule_set_exceptions : true )
269+
270+ assert_raises ArgumentError , 'stub' do
271+ _ , err = capture_io do
272+ cp_with_exceptions . add_rule_with_offsets! ( 'body' , 'background-color: blue' , 'inline' , 1 )
273+ end
274+ assert_includes err , "DEPRECATION"
275+ end
259276
260- assert_raises ArgumentError , 'background-color value is empty' do
277+ cp_without_exceptions = Parser . new ( capture_offsets : true , rule_set_exceptions : false )
261278 _ , err = capture_io do
262- cp_with_exceptions . add_rule_with_offsets! ( 'body' , 'background-color: !important ' , 'inline' , 1 )
279+ cp_without_exceptions . add_rule_with_offsets! ( 'body' , 'background-color: blue ' , 'inline' , 1 )
263280 end
264281 assert_includes err , "DEPRECATION"
265282 end
266-
267- cp_without_exceptions = Parser . new ( capture_offsets : true , rule_set_exceptions : false )
268- _ , err = capture_io do
269- cp_without_exceptions . add_rule_with_offsets! ( 'body' , 'background-color: !important' , 'inline' , 1 )
270- end
271- assert_includes err , "DEPRECATION"
272283 end
273284end
0 commit comments