Class: Matchy::Expectations::BeCloseExpectation

Inherits:
Base
  • Object
show all
Defined in:
lib/matchy/built_in/truth_expectations.rb

Instance Method Summary collapse

Methods inherited from Base

#fail!, #pass!

Constructor Details

#initialize(expected, delta, test_case) ⇒ BeCloseExpectation

Returns a new instance of BeCloseExpectation.



35
36
37
38
39
# File 'lib/matchy/built_in/truth_expectations.rb', line 35

def initialize(expected, delta, test_case)
  @expected = expected
  @test_case = test_case
  @delta = delta
end

Instance Method Details

#failure_messageObject



47
48
49
# File 'lib/matchy/built_in/truth_expectations.rb', line 47

def failure_message
  "Expected #{@receiver.inspect} to be close to #{@expected.inspect} (delta: #{@delta})."
end

#matches?(receiver) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/matchy/built_in/truth_expectations.rb', line 41

def matches?(receiver)
  @receiver = receiver
  
  (receiver - @expected).abs < @delta
end

#negative_failure_messageObject



51
52
53
# File 'lib/matchy/built_in/truth_expectations.rb', line 51

def negative_failure_message
  "Expected #{@receiver.inspect} to not be close to #{@expected.inspect} (delta: #{@delta})."
end