Class: Minicrest::ComparisonMatcher Private
- Defined in:
- lib/minicrest/comparison_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for matchers that compare a value against an expected value using an operator.
Direct Known Subclasses
Instance Method Summary collapse
-
#description ⇒ String
private
Returns a description of what this matcher expects.
-
#failure_message(actual) ⇒ String
private
Returns the failure message when the match fails.
-
#initialize(expected, operator, label) ⇒ ComparisonMatcher
constructor
private
Creates a new comparison matcher.
-
#matches?(actual) ⇒ Boolean
private
Checks if actual matches the expected value using the operator.
-
#negated_failure_message(actual) ⇒ String
private
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(expected, operator, label) ⇒ ComparisonMatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new comparison matcher.
15 16 17 18 19 20 |
# File 'lib/minicrest/comparison_matcher.rb', line 15 def initialize(expected, operator, label) super() @expected = expected @operator = operator @label = label end |
Instance Method Details
#description ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a description of what this matcher expects.
37 38 39 |
# File 'lib/minicrest/comparison_matcher.rb', line 37 def description "#{@label} #{@expected.inspect}" end |
#failure_message(actual) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the failure message when the match fails.
45 46 47 |
# File 'lib/minicrest/comparison_matcher.rb', line 45 def (actual) "expected #{actual.inspect} to be #{@label} #{@expected.inspect}" end |
#matches?(actual) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if actual matches the expected value using the operator.
26 27 28 29 30 31 32 |
# File 'lib/minicrest/comparison_matcher.rb', line 26 def matches?(actual) return false unless actual.respond_to?(@operator) actual.public_send(@operator, @expected) rescue ArgumentError, NoMethodError false end |
#negated_failure_message(actual) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the failure message when a negated match fails.
53 54 55 |
# File 'lib/minicrest/comparison_matcher.rb', line 53 def (actual) "expected #{actual.inspect} not to be #{@label} #{@expected.inspect}, but it was" end |