I am following Michal Hartls Rails tutorial Chapter 7. I have installed the Factory girl gem. I keep getting this error when I run my test
Failures:
1) UsersController GET 'show' should be successful
Failure/Error: @user = FactoryGirl.create(:user)
ArgumentError:
Factory not registered: user
# ./spec/controllers/users_controller_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.66336 seconds 42 examples, 1 failure
Failed examples:
rspec ./spec/controllers/users_controller_spec.rb:14 # UsersController GET 'show' should be successful
Gemfile
group :test do
gem 'autotest', '4.4.6'
gem "autotest-growl", "~> 0.2.16"
gem "autotest-rails", "~> 4.1.2"
gem "rspec", "~> 2.9.0"
gem 'rspec-rails', '2.9.0'
gem 'webrat', '0.7.3'
gem "spork", '0.9.0'
gem 'annotate', '~> 2.4.1.beta'
gem "factory_girl", "~> 3.2.0"
end
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platform =>
My user_controller_spec.rb is
require 'spec_helper'
describe UsersController do
render_views
describe "GET 'show'" do
before(:each) do
@user = FactoryGirl.create(:user)
end
it "should be successful" do
get :show, :id => @user
response.should be_success
end
end
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
it "should have the right title" do
get :new
response.should have_selector('title', :content => "Sign up")
end
end
end
My factories.rb is
FactoryGirl.create :user do |user|
user.name "Mark Brown"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
end
I changed
Factory(:name)
to
FactoryGirl.create(:user)
on line 10 in my user_controller_spec.rb
becuase I was getting a deprication warning. I thought that would fix it but now im just getting.
Factory not registered: user
Can someone tell me what going on?
I have already fixed it.
The solution was to change gem 'factory_girl'
to gem 'factory_girl_rails'
in my Gemfile.