-
-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validate_numericality_of on failure may not provide the reason for failure #509
Comments
I did some digging around on this one and here's what I found: Using the For example, this test passes: it "passes when `only_integer` option is also specified (no shorthand)" do
the_model = define_model :example, attr: :string do
validates_numericality_of(
:attr,
only_integer: true,
greater_than_or_equal_to: 1900
)
end.new
match = matcher.is_greater_than_or_equal_to(1900)
expect(the_model).to(match)
end This test uses the same effective validation but declares it using the
it "passes when `only_integer` option is also specified using shorthand" do
the_model = define_model :example, attr: :string do
validates :attr, numericality: {
only_integer: true,
greater_than_or_equal_to: 1900
}
end.new
match = matcher.is_greater_than_or_equal_to(1900)
expect(the_model).to(match)
end So, I'm wondering if the correct behavior of the failing test should actually be |
Ok, looks like this is related to #481 |
Yes this issue is just related to the failure message and and not the actual behavior of the submatcher. |
The code does look correct (I'd expected this to be present and indeed it is, and has been there for a while), but I'd like to verify this in a test, because I think we only test the message partially (we don't test the "got error..." part of the message). |
@mcmire I started this on maurogeorge@5710a64. But I think I got a issue when we test against two or more qualifiers and the fail qualifier is not the last in the chain of methods, the message is showed like:
The cause of the error is not showed. |
Yes, you're right :) |
Given this validation
and this test:
It will fail with:
As you can see the failure message doesn't contain the validation error.
I believe this is because none of the submatchers for ValidateNumericalityOfMatcher set a default message.
Really, all of the submatchers should share the same message, and updating that message should propagate to all submatchers.
The text was updated successfully, but these errors were encountered: