add be_close matcher + TOLERANCE constant

This commit is contained in:
Laurent Sansonetti
2014-04-20 14:28:00 +02:00
parent 5ccbcde97f
commit 2268897fb2

View File

@@ -181,6 +181,17 @@ class Object
end
end
TOLERANCE = 0.00003
def be_close(expected, tolerance)
lambda do |obj, res|
if ((obj - expected).abs < tolerance) != res
puts "Expectation failed (expected `#{obj}' to be within #{expected} of tolerance #{tolerance}')"
$expectations_failures += 1
end
$expectations_total += 1
end
end
def mock(obj)
# XXX we probably should be smarter here.
obj