Factories Already Defined

10 views
Skip to first unread message

Rodrigo Flores

unread,
Aug 26, 2010, 9:10:53 PM8/26/10
to ste...@googlegroups.com
Hi

I'm trying to use Steak with Factory Girl and I'm having this problem
while running rake spec (which I use to run all the tests):
Factory already defined: todo_item.

On the stacktrace, I see that it comes from my acceptance tests. Using
autotest, all my tests pass.

I don't know why this is happening since I'm not seeing where I load
the factories twice. My spec_helper and my acceptance helper are here:
http://gist.github.com/552564

Any hints ?

--

===================
Rodrigo L. M. Flores
Computer Science Msc. Student - IME - USP
Computer Science Degree - IME - USP
Homepage (en): http://www.rodrigoflores.org
Blog (pt-BR): http://blog.rodrigoflores.org
Linux User # : 351304
Jabber: i...@rodrigoflores.org

Luismi Cavallé

unread,
Aug 27, 2010, 9:22:13 AM8/27/10
to ste...@googlegroups.com
Too little info to help you. Where are you requiring or including FactoryGirl? Can we stack the stacktrace you mentioned?

Also, make sure you're using latest version of Steak from git, and that you don't have any rake file like in `/lib/tasks/steak.rake` since that file is no longer necessary.

-- Luismi

Rodrigo Flores

unread,
Aug 27, 2010, 11:16:07 AM8/27/10
to ste...@googlegroups.com
I found where the problem is. The spec rake tasks were running all the
_spec files inside directories on spec/ directory, when the behaviour
I want is to not run files in acceptance directory inside spec.

Rodrigo Flores

unread,
Aug 27, 2010, 1:44:41 PM8/27/10
to ste...@googlegroups.com
A not so beatiful workaround that solves this problem is to put on
spec_helper.rb:

if Factory.factories.empty?
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
end

Pessoal

unread,
Aug 27, 2010, 2:57:14 PM8/27/10
to ste...@googlegroups.com
You're probably doing something wrong because I use Factory Girl with both Rails 2 and 3.

If your project is Rails 3.0 you should use the factory_girl_rails gem. If not you just need to require 'factory_girl' in spec_helper.rb and place your factories inside factories folder (that is autoloaded by FactoryGirl).

--
Daniel Lopes
Reply all
Reply to author
Forward
0 new messages