我正在关注 Michal Hartls Rails 教程第 7 章。我已经安装了 Factory girl gem。运行测试时,我不断收到此错误
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
宝石文件
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 =>
我的 user_controller_spec.rb 是
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
我的 factory.rb 是
FactoryGirl.create :user do |user|
user.name "Mark Brown"
user.email "mbrown@yahoo.com"
user.password "foobar"
user.password_confirmation "foobar"
end
我变了
Factory(:name)
至
FactoryGirl.create(:user)
在我的第 10 行,user_controller_spec.rb
因为我收到了贬值警告。我认为这会解决它,但现在我刚刚得到。
Factory not registered: user
有人可以告诉我发生了什么吗?