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?
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.
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
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. –
Kloof 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.
fabrication
. Thanks. –
Loydloydie 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).
© 2022 - 2024 — McMap. All rights reserved.