Ch Zeeshan
Ch Zeeshan

Reputation: 1644

gem ''factory_girl_rails" Error uninitialized constant FactoryGirl (NameError)

Here is my factories/admin_user.rb code

FactoryGirl.define do
  factory :admin_user do |admin|
    admin.sequence(:email) { |n| "admin#{n}@example.com" }
    admin.password "123456789"
    admin.password_confirmation { |u| u.password }
  end
end

When I run this code I got this Error

uninitialized constant FactoryGirl (NameError)

Any Help??

Upvotes: 0

Views: 1731

Answers (1)

Billy Chan
Billy Chan

Reputation: 24815

The problem should be gem not loaded. You can check if FactoryGirl is correctly defined in Gemfile. And also check if ENV is correct as FactoryGirl is supposed to run under Test env.

Add Maybe test generator is not set correctly? You can check if you have put the following content in config/application.rb

config.generators do |g|
  g.test_framework :rspec,
  fixtures: true,
  view_specs: false,
  helper_specs: false,
  routing_specs: false,
  controller_specs: true,
  request_specs: true
  g.fixture_replacement :factory_girl, dir: "spec/factories"
end

The last line about fixture should be important to your case. Then you can try to remove your hack setting.

Upvotes: 1

Related Questions