diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-24 09:36:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-24 09:36:46 +0000 |
commit | df7fc7ce1b3d2749e747241c838757d9b016fcdc (patch) | |
tree | ffda0f0a37ac14ed89371e5db9e1da8c696235c6 /lib/test | |
parent | 8365138720e387c8f0f1a60712a7cd2b6219f8ff (diff) | |
download | ruby-df7fc7ce1b3d2749e747241c838757d9b016fcdc.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test')
-rw-r--r-- | lib/test/unit/assertions.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 788a2e47fb..7476c428af 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -191,7 +191,21 @@ module Test # 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 ) |