Dream of the kind of world
you wanna live in.
Dream it out loud,
at high volume

Bono, U2

01 Nov 2012Valid fixtures


Validate your fixtures.


As mentioned in our Ploppcasts session about Testing (German only, sorry) I'm using both fixtures and factories when testing my Rails applications. One of the drawbacks from using fixtures is that these don't have to be valid in terms of ActiveModel validations. In order to make sure my fixtures are in fact valid I introduced a fixtures test, which is simply a unit test to automatically verify the fixtures' validity:

So, taken these fixtures:

the test will indicate one failure, because the fixture user_without_email is invalid. The fixture invalid_user won't be marked as failure, because its name is starting with invalid_ telling the test that it should expect an invalid fixture, and return a failure otherwise. By this, we can keep having even invalid fixtures without failing tests.

blog comments powered by Disqus

Related Posts