Hi there, I’ve got a little question regarding rspec and the way I ought
to test models.
Let’s say I’ve got the following test: 5797’s gists · GitHub
It ensures the identity model is validated and returns an error if the
login is too short.
This test doesn’t cover one thing though: if I change
validates_lenght_of :login, :minimum => 4 to validates_length_of :login,
:minimum => 4, :on => :create it still passes, but I’d like it to fail.
The most straight-forward solution would be to add a specification with
update_identity instead of new_identity to see whether this validation
is run on update.
This doesn’t seem dry though, as I need to do some copy & paste.
Is there any preferable solution to this kind of problem?
Do the most straight-forward thing. DRY is not a useful concern in
writing tests. Being explicit about the behavior of the code under
test is more important. Test that the login is valid on update in
either case. Test that it is valid on create when 4 or longer and
invalid when 3 or less.
If you change the behavior of your code, you’ll have to write new
tests for the new behavior. That’s sort of the point of testing.
On Aug 17, 10:57 am, Mateusz Drozdzynski <rails-mailing-l…@andreas-