Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Rails 3.1 rc4, Ruby 1.9: ArgumentError: Not registered #168

Closed
ncri opened this issue Aug 2, 2011 · 19 comments
Closed

Error with Rails 3.1 rc4, Ruby 1.9: ArgumentError: Not registered #168

ncri opened this issue Aug 2, 2011 · 19 comments

Comments

@ncri
Copy link

ncri commented Aug 2, 2011

I get lots of these errors running my unit tests;

ArgumentError: Not registered: my_factory
gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/registry.rb:15:in find' gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl.rb:39:infactory_by_name'
gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/vintage.rb:53:in default_strategy' gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/vintage.rb:146:inFactory'

@joshuaclayton
Copy link
Contributor

Could you look to see if you're referencing a my_factory factory somewhere in your project? This exception is raised if you try to do something like Factory(:my_factory) or FactoryGirl.create(:my_factory) somewhere in your application or test suite.

@ncri
Copy link
Author

ncri commented Aug 2, 2011

Hi joshua,

isn't Factory(:my_factory) the intended use? That's how I use factories all over the place in my tests. ;-)

@joshuaclayton
Copy link
Contributor

well, yes, but not literally. Did you define a :my_factory factory in the factories file?

@ncri
Copy link
Author

ncri commented Aug 2, 2011

This is confusing me. :) The offending factories are defined in factories.rb, of cause. my_factory was just a placeholder.

@ncri
Copy link
Author

ncri commented Aug 2, 2011

factory.rb is supposed to be loaded automatically, right? All used to work fine with rails 2.3.

@joshuaclayton
Copy link
Contributor

Oh, I understand now - I was confused as the error you pasted looked real (I assumed you were referencing a weird factory name). What version of Factory Girl were you using before? Also, what version of Rails are you using?

@ncri
Copy link
Author

ncri commented Aug 2, 2011

I use factory_girl (2.0.2) and factory_girl_rails (1.1.0) with rails 3.1 rc4.

@ncri
Copy link
Author

ncri commented Aug 2, 2011

Before I used factory_girl (1.3.3)and Rails 2.3.5

@joshuaclayton
Copy link
Contributor

Alright, great. Since you've upgraded to Rails 3, you're going to want to add the factory_girl_rails gem to your Gemfile. You'll want to set the version to ~> 1.1 and then remove factory_girl from the Gemfile itself. Once you're done re-bundling, you should be all set; let me know if you run into any more issues!

@ncri
Copy link
Author

ncri commented Aug 2, 2011

I only have gem 'factory_girl_rails', "~> 1.1" in my gemfile...

@ncri
Copy link
Author

ncri commented Aug 2, 2011

Do I need to require anything in my testhelper.rb? The factories don't seem to be loaded...

@joshuaclayton
Copy link
Contributor

Hmm. Where are your factories defined? By default, factory_girl_rails is set up to look in factories, spec/factories, and test/factories, either as a ruby file or a directory with *.rb files. Is that not the case?

@ncri
Copy link
Author

ncri commented Aug 2, 2011

They are int test/factories.rb

@joshuaclayton
Copy link
Contributor

no, factory_girl_rails should do this for you. Here's the railtie: https://github.com/thoughtbot/factory_girl_rails/blob/master/lib/factory_girl_rails/railtie.rb

To ensure that this is working correctly, can you move factory_girl_rails outside of the test group in your gemfile and run a Rails console? In there, run FactoryGirl.definition_file_paths and please paste what is returned. Thanks!

@ncri
Copy link
Author

ncri commented Aug 2, 2011

After reading Ryans answer here http://stackoverflow.com/questions/5227081/given-a-typical-rails-3-environment-why-am-i-unable-to-execute-any-tests, I made a slight change to the requires at the top of my test_helper from:

require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'rails/test_help'

to

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

and now I get this error straight after running rake test:units, before executing any tests:

 gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/registry.rb:15:in `find': Not registered: user (ArgumentError)
from gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl.rb:39:in `factory_by_name'
from gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/vintage.rb:53:in `default_strategy'
from gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/vintage.rb:146:in `Factory'
from .../test/factories.rb:4:in `block in <top (required)>'

On line 4 of factories.rb the user factory is defined:

# encoding: utf-8

FactoryGirl.define do
  Factory :user do
    email    ...
    ...
  end
  ...
end       

@ncri
Copy link
Author

ncri commented Aug 2, 2011

Hmm, I tried that, but since the factory girl upgrade I can't even get my console started anymore, the same error:

 /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/registry.rb:15:in `find': Not registered: user (ArgumentError)
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl.rb:39:in `factory_by_name'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/vintage.rb:53:in `default_strategy'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/vintage.rb:146:in `Factory'
from /Users/nico/Rails/yousty/test/factories.rb:4:in `block in <top (required)>'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/default.rb:12:in `instance_eval'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/default.rb:12:in `run'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/nico/Rails/yousty/test/factories.rb:3:in `<top (required)>'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `block in require'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/find_definitions.rb:16:in `block in find_definitions'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/find_definitions.rb:13:in `each'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl-2.0.2/lib/factory_girl/find_definitions.rb:13:in `find_definitions'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/factory_girl_rails-1.1.0/lib/factory_girl_rails/railtie.rb:11:in `block in <class:Railtie>'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:34:in `call'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:25:in `run'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:50:in `block in run_initializers'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:49:in `each'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:49:in `run_initializers'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/application.rb:96:in `initialize!'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/nico/Rails/yousty/config/environment.rb:5:in `<top (required)>'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `block in require'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/application.rb:78:in `require_environment!'
from /Users/nico/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.1.0.rc4/lib/rails/commands.rb:39:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

@joshuaclayton
Copy link
Contributor

The new factory_girl syntax looks like this:

FactoryGirl.define do
  factory :user do
    email    ...
    ...
  end
  ...
end

Notice the lowercase factory :user within the define block - if it's uppercase, it's not defining the factory properly. Could you change those and let me know if that fixes the problem?

@natebird
Copy link

natebird commented Aug 3, 2011

I was getting the following error:

/Users/user/.rvm/gems/ruby-1.9.3-preview1@app/gems/factory_girl-2.0.2/lib/factory_girl/syntax/
default.rb:6:in `define': wrong number of arguments (1 for 0) (ArgumentError)

Changing to the new syntax fixed the issue. Thanks!

@ncri
Copy link
Author

ncri commented Aug 3, 2011

Thanks that solved it! Sorry, I got the new syntax wrong during conversion that was the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants