Flowdock
method

raise_exception

Importance_2
1.3.0 - Show latest stable - 0 notes - Class: Spec::Matchers
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/)
Show source
Register or log in to add new notes.