-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
NameError: uninitialized constant FactoryGirl #60
Comments
@gladgit Sorry you're having issues. Are you using Spork or any sort of similar gem? I also want to confirm that you have not added Finally, can you confirm that you're running your tests in the test environment (or whatever environment the group is from your Gemfile)? If the Rails environment is different from the group you've declared Thanks! |
@joshuaclayton Thanks for looking into this. To answer your questions, I am not using Spork or similar. I have not added
|
@gladgit alright, strange! Could you paste...
Thanks! That should help me narrow it down a bit better. |
Quick question first, does FactoryGirl work with a custom development environment? I am not using the standard ':development' environment. I have set up a custom development environment for Rails with its own environment file and RAILS_ENV setting. |
|
@gladgit Did you do something like Actually, even better, try this: change |
Yes, I explicitly I made the change to I know the spec/spec_helper.rb file is not part of FactoryGirl, but do you know of any gotchas with leaving Thanks for all your help. |
Any reason for setting The reason FactoryGirl isn't loading is because you've declared it in your Gemfile to only be available in the test environment, but if your shell sets it to something different than test, then it's not going to get loaded (that's the issue you were seeing). The reason why assigning So, there are a couple solutions:
I've ordered these by best to worst fixes. The easiest and cleanest thing to do, assuming you're not checking for a macdev environment all over your code (which would be bad!) is just remove setting |
I set RAILS_ENV as a solution for having multiple developers on a project, each with their own development database and settings, meaning their own database.yml file. So probably the easiest thing to do is use another solution for that problem, and don't fiddle with RAILS_ENV. But I'm curious why the spec_helper.rb file uses the or-equals to set RAILS_ENV. Presumably that file sets up the test environment so I imagine you would always want RAILS_ENV to be set to 'test' anyway. Thanks again for your help. |
I had the same issue but I noticed I had spork running before I included FactoryGirl gem in test environment. By simply restarting spork and running rspec again with fresh spork it fixed the issue. |
I just got to this thread after much googling and -- just like @johgrover -- all I needed to do was restart zeus. |
It appears that factory_girl_rails is supposed to automatically load itself, but it does not in my environment. The only installation instructions say to add factory_girl_rails to the gemfile (in the test group). But this does not make FactoryGirl available to me.
I get the error "NameError: uninitialized constant FactoryGirl"
When I require 'factory_girl' in my spec_helper.rb file, that error goes away, and I get a new error: "ArgumentError: Factory not registered: user", even though the :user factory has been created.
When I add "FactoryGirl.find_definitions" to my spec_helper.rb file, then everything works correctly.
I am using factory_girl-3.3.0, factory_girl_rails-3.3.0, rspec-2.8.0, rails-3.0.4, ruby-1.9.2
If factory_girl_rails is supposed to automatically load itself, then if fails in my environment. If it isn't, then perhaps the installation instructions should be updated to include instructions on requiring the necessary files.
The text was updated successfully, but these errors were encountered: