Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Add Factorygirl as an alternative to fixtures #1279
FactoryGirl is a widely used alternative to fixtures in tests. The fixtures are annoying since every time you want to test something slightly different (for example, a diary entry with an apostrophe in its title), you need to add a whole new fixture and rework the tests. Fixtures are also a pain when the model attributes change.
This PR adds FactoryGirl, and reworks two model tests (DiaryEntry and DiaryComment) to use them.
Thanks for the comments. One of the problems is that the original tests are a bit pointless - they are mostly asserting that the fixtures have loaded, or that Rails itself is working (e.g. build a model from attributes, whatdoyouknow, the model has those attributes). The refactored versions are still mostly trivial, and often a bit pointless too.
I would prefer to rewrite most of these tests completely to test our "business logic" instead. But I was wary of trying to do too many things at once, since I'm always suspicious when people start rewriting tests instead of refactoring them!
I'll fix the specific points you've raised, and make a separate PR with some more thorough rewriting.
Yes I always find that a lot of model tests involve a fair bit of "what exactly are we really testing here" head scratching...
I mean obviously if you have a method with some additional logic in it on a model that's fine and can be tested but a lot of the time the tests as you say seem to be testing rails more than our code. I think things that make sense in a model test are:
On the other handing, testing that