Class: RSpec::Matchers::BuiltIn::RaiseError

### Home Classes Methods

### In Files

- lib/rspec/matchers/built_in/raise_error.rb

### Parent

Object

### Methods

- ::new
- #description
- #does_not_match?
- #expects_call_stack_jump?
- #failure_message
- #failure_message_when_negated
- #matches?
- #supports_block_expectations?
- #with_message

### Included Modules

- RSpec::Matchers::Composable

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::BlockExpectationTarget
- RSpec::Expectations::Configuration
- RSpec::Expectations::ExpectationHelper
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::LegacyMacherAdapter
- RSpec::Expectations::LegacyMatcherAdapter
- RSpec::Expectations::LegacyMatcherAdapter::RSpec1
- RSpec::Expectations::LegacyMatcherAdapter::RSpec2
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::AliasedMatcher
- RSpec::Matchers::AliasedMatcherWithOperatorSupport
- RSpec::Matchers::AliasedNegatedMatcher
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::All
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeBetween
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalsey
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTruthy
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::CaptureStderr
- RSpec::Matchers::BuiltIn::CaptureStdout
- RSpec::Matchers::BuiltIn::CaptureStreamToTempfile
- RSpec::Matchers::BuiltIn::Change
- RSpec::Matchers::BuiltIn::ChangeDetails
- RSpec::Matchers::BuiltIn::ChangeFromValue
- RSpec::Matchers::BuiltIn::ChangeRelatively
- RSpec::Matchers::BuiltIn::ChangeToValue
- RSpec::Matchers::BuiltIn::Compound
- RSpec::Matchers::BuiltIn::Compound::And
- RSpec::Matchers::BuiltIn::Compound::NestedEvaluator
- RSpec::Matchers::BuiltIn::Compound::Or
- RSpec::Matchers::BuiltIn::Compound::SequentialEvaluator
- RSpec::Matchers::BuiltIn::ContainExactly
- RSpec::Matchers::BuiltIn::ContainExactly::PairingsMaximizer
- RSpec::Matchers::BuiltIn::Cover
- RSpec::Matchers::BuiltIn::EndWith
- RSpec::Matchers::BuiltIn::Eq
- RSpec::Matchers::BuiltIn::Eql
- RSpec::Matchers::BuiltIn::Equal
- RSpec::Matchers::BuiltIn::Exist
- RSpec::Matchers::BuiltIn::Exist::ExistenceTest
- RSpec::Matchers::BuiltIn::Has
- RSpec::Matchers::BuiltIn::HaveAttributes
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::NullCapture
- RSpec::Matchers::BuiltIn::OperatorMatcher
- RSpec::Matchers::BuiltIn::Output
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::SpecificValuesChange
- RSpec::Matchers::BuiltIn::StartAndEndWith
- RSpec::Matchers::BuiltIn::StartOrEndWith
- RSpec::Matchers::BuiltIn::StartWith
- RSpec::Matchers::BuiltIn::ThrowSymbol
- RSpec::Matchers::BuiltIn::YieldControl
- RSpec::Matchers::BuiltIn::YieldProbe
- RSpec::Matchers::BuiltIn::YieldSuccessiveArgs
- RSpec::Matchers::BuiltIn::YieldWithArgs
- RSpec::Matchers::BuiltIn::YieldWithNoArgs
- RSpec::Matchers::Composable
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::DefaultImplementations
- RSpec::Matchers::DSL::Macros
- RSpec::Matchers::DSL::Macros::Deprecated
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::ExpectedsForMultipleDiffs
- RSpec::Matchers::MatcherDelegator
- RSpec::Matchers::MatcherProtocol
- RSpec::Matchers::Pretty
- BasicObject
- Object

No matching classes.

# RSpec::Matchers::BuiltIn::RaiseError

@api private Provides the implementation for `raise_error`. Not intended to be instantiated directly. rubocop:disable ClassLength

### Public Class Methods

new(expected_error_or_message=Exception, expected_message=nil, &block) click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 11
    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

### Public Instance Methods

description() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/raise_error.rb, line 88
    def description
      "raise #{expected_error}"
    end

does_not_match?(given_proc) click to toggle source

@private

    # File lib/rspec/matchers/built_in/raise_error.rb, line 60
    def does_not_match?(given_proc)
      prevent_invalid_expectations
      !matches?(given_proc, :negative_expectation) && Proc === given_proc
    end

expects_call_stack_jump?() click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 70
    def expects_call_stack_jump?
      true
    end

failure_message() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/raise_error.rb, line 76
    def failure_message
      @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
    end

failure_message_when_negated() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/raise_error.rb, line 82
    def failure_message_when_negated
      "expected no #{expected_error}#{given_error}"
    end

matches?(given_proc, negative_expectation=false, &block) click to toggle source

rubocop:disable MethodLength @private

    # File lib/rspec/matchers/built_in/raise_error.rb, line 32
    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

supports_block_expectations?() click to toggle source

@private

    # File lib/rspec/matchers/built_in/raise_error.rb, line 66
    def supports_block_expectations?
      true
    end

with_message(expected_message) click to toggle source

@api public Specifies the expected error message.

    # File lib/rspec/matchers/built_in/raise_error.rb, line 24
    def with_message(expected_message)
      raise_message_already_set if @expected_message
      @expected_message = expected_message
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.