From 287d2adab0ce45018ada9941ce4eaf67ba6a4d3a Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 13 Dec 2013 09:17:55 +0000 Subject: 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 --- lib/test/unit/assertions.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3