Class: RSpec::Matchers::BuiltIn::OperatorMatcher Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
RSpec::Matchers::BuiltIn::NegativeOperatorMatcher, RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
|
|
Inherits: | Object |
Defined in: | rspec-expectations/lib/rspec/matchers/built_in/operators.rb |
Overview
Provides the implementation for operator matchers. Not intended to be instantiated directly. Only available for use with should
.
Class Method Summary
- .get(klass, operator) Internal use only
- .new(actual) ⇒ OperatorMatcher constructor Internal use only
- .register(klass, operator, matcher) Internal use only
- .registry Internal use only
- .unregister(klass, operator) Internal use only
- .use_custom_matcher_or_delegate(operator) Internal use only
Instance Method Summary
- #description ⇒ String Internal use only
- #fail_with_message(message) Internal use only
- #eval_match(actual, operator, expected) private Internal use only
- #has_non_generic_implementation_of?(op) ⇒ Boolean private Internal use only
Class Method Details
.get(klass, operator)
[ GitHub ].register(klass, operator, matcher)
[ GitHub ].registry
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/operators.rb', line 13
def registry @registry ||= {} end
.unregister(klass, operator)
[ GitHub ].use_custom_matcher_or_delegate(operator)
[ GitHub ]# 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
Instance Method Details
#description ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/operators.rb', line 76
def description "#{@operator} #{RSpec::Support::ObjectFormatter.format(@expected)}" end
#eval_match(actual, operator, expected) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/operators.rb', line 88
def eval_match(actual, operator, expected) ::RSpec::Matchers.last_matcher = self @operator, @expected = operator, expected __delegate_operator(actual, operator, expected) end
#fail_with_message(message)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/operators.rb', line 70
def ( ) RSpec::Expectations.fail_with(, @expected, @actual) end
#has_non_generic_implementation_of?(op) ⇒ Boolean
(private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/operators.rb', line 82
def has_non_generic_implementation_of?(op) Support.method_handle_for(@actual, op).owner != ::Kernel rescue NameError false end