Summary: Failed unit tests tell me which assert (file:line) failed, but not which validation resulted in the failure.
More info: I have 11 validations in one of my models. Unit testing is great, whether I run rake test:units --trace
or ruby -Itest test/unit/mymodel_test.rb
. However, despite the fact that it tells me exactly which assert
failed me, I am not told which validation failed. I must be missing something obvious, because I can't ask Google this question well enough to get an answer.
Thanks :)
I think that what you want is this:
assert person.valid?, person.errors.full_messages.inspect
if the person model is not valid, the error messages are printed out for you to see.
In order to print one or more failed validations, use a test like this:
test "post with neither name nor title" do
p = Post.new
assert p.valid?, p.errors.full_messages.inspect
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With