Reputation: 2340
I'm using Devise for user Authentication and have the following failing Cucumber scenario:
Scenario: Log in to the system
Given a user called "test" with a password of "secret"
And I am not logged in # Just visits /users/sign_out
When I go to the log in page
And I fill in "user_username" with "test"
And I fill in "user_password" with "secret"
And I press "Sign in"
Then I should see "Signed in successfully."
If I stick a "Then show me the page" at the end I'm shown a page with a blank log in form.
The following (very similar) test works:
Scenario: Fail to log in with invalid credentials
Given a user called "test" with a password of "secret"
And I am not logged in
When I go to the log in page
And I fill in "user_username" with "test"
And I fill in "user_password" with "invalid password"
And I press "Sign in"
Then I should see "Invalid email or password."
... so I'm assuming that the log in does a redirect after a successful validation that Cucumber isn't following (FWIW the log in all works when I do it manually in the browser)... can anyone tell me how to get the test to pass?
Thanks, Ash
EDIT: It's the last step that is failing with an "expected #has_content?("Signed in successfully.") to return true, got false" error (...ahem... should have mentioned that before!)
Upvotes: 1
Views: 1739
Reputation: 2340
Fixed it! I've just loaded my server with the test environment and reproduced the problem.
I'm using ldap_authenticatable with config.ldap_create_user = true. On the first log in the user account is created if it doesn't exist (which it doesn't in the freshly wiped test db), however this is then redirecting back to the log in page rather than following the root route. Subsequent log ins perform the expected behaviour. So the following test passes:
Scenario: Log in to the system
Given a user called "test" with a password of "secret"
And I am not logged in
When I go to the log in page
And I fill in "user_username" with "test"
And I fill in "user_password" with "secret"
And I press "Sign in"
And I fill in "user_username" with "test"
And I fill in "user_password" with "secret"
And I press "Sign in"
Then I should see "Signed in successfully."
Many thanks to pjammer for the rubber ducking!
Upvotes: 1
Reputation: 9577
is the id field user_username
or is it user_email
or something?
Also what does When I go to the log in page look like? you sure you go there?
Upvotes: 1