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 On Jul 5, 2012, at 3:18 PM, Rafael Mendonça França wrote: > 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 > > > > On Thu, Jul 5, 2012 at 3:48 PM, Olek Janiszewski <[email protected]> > wrote: > Hi guys, > > I've noticed the trend of trimming the fat from Rails in preparation for > version 4 (which I appreciate). > > Do you think it'd make sense to also remove the test fixtures engine from > Rails 4? From what I've seen, it's now more common to use more advanced > solutions, with FactoryGirl leading the pack, and it's usually more practical > to use Ruby to define fixtures, rather than YAML. > > More specifically: > > - would the core team approve of such effort? > - how much work would it mean? > - (related) how tightly are fixtures actually used within Rails' tests? > > It's hard to me to estimate the overall value/cost ratio, but if it's high > enough, I'd be willing to take a shot at it. > > -- > Bye, > Olek Janiszewski (exviva) > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/MNYYrHc3b_gJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
