Test factories first
In blog thoughtbot team outlined how they test their factories first. I like this approach. Since we prefer using minitest here is how we implemented it. It is similar to how the thoughtbot blog has described. However I still want to blog about it so that in our other projects we can use similar approach.
spec directory create a file called
factories_spec.rb . Here is how our file looks.
Next I need to tell rake to always run this test file first.
When rake command is executed then it goes through all the
.rake and loads them. So all we need to do is to create a rake file called
factory.rake and put this file under
Here a dependency is being added to
test . And if factory test fails then dependency is not met and the main test suite will not run.
That’s it. Now each unit test does not need to test factory first. All factories are getting tested here.