class Mocha::Expectation
def raises(exception = RuntimeError, message = nil)
- Example: Raise an exception on first invocation of expected method and then return values on subsequent invocations. -
Example: Raise different exceptions on consecutive invocations of the expected method. -
Example: Raise custom exception with extra constructor parameters by passing in an instance of the exception. -
Example: Raise specified exception if expected method is invoked. -
Overloads:
-
def raises(exception, message) -
def raises(exception) -
def raises
Other tags:
- See: #then -
See: Kernel#raise -
Returns:
-
(Expectation)- the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
Parameters:
-
message(String) -- exception message. -
exception(Class, Exception, String, #exception) -- exception to be raised or message to be passed to RuntimeError.
def raises(exception = RuntimeError, message = nil) @return_values += ReturnValues.new(ExceptionRaiser.new(exception, message)) self end