diff --git a/ChangeLog b/ChangeLog index 23574954fc..594d739f3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Dec 9 00:45:00 2003 Nathaniel Talbott + + * lib/test/unit/assertions.rb: renamed #assert_raises to #assert_raise + and made the former call the latter. [ruby-core:01890] + + * test/testunit/test_assertions.rb: ditto. + Tue Dec 9 00:07:35 2003 NAKAMURA, Hiroshi * lib/soap/rpc/standaloneServer.rb: add 'shutdown' and 'status' diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 3076b7fd02..090a07a405 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -56,9 +56,9 @@ EOT assert_block(full_message) { expected == actual } end - # Passes if block raises exception. + # Passes if block raises one of the given exceptions. public - def assert_raises(*args) + def assert_raise(*args) _wrap_assertion do if Class === args.last message = "" @@ -85,6 +85,12 @@ EOT end end + # Alias of assert_raise. Will be deprecated in 1.9, and removed in 2.0. + public + def assert_raises(*args, &block) + assert_raise(*args, &block) + end + # Passes if object.class == klass. public def assert_instance_of(klass, object, message="") diff --git a/test/testunit/test_assertions.rb b/test/testunit/test_assertions.rb index 6d0283174c..999376e765 100644 --- a/test/testunit/test_assertions.rb +++ b/test/testunit/test_assertions.rb @@ -104,37 +104,37 @@ module Test end end - def test_assert_raises + def test_assert_raise return_value = nil check_nothing_fails(true) { - return_value = assert_raises(RuntimeError) { + return_value = assert_raise(RuntimeError) { raise "Error" } } - check(return_value.kind_of?(Exception), "Should have returned the exception from a successful assert_raises") - check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raises") + check(return_value.kind_of?(Exception), "Should have returned the exception from a successful assert_raise") + check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise") check_nothing_fails(true) { - assert_raises(ArgumentError, "successful assert_raises") { + assert_raise(ArgumentError, "successful assert_raise") { raise ArgumentError.new("Error") } } check_nothing_fails(true) { - assert_raises(RuntimeError) { + assert_raise(RuntimeError) { raise "Error" } } check_nothing_fails(true) { - assert_raises(RuntimeError, "successful assert_raises") { + assert_raise(RuntimeError, "successful assert_raise") { raise "Error" } } check_fails(" exception expected but none was thrown.") { - assert_raises(RuntimeError) { + assert_raise(RuntimeError) { 1 + 1 } } - check_fails(%r{\Afailed assert_raises.\n exception expected but was\nClass: \nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) { - assert_raises(ArgumentError, "failed assert_raises") { + check_fails(%r{\Afailed assert_raise.\n exception expected but was\nClass: \nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) { + assert_raise(ArgumentError, "failed assert_raise") { raise "Error" } } @@ -147,26 +147,26 @@ module Test exceptions = [ArgumentError, TypeError] exceptions.each do |exc| check_nothing_fails(true) { - return_value = assert_raises(*exceptions) { + return_value = assert_raise(*exceptions) { raise exc, "Error" } } check(return_value.instance_of?(exc), "Should have returned #{exc} but was #{return_value.class}") - check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raises") + check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise") end check_fails("<[ArgumentError, TypeError]> exception expected but none was thrown.") { - assert_raises(*exceptions) { + assert_raise(*exceptions) { 1 + 1 } } - check_fails(%r{\Afailed assert_raises. + check_fails(%r{\Afailed assert_raise. <\[ArgumentError, TypeError\]> exception expected but was Class: Message: <"Error"> ---Backtrace--- .+ ---------------\Z}m) { - assert_raises(ArgumentError, TypeError, "failed assert_raises") { + assert_raise(ArgumentError, TypeError, "failed assert_raise") { raise "Error" } }