Class: DrLight::Matchers::CloseTo Private
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- DrLight::Matchers::CloseTo
- 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
Instance Method Summary collapse
-
#description ⇒ String
private
returns matcher description on success.
-
#failure_message_for_should ⇒ String
(also: #failure_message)
private
returns message for failure on should.
-
#failure_message_for_should_not ⇒ String
(also: #failure_message_when_negated)
private
returns message for failure on should not.
-
#initialize(expected, deviance) ⇒ CloseTo
constructor
private
A new instance of CloseTo.
-
#matches?(actual) ⇒ TrueClass, FalseClass
private
returns if actual is close to expected.
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.
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
#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 matcher description on success
38 39 40 |
# File 'lib/dr_light/matchers/close_to.rb', line 38 def description "be close to #{expected}" end |
#failure_message_for_should ⇒ String 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
45 46 47 48 |
# File 'lib/dr_light/matchers/close_to.rb', line 45 def "expected #{actual} to be close to #{expected} but " \ "was #{distance} deviances far away" end |
#failure_message_for_should_not ⇒ String 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
53 54 55 56 |
# File 'lib/dr_light/matchers/close_to.rb', line 53 def "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
29 30 31 32 33 |
# File 'lib/dr_light/matchers/close_to.rb', line 29 def matches?(actual) @actual = actual distance <= 1.0 end |