error Not registered: factory in fixtures file #15

dieuit07 opened this Issue Mar 14, 2012 · 4 comments


None yet
2 participants

Hi everyone,
When I run spec, I give this:

# <ArgumentError: Not registered: user>```

In my spec_helper:
`require 'rubygems'`
`require 'spork'`
`require 'factory_girl'
require 'simplecov'
SimpleCov.start 'rails'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'capybara/rspec'
  require 'fixtures'`

 `Dir[Rails.root.join("spec/factories/**/*.rb")].each {|f| require f}
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}`

In fixtures_builder/user.rb
`test = Factory(:user)`

If I place content user_factory.rb in the top file  fixtures_builder/user.rb, It run ok

Did I config something wrong?

rdy commented Mar 14, 2012

That error is actually coming from Factory Girl. But it is probably due to using spork.

Make sure you do the following in your Spork each run:

Spork.each_run do

Basically that message is when factory girl runs, and it doesn't have you factories loaded by the time it runs the test. Adding the FactoryGirl reload should make sure it is there in time without having to adjust your requires.

rdy closed this Mar 14, 2012

I do it follow your advise


but it still have this error


rdy commented Mar 14, 2012

you might also want to try the gem 'factory_girl_rails' instead of just gem 'factory_girl' which properly loads the factories at the right time which could also be the problem.

not thing change :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment