Class: DrLight::Matchers::CloseTo Private

Inherits:
RSpec::Matchers::BuiltIn::BaseMatcher
  • Object
show all
Defined in:
lib/dr_light/matchers/close_to.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.

Matcher checking that 2 numbers are close to each other

Author:

  • darthjee

Instance Method Summary collapse

Constructor Details

#initialize(expected, deviance) ⇒ CloseTo #initialize(expected) ⇒ CloseTo

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 new instance of CloseTo.

Overloads:

  • #initialize(expected, deviance) ⇒ CloseTo

    Parameters:

    • expected (Number)

      expected value to be close to

    • deviance (Number)

      Proximity deviance

  • #initialize(expected) ⇒ CloseTo

    Parameters:



18
19
20
21
22
23
24
# File 'lib/dr_light/matchers/close_to.rb', line 18

def initialize(expected, deviance)
  @expected = if expected.is_a?(ScientificNumber)
                expected
              else
                ScientificNumber.new(expected, deviance)
              end
end

Instance Method Details

#descriptionString

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 matcher description on success

Returns:

  • (String)


38
39
40
# File 'lib/dr_light/matchers/close_to.rb', line 38

def description
  "be close to #{expected}"
end

#failure_message_for_shouldString Also known as: failure_message

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 message for failure on should

Returns:

  • (String)


45
46
47
48
# File 'lib/dr_light/matchers/close_to.rb', line 45

def failure_message_for_should
  "expected #{actual} to be close to #{expected} but " \
    "was #{distance} deviances far away"
end

#failure_message_for_should_notString Also known as: failure_message_when_negated

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 message for failure on should not

Returns:

  • (String)


53
54
55
56
# File 'lib/dr_light/matchers/close_to.rb', line 53

def failure_message_for_should_not
  "expected #{actual} not to be close to #{expected} " \
    "but was only #{distance} deviances far away"
end

#matches?(actual) ⇒ TrueClass, FalseClass

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 if actual is close to expected

Returns:

  • (TrueClass, FalseClass)


29
30
31
32
33
# File 'lib/dr_light/matchers/close_to.rb', line 29

def matches?(actual)
  @actual = actual

  distance <= 1.0
end