class RSpec::Matchers::OperatorMatcher

Public Class Methods

get(klass, operator) click to toggle source
# File lib/rspec/matchers/operator_matcher.rb, line 14
def get(klass, operator)
  registry[klass] && registry[klass][operator]
end
new(actual) click to toggle source
# File lib/rspec/matchers/operator_matcher.rb, line 19
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
use_custom_matcher_or_delegate(operator) click to toggle source
# File lib/rspec/matchers/operator_matcher.rb, line 23
def self.use_custom_matcher_or_delegate(operator)
  define_method(operator) do |expected|
    if 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(%r^=/, '!')
  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 50
def description
  "#{@operator} #{@expected.inspect}"
end
fail_with_message(message) click to toggle source
# File lib/rspec/matchers/operator_matcher.rb, line 46
def fail_with_message(message)
  RSpec::Expectations.fail_with(message, @expected, @actual)
end