我正在从 Rails 教程书中学习 rais:http ://ruby.railstutorial.org/chapters/sign-in-sign-out#fnref:9.14
我正在做这个练习。任务是在规范助手中创建一个登录方法,以便它可以在集成测试中使用。他已经给出了代码:
def integration_sign_in(user)
visit signin_path
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button
end
所以,在我的 layout_links_spec.rb 集成测试中,我打算使用它。
before(:each) do
@user = Factory(:user)
visit signin_path
fill_in :email, :with => @user.email
fill_in :password, :with => @user.password
click_button
# integration_sign_in(Factory(:user))
end
我将所有内容都注释掉并使用integration_sign_in(Factory(:user))
. 我得到的错误是
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
但是,如果我使用看起来与 integration_sign_in 函数非常相似的原始版本,则测试通过。有人可以提供解释吗?
谢谢。