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
This commit is contained in:
parent
8365138720
commit
df7fc7ce1b
@ -191,7 +191,21 @@ module Test
|
|||||||
# assert_throw(tag, "#{tag} was not thrown!") do
|
# assert_throw(tag, "#{tag} was not thrown!") do
|
||||||
# throw tag
|
# throw tag
|
||||||
# end
|
# 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:
|
# :call-seq:
|
||||||
# assert_equal( expected, actual, failure_message = nil )
|
# assert_equal( expected, actual, failure_message = nil )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user