How to handle User "confirmation" with Watir/Cucumber?
I'm new to Watir and I've having a little trouble get开发者_Python百科ting logged in in my tests. I use authlogic as my authentication method of choice. When a User registers, they are sent an email with a confirmation link. Clicking this link confirms their account and they can then login.
The issue I'm having is how do I confirm the User when using Watir?
I have so far:
Given /I sign up/ do
BROWSER.goto("http://localhost:3000/register")
BROWSER.text_field(:id, "user_email").set("foo@bar.com")
BROWSER.text_field(:id, "user_name").set("Foo Bar)
BROWSER.text_field(:id, "user_password").set("foo bar")
BROWSER.text_field(:id, "user_password_confirmation").set("foo bar")
BROWSER.button(:id, "user_submit").click
end
Given /I am logged in via Watir/ do
BROWSER.goto("http://localhost:3000/login")
BROWSER.text_field(:id, "user_session_email").set("foo@bar.com)
BROWSER.text_field(:id, "user_session_password").set("foo bar")
BROWSER.button(:id, "user_session_submit").click
end
This correctly populates the fields and the User is saved. Now I try to confirm the User like so:
Given /I am confirmed/ do
User.last.confirmed!
end
Unfortunately this doesn't work. What am I missing?
I'm not familiar with waitir but I imagine given following steps:
Given I have signed up
When I confirm my account
Then my account should be confirmed
You could either keep track of the link you're expecting them to hit and actually test hitting that link to verify that the controller then sets the user as confirmed:
When /I confirm my account / do
BROWSER.goto("the_url_from_the_email")
# note that if you need to visit this link and click a button
# or something you will need to code that part as well
end
These steps would exercise the signup and confirmation code. I think if you wanted you'd either use these to compose a "Given I am logged in with a confirmed account" step as a precondition for other tests, or just use that same step to return a canned account.
Not sure that answers your original question really but as mentioned you haven't really said what's actually going wrong. I would assume that User.last.confirmed! isn't saving, or isn't saving the record you expect.
精彩评论