“确认令牌无效”使用 Cucumber 进行测试时

发布于 2024-12-06 13:38:25 字数 2023 浏览 0 评论 0原文

我正在尝试获取与 Devise 合作的注册表单;我正在用黄瓜测试它。

当用户注册时,我会发送一封确认电子邮件。但是,在运行我的测试时出现了问题。

这是我的场景:

  Scenario: Signing in via confirmation
    Given there are the following users:
      | email             | password | unconfirmed |
      | [email protected] | password | true        |
    And "[email protected]" 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 [email protected]"

但是,我收到以下错误:

 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 个错误禁止保存此用户:\n 确认令牌无效

我已经手动测试了这一点(去了注册并单击电子邮件中的确认链接)并且效果很好。只有当我通过 Cucumber 进行测试时,我才会收到“确认令牌无效”消息。有人知道我该如何解决这个问题吗?我希望看到我的测试通过。

非常感谢。

编辑:评论中要求的步骤:

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: 链接;我将第一个链接步骤更改为:

他们遵循电子邮件中的“确认我的帐户”

但这也不起作用。我仍然收到无效令牌错误消息。

I'm trying to get a sign up form working with Devise; I'm testing it with Cucumber.

When a user signs up, I send a confirmation e-mail. Something goes wrong when running my test, though.

This is my scenario:

  Scenario: Signing in via confirmation
    Given there are the following users:
      | email             | password | unconfirmed |
      | [email protected] | password | true        |
    And "[email protected]" 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 [email protected]"

However, I get the following error:

 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)

I guess the important part here is:

1 error prohibited this user from being saved:\n Confirmation token is invalid

I have tested this manually (went to sign up and clicked the confirmation link in the e-mail) and this works fine.. It's only when I test through Cucumber that I get the 'Confirmation token is invalid' message. Anyone know how I can fix this? I'd like to see my tests pass..

Thanks a lot.

EDIT: Steps asked for in the comments:

When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
  open_email(address, :with_subject => subject)
end

Clicking link:

When /^(?:I|they) click the first link in the email$/ do
  click_first_link_in_email
end

I just looked at the confirmation email I got and my e-mail address is parsed as a mailto: link; I changed the first link step to this:

And they follow "Confirm my account" in the email

but that didn't work either.. I'm still getting the invalid token error message.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单气质女生网名 2024-12-13 13:38:25

所以..我在这上面浪费了两个小时。我有一个错字。

我有以下行:

unconfirmed = attribute.delete("unconfirmed") == "true"

我忘记在 true 两边加上引号。没有引号,测试就通过了……

哎呀。

感谢所有花时间帮助我的人:)

So.. I wasted two hours on this. I had a typo.

I have the following line:

unconfirmed = attributes.delete("unconfirmed") == "true"

I forgot to put the quotes around true. Without the quotes, the test passes..

Jeez.

Thanks to everyone who put some time in helping me :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文