be_close(expected, delta)
public
Passes if actual == expected +/- delta
result.should be_close(3.0, 0.5)
# File lib/spec/matchers/be_close.rb, line 13
def be_close(expected, delta)
simple_matcher do |actual, matcher|
matcher.failure_message = "expected #{expected} +/- (< #{delta}), got #{actual}"
matcher.description = "be close to #{expected} (within +- #{delta})"
(actual - expected).abs < delta
end
end
1Note
- be_close(1, 0.1) is deprecated.
- please use be_within(0.1).of(1) instead.