summaryrefslogtreecommitdiffstats
path: root/test/testunit
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-05 14:22:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-05 14:22:36 +0000
commit4f89030a9131f1a11847c9cf48395990d6456f57 (patch)
tree4b69d89a9a3447af135a21e1b3b6d3c6431112c0 /test/testunit
parentf3ccb50d2713fdb94d4785fcfff37bc42b743e6f (diff)
downloadruby-4f89030a9131f1a11847c9cf48395990d6456f57.tar.gz
ruby-4f89030a9131f1a11847c9cf48395990d6456f57.tar.xz
ruby-4f89030a9131f1a11847c9cf48395990d6456f57.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@5122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/testunit')
-rw-r--r--test/testunit/test_assertions.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/testunit/test_assertions.rb b/test/testunit/test_assertions.rb
index f62a6186e..6d0283174 100644
--- a/test/testunit/test_assertions.rb
+++ b/test/testunit/test_assertions.rb
@@ -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"