【发布时间】:2015-12-14 17:03:15
【问题描述】:
我正在尝试测试用于重置密码的设计功能,但在尝试测试邮件中的链接和访问链接到的页面时遇到了一些问题。
我尝试了两种方法都没有成功:
1)
scenario "User resets his password" do
user2 = FactoryGirl.create(
:user, reset_password_token: "new_password",
)
visit new_user_password_path
fill_in "Email", with: user2.email
click_on "Send me reset password instructions"
open_email(user2.email)
click_first_link_in_email
expect(page).to have_content("Reset your password")
end
如果我这样做,我会收到错误:
Failure/Error: click_first_link_in_email
ActionController::RoutingError:
No route matches [GET] "/1999/xhtml'"
2)
scenario "User resets his password" do
user2 = FactoryGirl.create( :user, reset_password_token: "new_password" )
visit edit_user_password_path(reset_password_token:
expect(page).to have_content("Reset your password")
end
如果我这样做,它会将我带到初始页面:
"You can't access this page without coming from a password reset email"
【问题讨论】:
-
reset_password_token 后:我有一个 user2.reset_password_token)
-
第二个例子可以理解。它需要通过邮件并单击邮件中的重置密码链接。我建议你使用letter opener 或mail catcher
-
你为什么要测试这个@Westey?设计已经过测试和维护。我想你不应该担心这样的测试。
-
我正在使用 mailcatcher,一切正常,但我无法在测试环境中访问该页面(介绍新密码的页面)。由于网站性质的特殊原因,我需要添加额外的安全性和额外的测试:S
标签: ruby-on-rails testing rspec devise mailer