Extract fixtures to a separate gem for Rails 4

In my experience using factories are, at least, twice slower than using fixtures. I always prefer to use fixtures.

I don’t see any real gain in removing it from Rails, neither extracting it to a gem.

Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca

Factories give a lot more functionality, including inheritance and get really fancy when combined with stuff like Faker. I don’t think that the discussion here should be whether factories are useful or not, but if they are a good enough value added to rails.

I personally like the added functionality and expressability of factories and do not mind the extra time it takes to run the tests. But in my opinion what should really be taken in account is what we want someone that is just starting to test with rails to be using. Are fixtures really the best way to it? If so then maybe we could just add some reference in the documentation to other ways of doing it (factories), if not then changing the default to factories or extracting everything to separate gems and leave it to the user would be two possible solutions, IMO.

Factories are not slow!

Using a clean database and re-seeding fixtures with factories on top of a clean database and not using transactional fixtures is slow!

For the past 2 years I have been using transactional fixtures while using factories to seed that data, vs YAML files. The process is pretty simple.

  1. Make Rails ‘test:prepare’ taks call a ‘db:test:seed’ task.

  2. Make the ‘db:test:seed’ task load a file that leverages your factory gem of choice.

  3. Provide methods that leverage ActiveRecord::Fixtures.identify so both factories and tests can get to seeded data.

I finally found some time a few months back to put my work int a gem called “named_seeds”

https://github.com/metaskills/named_seeds/

I would love to see Rails bless a default factory gem. Then utilize a strategy like my “named_seeds” gem. It would allow:

  1. Backward compatibility to fixtures using methods like “user(:admin)”.

  2. A way to use any factory gem, the db/test/seeds.rb would be like db/seeds.rb, open ended.

  3. Hook into calling db/seeds for lookup tables, etc before test seeding too.

  4. Load other engine seeds before hand too.

All of this named_seeds does now.

  • Ken

I think we are not talking about add factories by default in the Rails, but about extract/remove fixtures.

We have a attempt to have the best of both words, that I think that can be added in the Rails.

https://github.com/plataformatec/hermes/blob/master/lib/hermes/builders.rb#L1-79

And you are right Ken, factories are not slow, but the current implementation/usage of they are. Your solution seems solve these actual issues.

Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca

Factories and factory_girl are one of the worst things to ever happen to Rails.

I can't possibly see this ending as anything but a giant flamewar email thread.

I agree with Steve. Would love to see a reasoned discussion on what you’d replace FactoryGirl with.

p.s. My test setup is better than your test setup.