FactoryGirl - Define factories in a different directory other than spec/factories

2092 views
Skip to first unread message

Carlos Chavez

unread,
Apr 16, 2013, 12:33:23 PM4/16/13
to factor...@googlegroups.com
Hi All.

I'm using factory girl on a rake task, by default its loading the factories from spec/factories, but I want to define a new set of factories in a different directory.

In config/application.rb I tried the following:

    config.generators do |g|
      g.fixture_replacement :factory_girl, :dir => '#{config.root}/lib/test_data_strap/factories'
    end

I also tried:

    FactoryGirl.definition_file_paths = %w(#{config.root}/lib/test_data_strap/factories)
    FactoryGirl.find_definitions


But those does not work, still loading the factories from spec/factories.

--
Cheers.
Carlos Chávez.

Carlos Chavez

unread,
Apr 16, 2013, 1:47:13 PM4/16/13
to factor...@googlegroups.com
Hi All.

I changed in the application.rb to the following:

FactoryGirl.definition_file_paths = %W(lib/test_data_strap/factories)
FactoryGirl.reload

Now, its seems like is loading the factories defined in that directory, but It seems that still loading the one that I have on spec/factories.

I have the following error messages:

Factory already registered: lu_age
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl/disallows_duplicates_registry.rb:11:in `register'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl.rb:45:in `block in register_factory'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl.rb:44:in `each'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl.rb:44:in `register_factory'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl/syntax/default.rb:24:in `factory'
/home/cchavez/scholastic/bitbucket/pcd-bookeditor/spec/factories/lu_age.rb:2:in `block in <top (required)>'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl/syntax/default.rb:16:in `instance_eval'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl/syntax/default.rb:16:in `run'
/home/cchavez/.rvm/gems/ruby-1.9.3-p385@pcd-bookeditor/gems/factory_girl-3.2.0/lib/factory_girl/syntax/default.rb:7:in `define'
/home/cchavez/scholastic/bitbucket/pcd-bookeditor/spec/factories/lu_age.rb:1:in `<top (required)>'


The thing is that I don't want to load the ones on spec/factories.




--
--
Individuals over processes. Interactions over tools. Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training
 
You received this message because you are subscribed to the "factory_girl" mailing list.
To post to this group, send email to factor...@googlegroups.com
To unsubscribe from this group, send email to
factory_girl...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/factory_girl?hl=en
---
You received this message because you are subscribed to the Google Groups "factory_girl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to factory_girl...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Saludos.
Carlos Chávez.

Carlos Chavez

unread,
Apr 16, 2013, 4:37:08 PM4/16/13
to factor...@googlegroups.com
Hi All.

I think found the solution, put the sentences on application.rb does not work, not sure why, what I did was put the following in the method that I'm going to call the factories:


    FactoryGirl.factories.clear
    FactoryGirl.definition_file_paths = %W(lib/test_data_strap/factories)
    FactoryGirl.reload


those lines does not work on the application.rb, but its working on the module that I'm going to use to create the data.

--
Cheers.
Carlos Chávez.

--
Saludos.
Carlos Chávez.

Chris Gat

unread,
Nov 6, 2013, 4:43:28 PM11/6/13
to factor...@googlegroups.com
Carlos, thanks for replying to your own post with the answer. This helped me out.
Reply all
Reply to author
Forward
0 new messages