This project is archived and is in readonly mode.
Add assert_not_valid to model assertions
-
Tarmo Tänav
Why not make the messages parameter optional and not assert the specific contents of the validation errors unless it is provided?
-
Nathan Wilmes
- Title changed from [patch] Add assert_not_valid to model assertions to Add assert_not_valid to model assertions
I don't have a strong problem with that. I'd argue that this function is most useful as a way to confirm which errors you've received, but you could certainly use it for a more basic valid/not valid checker.
-
Tarmo Tänav
A couple of more questions:
1. Why not "assert_invalid"?
2. Have you thought about supporting partial error messages checks? Basically, if you have a test for a particular validation then would it not make sense to only check for the presence of that validation error and not pollute the test for one validation with the failure of some other unrelated validation? Though I have no idea what kind interface changes this may require in order to also support the current messages=expected_messages case.
-
Nathan Wilmes
1. assert_not_valid opposes assert_valid more closely.. we were attempting to mimic the naming convention of assert_not_equal/assert_equal.
2. I've thought about it, but as you said, it's easiest to support either partial or exact matches, not both. The exact match format has been more rewarding for us at Pivotal.. when unrelated validations muck up the works, we typically want to know about them so that we can start adjusting the validations accordingly.
-
Tarmo Tänav
1. I agree
2. I agree, though I still think that if there is a all-in-one assertion helper for the "test more than needed, just in case" people there should be an equivalent for those who want to test one thing and one thing only.
Anyway, about the not passing any messages, are you going to add this to the patch? If so, it's a +1 from me.
(btw. besides not running the messages assertion if the messages parameter is blank the assertion failure message for the validation check would also need a different text as it can't really report what errors it was expecting if the errors are not specified)
Thank you,
-
Nathan Wilmes
Ok, here's the updated patch that makes additional parameters optional.
-
Tarmo Tänav
Thank you. Is there a good reason for not squishing the commits in the patch?
-
Nathan Wilmes
No good reason... I've just started using git, so I'm still working out how to do some of these kinds of operations.
-
josh
- State changed from new to invalid
- Assigned user set to josh
I think we saw assert_invalid before, and it was turned down.
We already trimmed out a bunch of superfluous assert_* response helpers. When there is a helper for just about every case, it becomes so hard to remember to use them.
assert_equal company.errors.on(:email), "can't be blank"
