0

Fixtures, factories, ... etc don't execute the real create() method. For instance, when an user is created, I generate a Preference object for him. But with fixtures I have to do it manually.

So could I do it with a script like all of my `User.create(:name => 'joe')? Or is there a popular gem who do that?

Thanks.

Dorian
  • 22,759
  • 8
  • 120
  • 116

1 Answers1

2

Factory Girl is a drop-in replacement for fixtures which allows associations that can be use as-is or can be overriden in your unit tests. It is pure ruby and as you can fine-tune at runtime the way objects are instantiated it is much more flexible than fixtures IMHO. By the way using Factory Girl with a mock framework (such as Mocha) avoids database hits therefore allow (much) faster tests.

Jef
  • 5,424
  • 26
  • 28
  • After watching Mocho, Factory Girl and Machinist. I think Mocha is good for performance but my team will not understand how it works. And the Machinist syntax is much better than the Factory Girl one. And I found that I can do `if Rails.env == 'development' ... load fixtures with Machinist` in seeds.rb so I can do exactly what I wanted. – Dorian Mar 23 '12 at 11:50