1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

assertions.rb: assert_throw

* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_throw):
  assertion for throw.  MiniTest::Assertions#assert_throws discards
  the cautht value.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-09-17 06:53:21 +00:00
parent 246ff7cb68
commit 91d28c4ffb
2 changed files with 24 additions and 1 deletions

View file

@ -1,4 +1,8 @@
Tue Sep 17 15:52:32 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
Tue Sep 17 15:53:20 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_throw):
assertion for throw. MiniTest::Assertions#assert_throws discards
the cautht value.
* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_nothing_thrown):
returns the result of the given block.

View file

@ -169,6 +169,25 @@ module Test
ret
end
# :call-seq:
# assert_throw( tag, failure_message = nil, &block )
#
#Fails unless the given block throws +tag+, returns the caught
#value otherwise.
#
#An optional failure message may be provided as the final argument.
#
# tag = Object.new
# assert_throw(tag, "#{tag} was not thrown!") do
# throw tag
# end
def assert_throw(tag, msg = nil)
catch(tag) do
yield(tag)
assert(false, message(msg) {"Expected #{mu_pp(tag)} to have been thrown"})
end
end
# :call-seq:
# assert_equal( expected, actual, failure_message = nil )
#