mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
af2dc00300
commit
1253665ec4
3 changed files with 30 additions and 17 deletions
|
@ -1,3 +1,10 @@
|
|||
Tue Dec 9 00:45:00 2003 Nathaniel Talbott <ntalbott@ruby-lang.org>
|
||||
|
||||
* 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 <nahi@ruby-lang.org>
|
||||
|
||||
* lib/soap/rpc/standaloneServer.rb: add 'shutdown' and 'status'
|
||||
|
|
|
@ -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="")
|
||||
|
|
|
@ -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("<RuntimeError> exception expected but none was thrown.") {
|
||||
assert_raises(RuntimeError) {
|
||||
assert_raise(RuntimeError) {
|
||||
1 + 1
|
||||
}
|
||||
}
|
||||
check_fails(%r{\Afailed assert_raises.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
assert_raises(ArgumentError, "failed assert_raises") {
|
||||
check_fails(%r{\Afailed assert_raise.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\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: <RuntimeError>
|
||||
Message: <"Error">
|
||||
---Backtrace---
|
||||
.+
|
||||
---------------\Z}m) {
|
||||
assert_raises(ArgumentError, TypeError, "failed assert_raises") {
|
||||
assert_raise(ArgumentError, TypeError, "failed assert_raise") {
|
||||
raise "Error"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue