当在Michael教程中的示例rails应用程序上运行bundle exec rspec时,我得到了错误“:工厂未注册:user”
我看到了一堆非常相似的问题,但我尝试了两种解决方案:
( a)重新启动rails服务器b)安装‘factory_girl_rails’
我的个人档案的相关部分:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.0.1'
group :test do
gem 'selenium-webdriver', '2.0.0'
gem 'capybara', '2.1.0'
gem 'factory_girl_rails', '4.2.1'
endFacotries.rb
#root/spec/factories.rb
FactoryGirl.define do
factory :user do
name "Michael Hartl"
email "michael@example.com"
password "foobar"
password_confirmation "foobar"
end
enduser_pages_spec.rb
#root/spec/requests/user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title('Sign up') }
end
endshow.html.erb
#root/app/views/user/show.html.erb
<% provide(:title, @user.name) %>
<h1><%= @user.name %></h1>误差输出
Failures:
1) User pages profile page
Failure/Error: let(:user) { FactoryGirl.create(:user) }
ArgumentError:
Factory not registered: user
# ./spec/requests/user_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'我从来没有向堆叠溢出的神让步过,但我要把我的电脑扔出窗外。帮助是非常感谢的!
发布于 2013-08-23 13:28:55
Bigxiang的评论是解决之道。我是一个初学者,实际上不知道我的目录的名称是重要的。一个错误导致了这个问题。
https://stackoverflow.com/questions/18265567
复制相似问题