Skip to content

Commit

Permalink
Improve documentation for Expectation#raises.
Browse files Browse the repository at this point in the history
I've had a number of people suggesting an extension to the API
to cope with custom exceptions that have extra constructor
parameters. However, since Mocha just passes the arguments on
to Kernel#raise, it's possible to pass in an instance of an
exception. Thus no change to the API is required, but it does
seem worthwhile pointing this out in the docs.
  • Loading branch information
floehopper committed May 13, 2010
1 parent c5736db commit eed5ff3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/mocha/expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ def returns(*values)

# :call-seq: raises(exception = RuntimeError, message = nil) -> expectation
#
# Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+.
# Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+ i.e. calls Kernel#raise(exception, message).
# object = mock()
# object.expects(:expected_method).raises(Exception, 'message')
# object.expected_method # => raises exception of class Exception and with message 'message'
# Note that if you have a custom exception class with extra constructor parameters, you can pass in an instance of the exception (just as you can for Kernel#raise).
# object = mock()
# object.expects(:expected_method).raises(MyException.new('message', 1, 2, 3))
# object.expected_method # => raises the specified instance of MyException
# May be called multiple times on the same expectation. Also see Expectation#then.
# object = mock()
# object.stubs(:expected_method).raises(Exception1).then.raises(Exception2)
Expand Down

0 comments on commit eed5ff3

Please sign in to comment.