Class: Spec::Matchers::OperatorMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actual) ⇒ OperatorMatcher

Returns a new instance of OperatorMatcher.



19
20
21
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb', line 19

def initialize(actual)
  @actual = actual
end

Class Method Details

.get(klass, operator) ⇒ Object



14
15
16
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb', line 14

def get(klass, operator)
  registry[klass][operator]
end

.register(klass, operator, matcher) ⇒ Object



10
11
12
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb', line 10

def register(klass, operator, matcher)
  registry[klass][operator] = matcher
end

.registryObject



6
7
8
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb', line 6

def registry
  @registry ||= Hash.new {|h,k| h[k] = {}}
end

.use_custom_matcher_or_delegate(operator) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gems/rspec-1.1.12/lib/spec/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(::Spec::Matchers.last_should, matcher.new(expected))
    else
      ::Spec::Matchers.last_matcher = self
      @operator, @expected = operator, expected
      __delegate_operator(@actual, operator, expected)
    end
  end
end

Instance Method Details

#descriptionObject



43
44
45
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb', line 43

def description
  "#{@operator} #{@expected.inspect}"
end

#fail_with_message(message) ⇒ Object



39
40
41
# File 'lib/gems/rspec-1.1.12/lib/spec/matchers/operator_matcher.rb', line 39

def fail_with_message(message)
  Spec::Expectations.fail_with(message, @expected, @actual)
end