Class: RSpec::Matchers::OperatorMatcher

### Home Classes Methods

### In Files

- lib/rspec/matchers/operator_matcher.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::DeprecatedConstants
- RSpec::Expectations::Deprecation
- RSpec::Expectations::Differ
- RSpec::Expectations::ExpectationHandler
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Syntax::ExpectExpressionGenerator
- RSpec::Expectations::Syntax::ShouldExpressionGenerator
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalse
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTrue
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::Change
- 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::Has
- RSpec::Matchers::BuiltIn::Have
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::MatchArray
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::StartAndEndWith
- 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::Configuration
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::Extensions
- RSpec::Matchers::Extensions::InstanceEvalWithArgs
- RSpec::Matchers::OperatorMatcher
- RSpec::Matchers::Pretty
- Array

No matching classes.

# RSpec::Matchers::OperatorMatcher

### Public Class Methods

get(klass, operator) click to toggle source

    # File lib/rspec/matchers/operator_matcher.rb, line 18
    def get(klass, operator)
      klass.ancestors.each { |ancestor|
        matcher = registry[ancestor] && registry[ancestor][operator]
        return matcher if matcher
      }

      nil
    end

new(actual) click to toggle source

    # File lib/rspec/matchers/operator_matcher.rb, line 28
    def initialize(actual)
      @actual = actual
    end

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

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

registry() click to toggle source

    # File lib/rspec/matchers/operator_matcher.rb, line 5
    def registry
      @registry ||= {}
    end

unregister(klass, operator) click to toggle source

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

use_custom_matcher_or_delegate(operator) click to toggle source

    # File lib/rspec/matchers/operator_matcher.rb, line 32
    def self.use_custom_matcher_or_delegate(operator)
      define_method(operator) do |expected|
        if uses_generic_implementation_of?(operator) && matcher = OperatorMatcher.get(@actual.class, operator)
          @actual.__send__(::RSpec::Matchers.last_should, 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_should == :should ? :should_not : :should
          raise "RSpec does not support `#{::RSpec::Matchers.last_should} #{negative_operator} expected`.  " +
            "Use `#{opposite_should} #{operator} expected` instead."
        end
      end
    end

### Public Instance Methods

description() click to toggle source

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

fail_with_message(message) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.