Add default exceptions affected by suppress (#25099)
* Add default exceptions affected by suppress suppress { do_something_that_might_fail } # instead of begin do_something_that_might_fail rescue end # or do_something_that_might_fail rescue nil * Do not add default exceptions list constant [Rafael Mendonça França + Alexey Zapparov]
This commit is contained in:
parent
d0a23339ac
commit
28492204ee
@ -37,6 +37,7 @@ def with_warnings(flag)
|
||||
#
|
||||
# puts 'This code gets executed and nothing related to ZeroDivisionError was seen'
|
||||
def suppress(*exception_classes)
|
||||
exception_classes = StandardError if exception_classes.empty?
|
||||
yield
|
||||
rescue *exception_classes
|
||||
end
|
||||
|
@ -42,6 +42,15 @@ def test_reraise
|
||||
end
|
||||
end
|
||||
|
||||
def test_suppress_with_defaults
|
||||
suppress { raise RuntimeError }
|
||||
suppress { raise ArgumentError }
|
||||
|
||||
assert_raise(LoadError) do
|
||||
suppress { raise LoadError }
|
||||
end
|
||||
end
|
||||
|
||||
def test_suppression
|
||||
suppress(ArgumentError) { raise ArgumentError }
|
||||
suppress(LoadError) { raise LoadError }
|
||||
|
Loading…
Reference in New Issue
Block a user