Exception: Assay::DeltaFailure

Inherits:
CompareFailure show all
Defined in:
lib/assay/assertions/delta_failure.rb

Overview

TODO: Support Range

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Assertion

assert, #assert, assertable_method, #assertion?, #fail?, fail?, #initialize, #negative?, #pass?, refute, #refute, #set_arguments, #set_negative, to_matcher

Constructor Details

This class inherits a constructor from Assay::Assertion

Class Method Details

.assertion_nameObject



9
10
11
# File 'lib/assay/assertions/delta_failure.rb', line 9

def self.assertion_name
  :in_delta
end

.pass?(exp, act, delta) ⇒ Boolean

Check assertion.

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# File 'lib/assay/assertions/delta_failure.rb', line 14

def self.pass?(exp, act, delta)
  case delta
  when Numeric
    (exp.to_f - act.to_f).abs <= delta.to_f
  else
    exp - act <= delta
  end
end

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/assay/assertions/delta_failure.rb', line 24

def to_s
  return super unless @arguments.size == 3

  exp   = @arguments[0].inspect
  act   = @arguments[1].inspect
  delta = @arguments[2].inspect

  if @_negated
    "Expected #{exp} to NOT be within #{delta} of #{act}"
  else
    "Expected #{exp} to be within #{delta} of #{act}"
  end
end