Skip to content

Commit

Permalink
Clearer error message for previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinko committed May 17, 2012
1 parent d186bf8 commit d55d9a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/matchers/built_in/be_within.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def matches?(actual)
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}"
raise ArgumentError, "The actual value (#{actual.inspect}) must be of a `Numeric` type"
end
(super(actual) - expected).abs <= delta
end
Expand Down
10 changes: 7 additions & 3 deletions spec/rspec/matchers/be_within_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ module Matchers

it "raises an error if no expected value is given" do
matcher = be_within(0.5)
expect { matcher.matches?(5.1) }.to raise_error(ArgumentError, /must set an expected value using #of/)
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/)
it "raises an error if the actual value is not of a Numeric type" do
expect { be_within(0.1).of(0).matches?(nil) }.to raise_error(
ArgumentError, /The actual value \(nil\) must be of a `Numeric` type/
)
end
end
end
Expand Down

0 comments on commit d55d9a8

Please sign in to comment.