ruby-changes:32303
From: nobu <ko1@a...>
Date: Tue, 24 Dec 2013 18:36:50 +0900 (JST)
Subject: [ruby-changes:32303] nobu:r44382 (trunk): assertions.rb: improve assert_throw
nobu 2013-12-24 18:36:46 +0900 (Tue, 24 Dec 2013) New Revision: 44382 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44382 Log: assertions.rb: improve assert_throw * lib/test/unit/assertions.rb (assert_throw): revert r44379 and improve failure message, since assert_throws cannot extract the inspection from the execption message correctly. Modified files: trunk/lib/test/unit/assertions.rb Index: lib/test/unit/assertions.rb =================================================================== --- lib/test/unit/assertions.rb (revision 44381) +++ lib/test/unit/assertions.rb (revision 44382) @@ -191,7 +191,21 @@ module Test https://github.com/ruby/ruby/blob/trunk/lib/test/unit/assertions.rb#L191 # assert_throw(tag, "#{tag} was not thrown!") do # throw tag # end - alias assert_throw assert_throws + def assert_throw(tag, msg = nil) + catch(tag) do + begin + yield(tag) + rescue ArgumentError => e + raise unless thrown = e.message[/\Auncaught throw (.+)\z/m, 1] + end + msg = message(msg) { + "Expected #{mu_pp(tag)} to have been thrown"\ + "#{", not #{thrown}" if thrown}" + } + assert(false, msg) + end + assert(true) + end # :call-seq: # assert_equal( expected, actual, failure_message = nil ) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/