summaryrefslogtreecommitdiff
path: root/lib/test/unit
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-23 09:18:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-23 09:18:47 +0000
commitd5d8097afd6c7f23e80d9b77675990d5aaa47317 (patch)
tree9b1b4c77d388a3bc515ad4d31d94d873c895a79b /lib/test/unit
parentc8a7730c7d8e948147059f0ac7c9268fb03c53bc (diff)
assertions.rb: allow proc
* lib/test/unit/assertions.rb (assert_raise): allow a proc as message like as other assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test/unit')
-rw-r--r--lib/test/unit/assertions.rb32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb
index 9e3cadcba9..7fdd61dd55 100644
--- a/lib/test/unit/assertions.rb
+++ b/lib/test/unit/assertions.rb
@@ -63,8 +63,36 @@ module Test
# assert_raise NameError do
# puts x #Raises NameError, so assertion succeeds
# end
- def assert_raise(*args, &b)
- assert_raises(*args, &b)
+ def assert_raise(*exp, &b)
+ case exp.last
+ when String, Proc
+ msg = exp.pop
+ end
+
+ begin
+ yield
+ rescue MiniTest::Skip => e
+ return e if exp.include? MiniTest::Skip
+ raise e
+ rescue Exception => e
+ expected = exp.any? { |ex|
+ if ex.instance_of? Module then
+ e.kind_of? ex
+ else
+ e.instance_of? ex
+ end
+ }
+
+ assert expected, proc {
+ exception_details(e, message(msg) {"#{mu_pp(exp)} exception expected, not"}.call)
+ }
+
+ return e
+ end
+
+ exp = exp.first if exp.size == 1
+
+ flunk(message(msg) {"#{mu_pp(exp)} expected but nothing was raised."})
end
# :call-seq: