2011-09-25 20 views
2

我正在尝试使用Devise获得注册表单;我正在用黄瓜进行测试。当使用Cucumber进行测试时,'确认令牌无效'

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

这是我的情景:

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 error prohibited this user from being saved:\n Confirmation token is invalid

我有手动测试(注册并点击确认链接在电子邮件),这工作正常..只有当我通过黄瓜测试,我得到'确认令牌是无效'的消息。任何人都知道我可以解决这个问题?我想看到我的测试通过..

非常感谢。

编辑:步骤在评论中问:

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

clicking链接:

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

,但没有工作,要么..我仍然得到无效的令牌错误消息。

+0

您可以发布涉及打开电子邮件并点击该链接的步骤步骤定义。 –

+0

@AndyWaite我更新了这篇文章:) – cabaret

+0

啊,你正在使用email_spec宝石?也许值得一提的是,我相信生成的电子邮件会出现在test.log中,因此请在那里检查并查看是否有正确的链接。 –

回答

3

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

我有以下行:

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

我忘了周围true引号。没有报价,测试通过..

Jeez。

谢谢大家谁放一些时间在帮助我:)

+0

你能解释一下这条线应该做什么吗?也许有更好的写法,这是不容易出错的。顺便说一句,这应该真的被单元测试所捕获 - 一个很好的例子说明为什么只有黄瓜是不够的。 –

+0

这条线在我的user_steps中。RB;它为用户设置了“未确认”变量,所以我知道哪些用户已经确认了他们的acct,哪些没有。我正在关注一本书,但是写这行的方式对我来说并不是那么清楚,但是......我该如何编写一个单元测试呢?我对这整个TDD的东西有点新鲜,我知道如何编写控制器等的Rspec测试,但对于步骤文件? – cabaret

+0

啊,我以为你的意思是这条线是在模型代码中。 –

相关问题