Extract fixtures to a separate gem for Rails 4

One of the reasons I prefer factories over fixtures is that my tests
express better.

login_user = Factory.create :user

login_as login_user


In this case, someone reading this test knows that it only matters

that a user is being created. It shouldn’t have any special

But if I do something like this:

login_user = Factory.create :user, name: 'Rodrigo'

Then I know that the name attribute of the user is relevant for that


Another reason is that I only load the records needed by my tests,

not lots of unrelated data that could have some side effect on the



My vote is to extract to a external gem.

It’s fine if you like fixtures, but it’s fine if you like factories too.

I think the benefit of release cycle decoupled from rails will be valuable.

What are the downsides?


Rails provides a curated stack. The stack reflects the preferences of the core team, we make some choices that we believe are the best defaults. For instance, when we compare Test::Unit and RSpec code side by side we prefer Test::Unit, and that’s what you get in the stack. Same for fixtures.

In addition to that, the framework also makes the design/development effort to let users be able to plug in alternatives, and Rails 3 made this less hackish than it was before. So it is totally fine that you prefer factories, and we’ll make sure you can use them.

I see.

What about release cycle?

Well, in the case of Rails the value of extracting something like this to a gem has more to do with the internal organization of the framework in my view.

Things in Rails follow the release cycle of Rails generally speaking. For example, Active Record is a gem, but there aren’t releases of Active Record independent from Rails, albeit it can be used outside Rails.

I don’t see a need to extract fixtures to a gem personally.

ok, thanks for explanation Xavier :slight_smile: