0

我查看了其他主题并进行了谷歌搜索,不幸的是没有一个解决方案有效。我刚刚开始编写我的第一个密码重置测试。我应该收到 Capybara elementnotfound 错误,因为没有标题或文本“密码”的链接。相反,工厂女孩说它不是注册用户。

  1) PasswordResets emails user when requesting password reset
     Failure/Error: user = FactoryGirl.create(:user)
     ArgumentError:
       Factory not registered: user
     # ./spec/requests/password_resets_spec.rb:5:in `block (2 levels) in <top (required)>'

这是我的 password_reset_spec.rb:

require 'spec_helper'

describe "PasswordResets" do
  it "emails user when requesting password reset"
    user = FactoryGirl.create(:user)
    visit login_path
    click_link "password"
    fill_in "Email", :with => user.email
    click_button "Reset Password"
  end

工厂.rb:

FactoryGirl.define do
  factory :user do
  f.sequence :email do |n| "foo#{n}@example.com"
  end
  f.password "secret"
end
end

宝石文件:

gem 'rspec-rails', :group => [:test, :development]
group :test do
  gem 'factory_girl'
  gem 'capybara'
  gem 'guard-rspec'
  gem 'rb-fsevent'
end
4

1 回答 1

0

您的工厂声明中的语法不正确,我会使用以下内容:

FactoryGirl.define do
  factory :user do
    sequence(:email) { |n| "foo#{n}@example.com" }
    password "secret"
  end
end
于 2013-03-05T15:33:29.787 回答