Class: RSpec::Matchers::BuiltIn::OperatorMatcher

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::get
- ::new
- ::register
- ::registry
- ::unregister
- ::use_custom_matcher_or_delegate
- #description
- #fail_with_message

### 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::OperatorMatcher

@api private Provides the implementation for operator matchers. Not intended to be instantiated directly. Only available for use with `should`.

### Public Class Methods

get(klass, operator) click to toggle source

@private

    # File lib/rspec/matchers/built_in/operators.rb, line 29
    def get(klass, operator)
      klass.ancestors.each do |ancestor|
        matcher = registry[ancestor] && registry[ancestor][operator]
        return matcher if matcher
      end

      nil
    end

new(actual) click to toggle source

    # File lib/rspec/matchers/built_in/operators.rb, line 41
    def initialize(actual)
      @actual = actual
    end

register(klass, operator, matcher) click to toggle source

@private

    # File lib/rspec/matchers/built_in/operators.rb, line 18
    def register(klass, operator, matcher)
      registry[klass] ||= {}
      registry[klass][operator] = matcher
    end

registry() click to toggle source

@private

    # File lib/rspec/matchers/built_in/operators.rb, line 13
    def registry
      @registry ||= {}
    end

unregister(klass, operator) click to toggle source

@private

    # File lib/rspec/matchers/built_in/operators.rb, line 24
    def unregister(klass, operator)
      registry[klass] && registry[klass].delete(operator)
    end

use_custom_matcher_or_delegate(operator) click to toggle source

@private

    # File lib/rspec/matchers/built_in/operators.rb, line 46
    def self.use_custom_matcher_or_delegate(operator)
      define_method(operator) do |expected|
        if !has_non_generic_implementation_of?(operator) && (matcher = OperatorMatcher.get(@actual.class, operator))
          @actual.__send__(::RSpec::Matchers.last_expectation_handler.should_method, matcher.new(expected))
        else
          eval_match(@actual, operator, expected)
        end
      end

      negative_operator = operator.sub(/^=/, '!')
      if negative_operator != operator && respond_to?(negative_operator)
        define_method(negative_operator) do |_expected|
          opposite_should = ::RSpec::Matchers.last_expectation_handler.opposite_should_method
          raise "RSpec does not support `#{::RSpec::Matchers.last_expectation_handler.should_method} #{negative_operator} expected`.  "                  "Use `#{opposite_should} #{operator} expected` instead."
        end
      end
    end

### Public Instance Methods

description() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/operators.rb, line 76
    def description
      "#{@operator} #{@expected.inspect}"
    end

fail_with_message(message) click to toggle source

@private

    # File lib/rspec/matchers/built_in/operators.rb, line 70
    def fail_with_message(message)
      RSpec::Expectations.fail_with(message, @expected, @actual)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.