class 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

@private

# File rspec-expectations/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
# File rspec-expectations/lib/rspec/matchers/built_in/operators.rb, line 41
def initialize(actual)
  @actual = actual
end

@private

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

@private

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

@private

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

@private

# File rspec-expectations/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

@api private @return [String]

# File rspec-expectations/lib/rspec/matchers/built_in/operators.rb, line 76
def description
  "#{@operator} #{RSpec::Support::ObjectFormatter.format(@expected)}"
end

@private

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