From fb9f4e9770b827e1125d6fa068e7a02e2c1b7aaf Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Fri, 10 Sep 2010 18:56:49 -0300 Subject: [PATCH] Make exception handling more readable on ActiveSupport --- activesupport/lib/active_support/cache.rb | 4 ++-- .../lib/active_support/testing/performance.rb | 8 ++++---- activesupport/test/core_ext/duration_test.rb | 4 ++-- activesupport/test/ordered_hash_test.rb | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index df35540..9098ffb 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -61,8 +61,8 @@ module ActiveSupport store_class = begin require "active_support/cache/#{store}" - rescue LoadError - raise "Could not find cache store adapter for #{store} (#{$!})" + rescue LoadError => e + raise "Could not find cache store adapter for #{store} (#{e})" else ActiveSupport::Cache.const_get(store_class_name) end diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index f7ddf64..64b436b 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -58,16 +58,16 @@ begin metric.send(mode) { __send__ @method_name } rescue ::Test::Unit::AssertionFailedError => e add_failure(e.message, e.backtrace) - rescue StandardError, ScriptError - add_error($!) + rescue StandardError, ScriptError => e + add_error(e) ensure begin teardown run_callbacks :teardown, :enumerator => :reverse_each rescue ::Test::Unit::AssertionFailedError => e add_failure(e.message, e.backtrace) - rescue StandardError, ScriptError - add_error($!) + rescue StandardError, ScriptError => e + add_error(e) end end diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index b6456f0..bb453b8 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -53,8 +53,8 @@ class DurationTest < ActiveSupport::TestCase flunk("no exception was raised") rescue ArgumentError => e assert_equal 'expected a time or date, got ""', e.message, "ensure ArgumentError is not being raised by dependencies.rb" - rescue Exception - flunk("ArgumentError should be raised, but we got #{$!.class} instead") + rescue Exception => e + flunk("ArgumentError should be raised, but we got #{e.class} instead") end end diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index f47e896..50778b5 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -217,8 +217,8 @@ class OrderedHashTest < Test::Unit::TestCase ActiveSupport::OrderedHash[1,2,3,4,5] flunk "Hash::[] should have raised an exception on initialization " + "with an odd number of parameters" - rescue - assert_equal "odd number of arguments for Hash", $!.message + rescue ArgumentError => e + assert_equal "odd number of arguments for Hash", e.message end end -- 1.6.6.1