Skip to content
Browse files

Make expect(a).to be_within(x).percent_of(y) work with integer x and y

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information...
1 parent 82f05dd commit 4b0a77ec507d60515c18eef20c664b66a1d49318 @samphippen samphippen committed
Showing with 5 additions and 1 deletion.
  1. +1 −1 lib/rspec/matchers/built_in/be_within.rb
  2. +4 −0 spec/rspec/matchers/be_within_spec.rb
View
2 lib/rspec/matchers/built_in/be_within.rb
@@ -23,7 +23,7 @@ def of(expected)
def percent_of(expected)
@expected = expected
- @tolerance = @delta * @expected / 100
+ @tolerance = @delta * @expected / 100.0
@unit = '%'
self
end
View
4 spec/rspec/matchers/be_within_spec.rb
@@ -27,6 +27,10 @@ module Matchers
expect(5.5).to be_within(0.5).of(5.0)
end
+ it "passes with integer arguments that are near each other" do
+ expect(1.0001).to be_within(5).percent_of(1)
+ end
+
it "fails when actual < (expected - delta)" do
expect {
expect(4.49).to be_within(0.5).of(5.0)

0 comments on commit 4b0a77e

Please sign in to comment.
Something went wrong with that request. Please try again.