Method: RSpec::Matchers#raise_error

Defined in:
lib/rspec/matchers.rb

#raise_error(error = Exception, message = nil, &block) ⇒ Object Also known as: raise_exception

With no args, matches if any error is raised. With a named error, matches only if that specific error is raised. With a named error and messsage specified as a String, matches only if both match. With a named error and messsage specified as a Regexp, matches only if both match. Pass an optional block to perform extra verifications on the exception matched

Examples:


expect { do_something_risky }.to raise_error
expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky")
expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/)

expect { do_something_risky }.not_to raise_error


524
525
526
# File 'lib/rspec/matchers.rb', line 524

def raise_error(error=Exception, message=nil, &block)
  BuiltIn::RaiseError.new(error, message, &block)
end