Permalink
Browse files

Merge pull request #229 from samphippen/percent-matcher-with-integers

Make the expect(a).to be_within(x).percent_of(y) matcher work with integer x and y
  • Loading branch information...
2 parents 82f05dd + e717002 commit f12680c126c6145cb9101a87b209b3809270588a @myronmarston myronmarston committed Mar 28, 2013
Showing with 7 additions and 1 deletion.
  1. +2 −0 Changelog.md
  2. +1 −1 lib/rspec/matchers/built_in/be_within.rb
  3. +4 −0 spec/rspec/matchers/be_within_spec.rb
View
@@ -12,6 +12,8 @@ Bug fixes
* Fix differ to not raise errors when dealing with differently-encoded
strings (Jon Rowe).
+* Fix `expect(something).to be_within(x).percent_of(y)` where x and y are both
+ integers (Sam Phippen).
### 2.13.0 / 2013-02-23
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.1...v2.13.0)
@@ -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
@@ -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 f12680c

Please sign in to comment.