Class: RSpec::Matchers::BuiltIn::BaseMatcher

### Home Classes Methods

### In Files

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

### Parent

Object

### Namespace

- MODULE RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages
- MODULE RSpec::Matchers::BuiltIn::BaseMatcher::HashFormatting

### Methods

- ::matcher_name
- ::new
- #actual_formatted
- #description
- #diffable?
- #expected_formatted
- #expects_call_stack_jump?
- #match_unless_raises
- #matches?
- #supports_block_expectations?

### Included Modules

- RSpec::Matchers::Composable
- RSpec::Matchers::BuiltIn::BaseMatcher::HashFormatting
- RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::BlockExpectationTarget
- RSpec::Expectations::Configuration
- RSpec::Expectations::ExpectationHelper
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::FailureAggregator
- RSpec::Expectations::LegacyMacherAdapter
- RSpec::Expectations::LegacyMatcherAdapter
- RSpec::Expectations::LegacyMatcherAdapter::RSpec1
- RSpec::Expectations::LegacyMatcherAdapter::RSpec2
- RSpec::Expectations::MultipleExpectationsNotMetError
- 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::BaseMatcher::HashFormatting
- 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::EnglishPhrasing
- RSpec::Matchers::ExpectedsForMultipleDiffs
- RSpec::Matchers::FailMatchers
- RSpec::Matchers::MatcherDelegator
- RSpec::Matchers::MatcherProtocol
- BasicObject
- Object

No matching classes.

# RSpec::Matchers::BuiltIn::BaseMatcher

@api private

Used internally as a base class for matchers that ship with rspec-expectations and rspec-rails.

### Warning:

This class is for internal use, and subject to change without notice. We strongly recommend that you do not base your custom matchers on this class. If/when this changes, we will announce it and remove this warning.

### Constants

UNDEFINED

  @api private Used to detect when no arg is passed to `initialize`. `nil` cannot be used because it's a valid value to pass.

### Attributes

actual[R]

@private

expected[R]

@private

rescued_exception[R]

@private

### Public Class Methods

matcher_name() click to toggle source

@private

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 94
    def self.matcher_name
      @matcher_name ||= underscore(name.split("::").last)
    end

new(expected=UNDEFINED) click to toggle source

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 25
    def initialize(expected=UNDEFINED)
      @expected = expected unless UNDEFINED.equal?(expected)
    end

### Public Instance Methods

actual_formatted() click to toggle source

@private

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 89
    def actual_formatted
      RSpec::Support::ObjectFormatter.format(@actual)
    end

description() click to toggle source

@api private Generates a description using {EnglishPhrasing}. @return [String]

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 57
    def description
      desc = EnglishPhrasing.split_words(self.class.matcher_name)
      desc << EnglishPhrasing.list(@expected) if defined?(@expected)
      desc
    end

diffable?() click to toggle source

@api private Matchers are not diffable by default. Override this to make your subclass diffable.

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 66
    def diffable?
      false
    end

expected_formatted() click to toggle source

@private

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 84
    def expected_formatted
      RSpec::Support::ObjectFormatter.format(@expected)
    end

expects_call_stack_jump?() click to toggle source

@api private

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 79
    def expects_call_stack_jump?
      false
    end

match_unless_raises(*exceptions) click to toggle source

@api private Used to wrap a block of code that will indicate failure by raising one of the named exceptions.

This is used by rspec-rails for some of its matchers that wrap rails' assertions.

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 44
    def match_unless_raises(*exceptions)
      exceptions.unshift Exception if exceptions.empty?
      begin
        yield
        true
      rescue *exceptions => @rescued_exception
        false
      end
    end

matches?(actual) click to toggle source

@api private Indicates if the match is successful. Delegates to `match`, which should be defined on a subclass. Takes care of consistently initializing the `actual` attribute.

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 33
    def matches?(actual)
      @actual = actual
      match(expected, actual)
    end

supports_block_expectations?() click to toggle source

@api private Most matchers are value matchers (i.e. meant to work with `expect(value)`) rather than block matchers (i.e. meant to work with `expect { }`), so this defaults to false. Block matchers must override this to return true.

    # File lib/rspec/matchers/built_in/base_matcher.rb, line 74
    def supports_block_expectations?
      false
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.