class Spec::Matchers::OperatorMatcher
def self.use_custom_matcher_or_delegate(operator)
def self.use_custom_matcher_or_delegate(operator) define_method(operator) do |expected| if matcher = OperatorMatcher.get(@actual.class, operator) @actual.send(::Spec::Matchers.last_should, matcher.new(expected)) else eval_match(@actual, operator, expected) end end end
def description
def description "#{@operator} #{@expected.inspect}" end
def eval_match(actual, operator, expected)
def eval_match(actual, operator, expected) ::Spec::Matchers.last_matcher = self @operator, @expected = operator, expected __delegate_operator(actual, operator, expected) end
def fail_with_message(message)
def fail_with_message(message) Spec::Expectations.fail_with(message, @expected, @actual) end
def get(klass, operator)
def get(klass, operator) registry[klass] && registry[klass][operator] end
def initialize(actual)
def initialize(actual) @actual = actual end
def register(klass, operator, matcher)
def register(klass, operator, matcher) registry[klass] ||= {} registry[klass][operator] = matcher end
def registry
def registry @registry ||= {} end