Class: ArgumentSpecification::Matchers::BeComparedTo
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- ArgumentSpecification::Matchers::BeComparedTo
- Defined in:
- lib/argspec/matchers/be_compared_to.rb
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#failure_message ⇒ Object
The failure message when using ‘should’.
-
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’.
-
#initialize(operator, expected) ⇒ BeComparedTo
constructor
Create a new matcher instance.
-
#matches? ⇒ Boolean
Check if the actual object matches.
Methods inherited from BaseMatcher
Constructor Details
#initialize(operator, expected) ⇒ BeComparedTo
Create a new matcher instance
Arguments:
operator: (Symbol)
expected: (Object)
Example:
>> ArgumentSpecification::Matchers::BeComparedTo.new(:==, 10)
=> #<ArgumentSpecification::Matchers::BeComparedTo:0x00000000000000 @operator=:==, @expected=10>
16 17 18 19 |
# File 'lib/argspec/matchers/be_compared_to.rb', line 16 def initialize(operator, expected) @operator = operator @expected = expected end |
Instance Attribute Details
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
4 5 6 |
# File 'lib/argspec/matchers/be_compared_to.rb', line 4 def expected @expected end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
4 5 6 |
# File 'lib/argspec/matchers/be_compared_to.rb', line 4 def operator @operator end |
Instance Method Details
#failure_message ⇒ Object
The failure message when using ‘should’
Example:
>> matcher.
=> "':foo' should be equal to ':test'"
27 28 29 30 31 |
# File 'lib/argspec/matchers/be_compared_to.rb', line 27 def actual = prettify_args(@actual) "'#{actual}' should #{pretty_matcher} '#{@expected}'" end |
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’
Example:
>> matcher.
=> "':test' should not be equal to ':test'"
39 40 41 42 43 |
# File 'lib/argspec/matchers/be_compared_to.rb', line 39 def actual = prettify_args(@actual) "'#{actual}' should not #{pretty_matcher} '#{@expected}'" end |
#matches? ⇒ Boolean
Check if the actual object matches
Example:
>> matcher.matches?
=> true
51 52 53 54 55 56 57 |
# File 'lib/argspec/matchers/be_compared_to.rb', line 51 def matches? begin @actual.send(@operator, @expected) rescue ArgumentError false end end |