diff --git a/ChangeLog b/ChangeLog index 57328b05aa..b687bf4882 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -Tue Sep 17 15:52:32 2013 Nobuyoshi Nakada +Tue Sep 17 15:53:20 2013 Nobuyoshi Nakada + + * 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. diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 0c919394ab..29b12f7ca4 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -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 ) #