Class: Spec::Matchers::OperatorMatcher
- Inherits:
-
Object
- Object
- Spec::Matchers::OperatorMatcher
show all
- Defined in:
- lib/spec/matchers/operator_matcher.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of OperatorMatcher.
25
26
27
|
# File 'lib/spec/matchers/operator_matcher.rb', line 25
def initialize(actual)
@actual = actual
end
|
Class Method Details
.get(klass, operator) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/spec/matchers/operator_matcher.rb', line 15
def get(klass, operator)
matcher = registry[klass] && registry[klass][operator]
unless matcher
parent_class = registry.keys.detect {|pc| klass <= pc }
matcher = registry[parent_class] && registry[parent_class][operator]
end
matcher
end
|
.register(klass, operator, matcher) ⇒ Object
10
11
12
13
|
# File 'lib/spec/matchers/operator_matcher.rb', line 10
def register(klass, operator, matcher)
registry[klass] ||= {}
registry[klass][operator] = matcher
end
|
6
7
8
|
# File 'lib/spec/matchers/operator_matcher.rb', line 6
def registry
@registry ||= {}
end
|
.use_custom_matcher_or_delegate(operator) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/spec/matchers/operator_matcher.rb', line 29
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
|
Instance Method Details
#description ⇒ Object
47
48
49
|
# File 'lib/spec/matchers/operator_matcher.rb', line 47
def description
"#{@operator} #{@expected.inspect}"
end
|
#fail_with_message(message) ⇒ Object
43
44
45
|
# File 'lib/spec/matchers/operator_matcher.rb', line 43
def fail_with_message(message)
Spec::Expectations.fail_with(message, @expected, @actual)
end
|