Skip to content
Browse files

Merge pull request #145 from zhangsu/master

Fix confusing error message in `be_within`
  • Loading branch information...
2 parents 5626043 + 675115d commit d186bf8174c5f75941f0dd64aa43b2e5d0ddb1c9 @justinko justinko committed May 16, 2012
Showing with 7 additions and 0 deletions.
  1. +3 −0 lib/rspec/matchers/built_in/be_within.rb
  2. +4 −0 spec/rspec/matchers/be_within_spec.rb
View
3 lib/rspec/matchers/built_in/be_within.rb
@@ -14,6 +14,9 @@ def matches?(actual)
unless defined?(@expected)
raise ArgumentError.new("You must set an expected value using #of: be_within(#{delta}).of(expected_value)")
end
+ unless actual.is_a? Numeric
+ raise ArgumentError, "Expected a numeric value be within #{delta} of #{expected} but got #{actual.inspect}"
@alexch
alexch added a note Jun 20, 2012

I think you mean "Expected a numeric value within delta of expected" (you have an extra "be" in there)

@alexch
alexch added a note Jun 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ end
(super(actual) - expected).abs <= delta
end
View
4 spec/rspec/matchers/be_within_spec.rb
@@ -59,6 +59,10 @@ module Matchers
matcher = be_within(0.5)
expect { matcher.matches?(5.1) }.to raise_error(ArgumentError, /must set an expected value using #of/)
end
+
+ it "raises an error if the actual value is not numeric" do
+ expect { be_within(0.1).of(0).matches?(nil) }.to raise_error(ArgumentError, /Expected a numeric value be within/)
+ end
end
end
end

0 comments on commit d186bf8

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