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

assertions.rb: assert_nothing_thrown returns the result

* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_nothing_thrown):
  returns the result of the given block.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-09-17 06:52:33 +00:00
parent 4afabb5a88
commit 246ff7cb68
2 changed files with 9 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Tue Sep 17 15:52:32 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_nothing_thrown):
returns the result of the given block.
Tue Sep 17 12:55:58 2013 Eric Hodel <drbrain@segment7.net> Tue Sep 17 12:55:58 2013 Eric Hodel <drbrain@segment7.net>
* doc/regexp.rdoc: [DOC] Replace paragraphs in verbatim sections with * doc/regexp.rdoc: [DOC] Replace paragraphs in verbatim sections with

View file

@ -149,7 +149,8 @@ module Test
# :call-seq: # :call-seq:
# assert_nothing_thrown( failure_message = nil, &block ) # assert_nothing_thrown( failure_message = nil, &block )
# #
#Fails if the given block uses a call to Kernel#throw. #Fails if the given block uses a call to Kernel#throw, and
#returns the result of the block otherwise.
# #
#An optional failure message may be provided as the final argument. #An optional failure message may be provided as the final argument.
# #
@ -158,13 +159,14 @@ module Test
# end # end
def assert_nothing_thrown(msg=nil) def assert_nothing_thrown(msg=nil)
begin begin
yield ret = yield
rescue ArgumentError => error rescue ArgumentError => error
raise error if /\Auncaught throw (.+)\z/m !~ error.message raise error if /\Auncaught throw (.+)\z/m !~ error.message
msg = message(msg) { "<#{$1}> was thrown when nothing was expected" } msg = message(msg) { "<#{$1}> was thrown when nothing was expected" }
flunk(msg) flunk(msg)
end end
assert(true, "Expected nothing to be thrown") assert(true, "Expected nothing to be thrown")
ret
end end
# :call-seq: # :call-seq: