module RSpec::Matchers
def raise_error(error=Exception, message=nil, &block)
expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/)
expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky")
expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
expect { do_something_risky }.to raise_error
@example
Pass an optional block to perform extra verifications on the exception matched
With a named error and messsage specified as a Regexp, matches only if both match.
With a named error and messsage specified as a String, matches only if both match.
With a named error, matches only if that specific error is raised.
With no args, matches if any error is raised.
def raise_error(error=Exception, message=nil, &block) BuiltIn::RaiseError.new(error, message, &block) end