Class: Philiprehberger::Approx::RSpecMatchers::BeApproxMatcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/approx/rspec_matchers.rb

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.

Instance Method Summary collapse

Constructor Details

#initialize(expected, epsilon, rel_tol = 0) ⇒ BeApproxMatcher

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 BeApproxMatcher.



31
32
33
34
35
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 31

def initialize(expected, epsilon, rel_tol = 0)
  @expected = expected
  @epsilon = epsilon
  @rel_tol = rel_tol
end

Instance Method Details

#descriptionObject

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.



42
43
44
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 42

def description
  "be approximately equal to #{@expected.inspect} (#{tolerance_description})"
end

#failure_messageObject

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.



46
47
48
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 46

def failure_message
  "expected #{@actual.inspect} to be approximately equal to #{@expected.inspect} (#{tolerance_description})"
end

#failure_message_when_negatedObject

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.



50
51
52
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 50

def failure_message_when_negated
  "expected #{@actual.inspect} not to be approximately equal to #{@expected.inspect} (#{tolerance_description})"
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.

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 37

def matches?(actual)
  @actual = actual
  Approx.equal?(actual, @expected, epsilon: @epsilon, rel_tol: @rel_tol)
end