@api private Provides the implementation for `raise_error`. Not intended to be instantiated directly.
# File lib/rspec/matchers/built_in/raise_error.rb, line 10 def initialize(expected_error_or_message=Exception, expected_message=nil, &block) @block = block @actual_error = nil case expected_error_or_message when String, Regexp @expected_error, @expected_message = Exception, expected_error_or_message else @expected_error, @expected_message = expected_error_or_message, expected_message end end
@api private @return [String]
# File lib/rspec/matchers/built_in/raise_error.rb, line 83 def description "raise #{expected_error}" end
@private
# File lib/rspec/matchers/built_in/raise_error.rb, line 59 def does_not_match?(given_proc) prevent_invalid_expectations !matches?(given_proc, :negative_expectation) && Proc === given_proc end
@api private @return [String]
# File lib/rspec/matchers/built_in/raise_error.rb, line 71 def failure_message @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}" end
@api private @return [String]
# File lib/rspec/matchers/built_in/raise_error.rb, line 77 def failure_message_when_negated "expected no #{expected_error}#{given_error}" end
rubocop:disable MethodLength @private
# File lib/rspec/matchers/built_in/raise_error.rb, line 31 def matches?(given_proc, negative_expectation=false, &block) @given_proc = given_proc @block ||= block @raised_expected_error = false @with_expected_message = false @eval_block = false @eval_block_passed = false return false unless Proc === given_proc begin given_proc.call rescue Exception => @actual_error if values_match?(@expected_error, @actual_error) @raised_expected_error = true @with_expected_message = verify_message end end unless negative_expectation eval_block if @raised_expected_error && @with_expected_message && @block end expectation_matched? end
Generated with the Darkfish Rdoc Generator 2.