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

时间:2011-09-25 20:50:02

标签: ruby-on-rails ruby-on-rails-3 devise cucumber actionmailer

我正在尝试与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测试我得到'确认令牌无效'消息时。有谁知道如何解决这个问题?我想看看我的测试通过..

非常感谢。

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

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

And they follow "Confirm my account" in the email

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

1 个答案:

答案 0 :(得分:3)

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

我有以下一行:

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

我忘了在true附近加上引号。没有引号,测试通过..

哎呀。

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