Class: Micronaut::Matchers::BeClose

Inherits:
Object
  • Object
show all
Defined in:
lib/micronaut/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/micronaut/matchers/be_close.rb', line 5

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

Instance Method Details

#descriptionObject



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

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

#failure_messageObject



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

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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