开发者

'Confirmation token is invalid' when testing with Cucumber

开发者 https://www.devze.com 2023-04-07 04:05 出处:网络
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.

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 |
      | user@ticketee.com | password | true        |
    And "user@ticketee.com" opens the email with subject "Confirmation instructions"
    And th开发者_如何学运维ey 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"

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.


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消