method
raise_exception
1.3.1 -
Show latest stable
-
0 notes -
Class: Spec::Matchers
- 1.1.4
- 1.1.12
- 1.2.0
- 1.2.8
- 1.3.0 (0)
- 1.3.1 (0)
- What's this?
raise_exception(exception=Exception, message=nil, &block)
public
With no args, matches if any exception is raised. With a named exception, matches only if that specific exception is raised. With a named exception and messsage specified as a String, matches only if both match. With a named exception and messsage specified as a Regexp, matches only if both match. Pass an optional block to perform extra verifications on the exception matched
Examples
lambda { do_something_risky }.should raise_exception lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError) lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError) { |exception| exception.data.should == 42 } lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError, "that was too risky") lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError, /oo ri/) lambda { do_something_risky }.should_not raise_exception lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError) lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError, "that was too risky") lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError, /oo ri/)