mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises,
Test::Unit::Assertions::assert_nothing_raised): use the last argument as message unless non-class object. * test/testunit/test_assertions.rb (test_assert_raises): test for multiple exception list. [ruby-core:01891] * test/testunit/test_assertions.rb (test_assert_nothing_raised): test for non-exception classes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1ed39b7392
commit
33f0b0ae0b
3 changed files with 53 additions and 4 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Fri Dec 5 23:22:30 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises,
|
||||
Test::Unit::Assertions::assert_nothing_raised): use the last
|
||||
argument as message unless non-class object.
|
||||
|
||||
* test/testunit/test_assertions.rb (test_assert_raises): test for
|
||||
multiple exception list. [ruby-core:01891]
|
||||
|
||||
* test/testunit/test_assertions.rb (test_assert_nothing_raised): test
|
||||
for non-exception classes.
|
||||
|
||||
Fri Dec 5 22:23:04 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||
|
||||
* lib/soap/netHttpClient.rb: proxy support did not work. fixed.
|
||||
|
|
|
@ -60,13 +60,13 @@ EOT
|
|||
public
|
||||
def assert_raises(*args)
|
||||
_wrap_assertion do
|
||||
if Class === args.last and Exception >= args.last
|
||||
if Class === args.last
|
||||
message = ""
|
||||
else
|
||||
message = args.pop
|
||||
end
|
||||
args.each do |klass|
|
||||
assert(Exception >= klass, "Should expect a class of exception")
|
||||
assert(Exception >= klass, "Should expect a class of exception, #{klass}")
|
||||
end
|
||||
expected = args.size == 1 ? args.first : args
|
||||
actual_exception = nil
|
||||
|
@ -182,13 +182,13 @@ EOT
|
|||
public
|
||||
def assert_nothing_raised(*args)
|
||||
_wrap_assertion do
|
||||
if Class === args.last and Exception >= args.last
|
||||
if Class === args.last
|
||||
message = ""
|
||||
else
|
||||
message = args.pop
|
||||
end
|
||||
args.each do |klass|
|
||||
assert(Exception >= klass, "Should expect a class of exception")
|
||||
assert(Exception >= klass, "Should expect a class of exception, #{klass}")
|
||||
end
|
||||
begin
|
||||
yield
|
||||
|
|
|
@ -138,6 +138,38 @@ module Test
|
|||
raise "Error"
|
||||
}
|
||||
}
|
||||
check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
|
||||
assert_nothing_raised(Object) {
|
||||
1 + 1
|
||||
}
|
||||
}
|
||||
|
||||
exceptions = [ArgumentError, TypeError]
|
||||
exceptions.each do |exc|
|
||||
check_nothing_fails(true) {
|
||||
return_value = assert_raises(*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")
|
||||
end
|
||||
check_fails("<[ArgumentError, TypeError]> exception expected but none was thrown.") {
|
||||
assert_raises(*exceptions) {
|
||||
1 + 1
|
||||
}
|
||||
}
|
||||
check_fails(%r{\Afailed assert_raises.
|
||||
<\[ArgumentError, TypeError\]> exception expected but was
|
||||
Class: <RuntimeError>
|
||||
Message: <"Error">
|
||||
---Backtrace---
|
||||
.+
|
||||
---------------\Z}m) {
|
||||
assert_raises(ArgumentError, TypeError, "failed assert_raises") {
|
||||
raise "Error"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_assert_instance_of
|
||||
|
@ -272,6 +304,11 @@ module Test
|
|||
rescue ZeroDivisionError
|
||||
end
|
||||
}
|
||||
check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
|
||||
assert_nothing_raised(Object) {
|
||||
1 + 1
|
||||
}
|
||||
}
|
||||
check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
assert_nothing_raised {
|
||||
raise "Error"
|
||||
|
|
Loading…
Reference in a new issue