【发布时间】:2011-09-25 20:50:01
【问题描述】:
我正在尝试使用 Devise 获取注册表单;我正在用 Cucumber 测试它。
当用户注册时,我会发送一封确认电子邮件。但是,在运行我的测试时出了点问题。
这是我的场景:
Scenario: Signing in via confirmation
Given there are the following users:
| email | password | unconfirmed |
| user@ticketee.com | password | true |
And "user@ticketee.com" opens the email with subject "Confirmation instructions"
And they click the first link in the email
Then I should see "Your account was successfully confirmed."
And I should see "Signed in as user@ticketee.com"
但是,我收到以下错误:
expected there to be content "Your account was successfully confirmed. You are now signed in." in "\n Ticketee\n \n\nTicketee\nSign up\n Sign in\nResend confirmation instructions\n\n\n \n 1 error prohibited this user from being saved:\n Confirmation token is invalid\n\n\n Email\n\n \n\n Sign inSign upForgot your password?" (RSpec::Expectations::ExpectationNotMetError)
我想这里的重要部分是:
1 error prohibited this user from being saved:\n Confirmation token is invalid
我已经手动对此进行了测试(去注册并单击电子邮件中的确认链接)并且效果很好。只有当我通过 Cucumber 进行测试时,我才收到“确认令牌无效”消息。有谁知道我该如何解决这个问题?我希望看到我的测试通过..
非常感谢。
编辑:在 cmets 中要求的步骤:
When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
open_email(address, :with_subject => subject)
end
点击链接:
When /^(?:I|they) click the first link in the email$/ do
click_first_link_in_email
end
我刚刚查看了收到的确认电子邮件,我的电子邮件地址被解析为 mailto: 链接;我将第一个链接步骤更改为:
And they follow "Confirm my account" in the email
但这也不起作用..我仍然收到无效令牌错误消息。
【问题讨论】:
-
您能否发布涉及打开电子邮件和单击链接的步骤的步骤定义。
-
@AndyWaite 我更新了帖子:)
-
啊,您使用的是 email_spec gem?可能也值得一提。我相信生成的电子邮件会出现在 test.log 中,因此请在那里检查一下,看看是否有正确的链接。
-
哦;很抱歉没有提到这一点。我清除了我的 test.log 并运行了测试。看起来它发送了两次电子邮件,但我不太确定。我可以在这里发布日志,但它相当大..
标签: ruby-on-rails ruby-on-rails-3 devise cucumber actionmailer