1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Exception handling more readable

[#5601 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
Thiago Pradi 2010-09-11 11:00:37 -03:00 committed by Santiago Pastorino
parent af6757a1ca
commit 3c9bf6e1dc
8 changed files with 26 additions and 26 deletions

View file

@ -459,8 +459,8 @@ class AssertSelectTest < ActionController::TestCase
assert_select_rjs :remove, "test1" assert_select_rjs :remove, "test1"
rescue Assertion rescue Assertion => e
assert_equal "No RJS statement that removes 'test1' was rendered.", $!.message assert_equal "No RJS statement that removes 'test1' was rendered.", e.message
end end
def test_assert_select_rjs_for_remove_ignores_block def test_assert_select_rjs_for_remove_ignores_block
@ -491,8 +491,8 @@ class AssertSelectTest < ActionController::TestCase
assert_select_rjs :show, "test1" assert_select_rjs :show, "test1"
rescue Assertion rescue Assertion => e
assert_equal "No RJS statement that shows 'test1' was rendered.", $!.message assert_equal "No RJS statement that shows 'test1' was rendered.", e.message
end end
def test_assert_select_rjs_for_show_ignores_block def test_assert_select_rjs_for_show_ignores_block
@ -523,8 +523,8 @@ class AssertSelectTest < ActionController::TestCase
assert_select_rjs :hide, "test1" assert_select_rjs :hide, "test1"
rescue Assertion rescue Assertion => e
assert_equal "No RJS statement that hides 'test1' was rendered.", $!.message assert_equal "No RJS statement that hides 'test1' was rendered.", e.message
end end
def test_assert_select_rjs_for_hide_ignores_block def test_assert_select_rjs_for_hide_ignores_block
@ -555,8 +555,8 @@ class AssertSelectTest < ActionController::TestCase
assert_select_rjs :toggle, "test1" assert_select_rjs :toggle, "test1"
rescue Assertion rescue Assertion => e
assert_equal "No RJS statement that toggles 'test1' was rendered.", $!.message assert_equal "No RJS statement that toggles 'test1' was rendered.", e.message
end end
def test_assert_select_rjs_for_toggle_ignores_block def test_assert_select_rjs_for_toggle_ignores_block

View file

@ -67,8 +67,8 @@ module ActiveRecord
begin begin
require "active_record/connection_adapters/#{spec[:adapter]}_adapter" require "active_record/connection_adapters/#{spec[:adapter]}_adapter"
rescue LoadError rescue LoadError => e
raise "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{$!})" raise "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{e})"
end end
adapter_method = "#{spec[:adapter]}_connection" adapter_method = "#{spec[:adapter]}_connection"

View file

@ -67,8 +67,8 @@ namespace :db do
# Create the SQLite database # Create the SQLite database
ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection ActiveRecord::Base.connection
rescue rescue Exception => e
$stderr.puts $!, *($!.backtrace) $stderr.puts e, *(e.backtrace)
$stderr.puts "Couldn't create database for #{config.inspect}" $stderr.puts "Couldn't create database for #{config.inspect}"
end end
end end
@ -113,8 +113,8 @@ namespace :db do
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding)) ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.establish_connection(config)
rescue rescue Exception => e
$stderr.puts $!, *($!.backtrace) $stderr.puts e, *(e.backtrace)
$stderr.puts "Couldn't create database for #{config.inspect}" $stderr.puts "Couldn't create database for #{config.inspect}"
end end
end end

View file

@ -589,8 +589,8 @@ module ActiveResource
def prefix(options={}) "#{prefix_call}" end def prefix(options={}) "#{prefix_call}" end
RUBY_EVAL RUBY_EVAL
end end
rescue rescue Exception => e
logger.error "Couldn't set prefix: #{$!}\n #{code}" if logger logger.error "Couldn't set prefix: #{e}\n #{code}" if logger
raise raise
end end

View file

@ -61,8 +61,8 @@ module ActiveSupport
store_class = store_class =
begin begin
require "active_support/cache/#{store}" require "active_support/cache/#{store}"
rescue LoadError rescue LoadError => e
raise "Could not find cache store adapter for #{store} (#{$!})" raise "Could not find cache store adapter for #{store} (#{e})"
else else
ActiveSupport::Cache.const_get(store_class_name) ActiveSupport::Cache.const_get(store_class_name)
end end

View file

@ -58,16 +58,16 @@ begin
metric.send(mode) { __send__ @method_name } metric.send(mode) { __send__ @method_name }
rescue ::Test::Unit::AssertionFailedError => e rescue ::Test::Unit::AssertionFailedError => e
add_failure(e.message, e.backtrace) add_failure(e.message, e.backtrace)
rescue StandardError, ScriptError rescue StandardError, ScriptError => e
add_error($!) add_error(e)
ensure ensure
begin begin
teardown teardown
run_callbacks :teardown, :enumerator => :reverse_each run_callbacks :teardown, :enumerator => :reverse_each
rescue ::Test::Unit::AssertionFailedError => e rescue ::Test::Unit::AssertionFailedError => e
add_failure(e.message, e.backtrace) add_failure(e.message, e.backtrace)
rescue StandardError, ScriptError rescue StandardError, ScriptError => e
add_error($!) add_error(e)
end end
end end

View file

@ -53,8 +53,8 @@ class DurationTest < ActiveSupport::TestCase
flunk("no exception was raised") flunk("no exception was raised")
rescue ArgumentError => e rescue ArgumentError => e
assert_equal 'expected a time or date, got ""', e.message, "ensure ArgumentError is not being raised by dependencies.rb" assert_equal 'expected a time or date, got ""', e.message, "ensure ArgumentError is not being raised by dependencies.rb"
rescue Exception rescue Exception => e
flunk("ArgumentError should be raised, but we got #{$!.class} instead") flunk("ArgumentError should be raised, but we got #{e.class} instead")
end end
end end

View file

@ -217,8 +217,8 @@ class OrderedHashTest < Test::Unit::TestCase
ActiveSupport::OrderedHash[1,2,3,4,5] ActiveSupport::OrderedHash[1,2,3,4,5]
flunk "Hash::[] should have raised an exception on initialization " + flunk "Hash::[] should have raised an exception on initialization " +
"with an odd number of parameters" "with an odd number of parameters"
rescue rescue ArgumentError => e
assert_equal "odd number of arguments for Hash", $!.message assert_equal "odd number of arguments for Hash", e.message
end end
end end