class ArgumentSpecification::Matchers::BeComparedTo
Attributes
expected[R]
operator[R]
Public Class Methods
new(operator, expected)
click to toggle source
Create a new matcher instance
Arguments:
operator: (Symbol) expected: (Object)
Example:
>> ArgumentSpecification::Matchers::BeComparedTo.new(:==, 10) => #<ArgumentSpecification::Matchers::BeComparedTo:0x00000000000000 @operator=:==, @expected=10>
# File lib/argspec/matchers/be_compared_to.rb, line 16 def initialize(operator, expected) @operator = operator @expected = expected end
Public Instance Methods
failure_message()
click to toggle source
The failure message when using ‘should’
Example:
>> matcher.failure_message => "':foo' should be equal to ':test'"
# File lib/argspec/matchers/be_compared_to.rb, line 27 def failure_message actual = prettify_args(@actual) "'#{actual}' should #{pretty_matcher} '#{@expected}'" end
failure_message_when_negated()
click to toggle source
The failure message when using ‘should not’
Example:
>> matcher.failure_message_when_negated => "':test' should not be equal to ':test'"
# File lib/argspec/matchers/be_compared_to.rb, line 39 def failure_message_when_negated actual = prettify_args(@actual) "'#{actual}' should not #{pretty_matcher} '#{@expected}'" end
matches?()
click to toggle source
Check if the actual object matches
Example:
>> matcher.matches? => true
# File lib/argspec/matchers/be_compared_to.rb, line 51 def matches? begin @actual.send(@operator, @expected) rescue ArgumentError false end end
Private Instance Methods
pretty_matcher()
click to toggle source
Get the pretty matcher name
Example:
>> matcher = BeComparedTo.new(:==, 1) >> matcher.pretty_matcher => "equal"
# File lib/argspec/matchers/be_compared_to.rb, line 67 def pretty_matcher case @operator when :== "equal" when :=== "case equal" when :=~ "match" when :< "be less than" when :> "be greater than" when :<= "be less than or equal to" when :>= "be greater than or equal to" else "pass comparison #{@operator} to" end end