ArgumentError: Factory not registered: user语言 - Hartl Chapter



我很难通过Michael Hartl的Ruby on Rails教程第7.1.3章的测试。

下面是错误信息:
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)>'
  2) 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)>'
Finished in 2.72 seconds
37 examples, 2 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:11 # User pages profile page 
rspec ./spec/requests/user_pages_spec.rb:12 # User pages profile page
这是我的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_selector('h1',    text: user.name) }
    it { should have_selector('title', text: user.name) }
  end
  describe "signup page" do
    before { visit signup_path }
    it { should have_selector('h1',    text: 'Sign up') }
    it { should have_selector('title', text: 'Sign up') }
  end
end

这是我的工厂。rb:

FactoryGirl.define do
  factory :user do
    name     "Michael Hartl"
    email    "mhartl@example.com"
    password "foobar"
    password_confirmation "foobar"
  end
end

这是Gemfile:

group :test do
  gem 'capybara', '1.1.2'
  gem 'cucumber-rails', '1.2.1', :require => false
  gem 'database_cleaner', '0.7.0'
  gem 'factory_girl_rails', '1.4.0'
end

我已经尝试重新启动服务器,并运行bundle exec rake db:reset, db:test:prepare, db:test:load, db:migrate -似乎没有任何工作。什么好主意吗?

如果您遵循Michael Hartl的指南,您可能也会使用sporkguard。工厂中的更新不会被spork记录,除非spork重新启动。

如果您正在使用它们,请尝试重新启动sporkguard

相关内容

  • 没有找到相关文章

最新更新