summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-04 17:49:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-04 17:49:39 +0000
commit01d06638b96eefdb5f6bd019289f1e479d3c5723 (patch)
treeade4b7aff3ab91ab2c1ad1e43ce95873955dde1c
parente78a9cdcdb05a9f196b4c76c119626e519946888 (diff)
* lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises):
allow multiple exception list. [ruby-core:01884] * lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_nothing_raised): check whether arguments are subclass of Exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--lib/test/unit/assertions.rb34
2 files changed, 30 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 65fca1dded..e20cdec9ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Dec 5 02:49:35 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises):
+ allow multiple exception list. [ruby-core:01884]
+
+ * lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_nothing_raised):
+ check whether arguments are subclass of Exception.
+
Thu Dec 4 21:50:07 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/drb/drb.rb (DRb::DRbMessage::send_request, send_reply):
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb
index 3c2f7b98c0..02126badca 100644
--- a/lib/test/unit/assertions.rb
+++ b/lib/test/unit/assertions.rb
@@ -58,23 +58,29 @@ EOT
# Passes if block raises exception.
public
- def assert_raises(expected_exception_klass, message="")
+ def assert_raises(*args)
_wrap_assertion do
- assert_instance_of(Class, expected_exception_klass, "Should expect a class of exception")
+ if Class === args.last and Exception >= args.last
+ message = ""
+ else
+ message = args.pop
+ end
+ args.each do |klass|
+ assert(Exception >= klass, "Should expect a class of exception")
+ end
+ expected = args.size == 1 ? args.first : args
actual_exception = nil
- full_message = build_message(message, "<?> exception expected but none was thrown.", expected_exception_klass)
+ full_message = build_message(message, "<?> exception expected but none was thrown.", expected)
assert_block(full_message) do
- thrown = false
begin
yield
- rescue Exception => thrown_exception
- actual_exception = thrown_exception
- thrown = true
+ rescue Exception => actual_exception
+ break
end
- thrown
+ false
end
- full_message = build_message(message, "<?> exception expected but was\n?", expected_exception_klass, actual_exception)
- assert_block(full_message) { expected_exception_klass == actual_exception.class }
+ full_message = build_message(message, "<?> exception expected but was\n?", expected, actual_exception)
+ assert_block(full_message) { args.include?(actual_exception.class) }
actual_exception
end
end
@@ -176,10 +182,14 @@ EOT
public
def assert_nothing_raised(*args)
_wrap_assertion do
- message = ""
- if (!args[-1].instance_of?(Class))
+ if Class === args.last and Exception >= args.last
+ message = ""
+ else
message = args.pop
end
+ args.each do |klass|
+ assert(Exception >= klass, "Should expect a class of exception")
+ end
begin
yield
rescue Exception => e