There seems to be few resources about the fabrication
gem, and I couldn't find a good comparison of the features that distinguish it from factory_girl
. As of versions fabrication-2.2.3
and factory_girl-4.0.0
, I can hardly find a difference. How do these gems compare? What can make fabrication
a better choice and why? Have they both converged?

- 41,555
- 36
- 141
- 182
-
I guess you could choose an answer :) – apneadiving Apr 29 '13 at 17:00
-
1@apneadiving I wish, but all the answers are either subjective or incomplete. I wish someone could post an objective comparison. – Hosam Aly Apr 29 '13 at 20:38
4 Answers
Just for what it's worth, I find fabrication to be faster, and I've experienced fewer errors with it. I think the big popularity gap is mostly because fabrication is much newer.

- 42,517
- 51
- 181
- 281
-
Thanks @Andrew. Could you please elaborate on having fewer errors? What type of errors? – Hosam Aly Aug 30 '12 at 07:03
-
4Basically with FG I ran into difficult to debug errors with associations etc. from time to time, and with Fabrication I had a lot less of that. – Andrew Aug 31 '12 at 01:41
We started out with Factory Girl, but wound up ripping it out in favour of constructing "actual" AR model instances; a decision I'm now revisiting.
So far, I like Fabricator. It seems to be easier to mock associations where absolutely nothing has to hit a real database, which never felt quite right in FG. YMMV, of course, and there's also:
Never theorise before you have data. Invariably, you end up twisting facts to suit theories, instead of theories to suit facts. — Holmes' Law of Factual Theories

- 1,071
- 11
- 21
-
6+1: When you want to avoid database access, `Fabricator.build(:factory-name)` just works. I have tried using both `FactoryGirl.build` and `FactoryGirl.build_stubbed` without success - it seems to get confused with model associations, and ends up hitting the database. – rsenna Feb 18 '13 at 21:36
-
3This topic is addressed here: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md. Add the hook to ActiveSupportNotifications and you can see if your test is hitting the DB. You have to be careful how you structure your factories in order to get build_stubbed to avoid hitting the DB. It definitely works fine. – justingordon Apr 18 '13 at 01:50
Factory Girl has an extra concept of trait
which is really useful.
Other features seem more or less alike.
If you want to choose one, consider the number of downloads:
Could be useful when you look for help/support.

- 45,245
- 23
- 243
- 245

- 114,565
- 26
- 219
- 213
-
factory girl's doc lives here: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md – apneadiving Aug 29 '12 at 13:41
-
Thanks. There is a clear difference in popularity (https://www.ruby-toolbox.com/categories/rails_fixture_replacement), but this doesn't necessarily mean that one is better than the other. It could be because one is older, or is more mainstream, or because the other has just matured recently. – Hosam Aly Aug 29 '12 at 13:43
-
The concept of traits is interesting (https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#traits), and apparently is not included in `fabrication`. Thanks. – Hosam Aly Aug 29 '12 at 13:44
I recently did a profiling of Fabricator vs FactoryGirl because I was curious about the performance comments mentioned by others. I also found Fabricator to be slightly faster (but only when using associations):
https://ksylvest.com/posts/2017-08-12/fabrication-vs-factorygirl
Given the runtimes were so close, I prefer Fabricator over FactoryGirl because setting up associations will by default propagate build vs create (instead of having to specify a strategy).

- 37,288
- 33
- 152
- 232