summaryrefslogtreecommitdiff
path: root/lib/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 09:17:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 09:17:55 +0000
commit287d2adab0ce45018ada9941ce4eaf67ba6a4d3a (patch)
tree066ef758e9e417f69e059a5819ce7f5689f754a5 /lib/test
parent3ba2006aa443b45aba41d4a6bc8fa82505def4d3 (diff)
downloadruby-287d2adab0ce45018ada9941ce4eaf67ba6a4d3a.tar.gz
assertions.rb: last match in assert_raise_with_message
* lib/test/unit/assertions.rb (assert_raise_with_message): set caller's last match if expected is a Regexp. * test/ruby/test_arity.rb (err_mess): use assert_raise_with_message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test')
-rw-r--r--lib/test/unit/assertions.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb
index 7da0c4e1eb..042adba6fd 100644
--- a/lib/test/unit/assertions.rb
+++ b/lib/test/unit/assertions.rb
@@ -88,7 +88,7 @@ module Test
# assert_raise_with_message(RuntimeError, "foo") do
# raise "foo" #Raises RuntimeError with the message, so assertion succeeds
# end
- def assert_raise_with_message(exception, expected, msg = nil)
+ def assert_raise_with_message(exception, expected, msg = nil, &block)
case expected
when String
assert = :assert_equal
@@ -100,7 +100,14 @@ module Test
ex = assert_raise(exception, *msg) {yield}
msg = message(msg, "") {"Expected Exception(#{exception}) was raised, but the message doesn't match"}
- __send__(assert, expected, ex.message, msg)
+
+ if assert == :assert_equal
+ assert_equal(expected, ex.message, msg)
+ else
+ msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp ex.message}" }
+ assert expected =~ ex.message, msg
+ block.binding.eval("proc{|_|$~=_}").call($~)
+ end
ex
end