From 28492204ee59a5aca2f3bc7b161d45724552686d Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Mon, 23 May 2016 22:45:01 +0200 Subject: Add default exceptions affected by suppress (#25099) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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] --- activesupport/lib/active_support/core_ext/kernel/reporting.rb | 1 + activesupport/test/core_ext/kernel_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/kernel/reporting.rb b/activesupport/lib/active_support/core_ext/kernel/reporting.rb index d0197af95f..9e50ea23b7 100644 --- a/activesupport/lib/active_support/core_ext/kernel/reporting.rb +++ b/activesupport/lib/active_support/core_ext/kernel/reporting.rb @@ -37,6 +37,7 @@ module Kernel # # 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 diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index 503e6595cb..bb634d6a09 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -42,6 +42,15 @@ class KernelSuppressTest < ActiveSupport::TestCase 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 } -- cgit v1.2.3