RSpec's be_within Matcher
Today I learned RSpec has a be_within matcher.
It does what it says - it verifies if the actual is within a delta (<=
)
of the expected.
expect(3.0).to be_within(0.5).of(3.0) # ✅
expect(3.2).to be_within(0.5).of(3.0) # ✅
expect(3.5).to be_within(0.5).of(3.0) # ✅
expect(4.3).to be_within(0.5).of(3.0) # ❌
Tweet