Class: Spec::Matchers::BeClose

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(expected, delta) ⇒ BeClose

Returns a new instance of BeClose.



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

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

Instance Method Details

#descriptionObject



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

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

#failure_messageObject



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

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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