Skip to content

Commit

Permalink
+ Added examples to documentation for assert_raises. (lxxxvi)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 12349]
  • Loading branch information
zenspider committed Oct 20, 2019
1 parent 2716a85 commit d80a4d4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,21 @@ def assert_predicate o1, op, msg = nil
#
# +exp+ takes an optional message on the end to help explain
# failures and defaults to StandardError if no exception class is
# passed.
# passed. Eg:
#
# assert_raises(CustomError) { method_with_custom_error }
#
# With custom error message:
#
# assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
#
# Using the returned object:
#
# error = assert_raises(CustomError) do
# raise CustomError, 'This is really bad'
# end
#
# assert_equal 'This is really bad', error.message

def assert_raises *exp
flunk "assert_raises requires a block to capture errors." unless
Expand Down

0 comments on commit d80a4d4

Please sign in to comment.