Class: Philiprehberger::Approx::RSpecMatchers::BeApproxWithinMatcher 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, abs, rel, percent) ⇒ BeApproxWithinMatcher

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



52
53
54
55
56
57
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 52

def initialize(expected, abs, rel, percent)
  @expected = expected
  @abs = abs
  @rel = rel
  @percent = percent
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.



69
70
71
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 69

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.



73
74
75
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 73

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.



77
78
79
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 77

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)


59
60
61
62
63
64
65
66
67
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 59

def matches?(actual)
  @actual = actual

  if @percent
    Approx.percent_equal?(actual, @expected, percent: @percent)
  else
    Approx.within?(actual, @expected, abs: @abs, rel: @rel)
  end
end