зеркало из https://github.com/github/ruby.git
* 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:
Родитель
af2dc00300
Коммит
1253665ec4
|
@ -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>
|
Tue Dec 9 00:07:35 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* lib/soap/rpc/standaloneServer.rb: add 'shutdown' and 'status'
|
* lib/soap/rpc/standaloneServer.rb: add 'shutdown' and 'status'
|
||||||
|
|
|
@ -56,9 +56,9 @@ EOT
|
||||||
assert_block(full_message) { expected == actual }
|
assert_block(full_message) { expected == actual }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Passes if block raises exception.
|
# Passes if block raises one of the given exceptions.
|
||||||
public
|
public
|
||||||
def assert_raises(*args)
|
def assert_raise(*args)
|
||||||
_wrap_assertion do
|
_wrap_assertion do
|
||||||
if Class === args.last
|
if Class === args.last
|
||||||
message = ""
|
message = ""
|
||||||
|
@ -85,6 +85,12 @@ EOT
|
||||||
end
|
end
|
||||||
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.
|
# Passes if object.class == klass.
|
||||||
public
|
public
|
||||||
def assert_instance_of(klass, object, message="")
|
def assert_instance_of(klass, object, message="")
|
||||||
|
|
|
@ -104,37 +104,37 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_assert_raises
|
def test_assert_raise
|
||||||
return_value = nil
|
return_value = nil
|
||||||
check_nothing_fails(true) {
|
check_nothing_fails(true) {
|
||||||
return_value = assert_raises(RuntimeError) {
|
return_value = assert_raise(RuntimeError) {
|
||||||
raise "Error"
|
raise "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check(return_value.kind_of?(Exception), "Should have returned the 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_raises")
|
check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
|
||||||
check_nothing_fails(true) {
|
check_nothing_fails(true) {
|
||||||
assert_raises(ArgumentError, "successful assert_raises") {
|
assert_raise(ArgumentError, "successful assert_raise") {
|
||||||
raise ArgumentError.new("Error")
|
raise ArgumentError.new("Error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_nothing_fails(true) {
|
check_nothing_fails(true) {
|
||||||
assert_raises(RuntimeError) {
|
assert_raise(RuntimeError) {
|
||||||
raise "Error"
|
raise "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_nothing_fails(true) {
|
check_nothing_fails(true) {
|
||||||
assert_raises(RuntimeError, "successful assert_raises") {
|
assert_raise(RuntimeError, "successful assert_raise") {
|
||||||
raise "Error"
|
raise "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_fails("<RuntimeError> exception expected but none was thrown.") {
|
check_fails("<RuntimeError> exception expected but none was thrown.") {
|
||||||
assert_raises(RuntimeError) {
|
assert_raise(RuntimeError) {
|
||||||
1 + 1
|
1 + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_fails(%r{\Afailed assert_raises.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
check_fails(%r{\Afailed assert_raise.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||||
assert_raises(ArgumentError, "failed assert_raises") {
|
assert_raise(ArgumentError, "failed assert_raise") {
|
||||||
raise "Error"
|
raise "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,26 +147,26 @@ module Test
|
||||||
exceptions = [ArgumentError, TypeError]
|
exceptions = [ArgumentError, TypeError]
|
||||||
exceptions.each do |exc|
|
exceptions.each do |exc|
|
||||||
check_nothing_fails(true) {
|
check_nothing_fails(true) {
|
||||||
return_value = assert_raises(*exceptions) {
|
return_value = assert_raise(*exceptions) {
|
||||||
raise exc, "Error"
|
raise exc, "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check(return_value.instance_of?(exc), "Should have returned #{exc} but was #{return_value.class}")
|
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
|
end
|
||||||
check_fails("<[ArgumentError, TypeError]> exception expected but none was thrown.") {
|
check_fails("<[ArgumentError, TypeError]> exception expected but none was thrown.") {
|
||||||
assert_raises(*exceptions) {
|
assert_raise(*exceptions) {
|
||||||
1 + 1
|
1 + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_fails(%r{\Afailed assert_raises.
|
check_fails(%r{\Afailed assert_raise.
|
||||||
<\[ArgumentError, TypeError\]> exception expected but was
|
<\[ArgumentError, TypeError\]> exception expected but was
|
||||||
Class: <RuntimeError>
|
Class: <RuntimeError>
|
||||||
Message: <"Error">
|
Message: <"Error">
|
||||||
---Backtrace---
|
---Backtrace---
|
||||||
.+
|
.+
|
||||||
---------------\Z}m) {
|
---------------\Z}m) {
|
||||||
assert_raises(ArgumentError, TypeError, "failed assert_raises") {
|
assert_raise(ArgumentError, TypeError, "failed assert_raise") {
|
||||||
raise "Error"
|
raise "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче