我正在使用 minitest 与 factory girl 和 capybara 进行集成测试。当我不使用工厂女孩创建用户对象时,Capybara 工作正常,如下所示:
it "logs in a user successfully" do
visit signup_path
fill_in "Email", :with => "joey@ramones.com"
fill_in "Password", :with => "rockawaybeach"
fill_in "Password confirmation", :with => "rockawaybeach"
click_button "Create User"
current_path == "/"
page.text.must_include "Signed up!"
visit login_path
fill_in "Email", :with => "joey@ramones.com"
fill_in "Password", :with => "rockawaybeach"
check "Remember me"
click_button "Log in"
current_path == "/dashboard"
page.text.must_include "Logged in!"
page.text.must_include "Your Dashboard"
end
但是一旦我尝试用 factory girl 创建一个用户,奇怪的事情就开始发生了,比如 visit 方法和 click_button 方法停止工作。例如,这个测试似乎没有任何问题:
require "test_helper"
describe "Password resets" do
before(:each) do
@user = FactoryGirl.create(:user)
end
it "emails user when requesting password reset" do
visit login_path
click_link "password"
fill_in "Email", :with => user.email
click_button "Reset my password"
end
end
这是我的 factory.rb:
FactoryGirl.define do
factory :user do |f|
f.sequence(:email) { |n| "foo#{n}@example.com" }
f.password "secret"
f.password_confirmation "secret"
end
end
这是我得到的实际错误:
est_0001_emails user when requesting password reset 0:00:01.624 ERROR
undefined local variable or method `login_path' for #<#<Class:0x007fc2db48d820>:0x007fc2df337e40>
但是,visit login_path
如果我删除,效果很好@user = FactoryGirl.create(:user)
这是Capybara的错误吗?还是我在这里做错了什么?