Class: Spec::Matchers::BeClose

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/be_close.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected, delta) ⇒ BeClose

Returns a new instance of BeClose.



5
6
7
# File 'lib/spec/matchers/be_close.rb', line 5

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

Instance Method Details

#descriptionObject



18
19
20
# File 'lib/spec/matchers/be_close.rb', line 18

def description
  "be close to #{@expected} (within +- #{@delta})"
end

#failure_message_for_shouldObject



14
15
16
# File 'lib/spec/matchers/be_close.rb', line 14

def failure_message_for_should
  "expected #{@expected} +/- (< #{@delta}), got #{@actual}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/spec/matchers/be_close.rb', line 9

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