I am trying to test the login functionality with Cucumber. My file users_steps.rb contains
Given /^I am a user named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |name, email, password|
u = User.new(:name => name,
:email => email,
:password => password,
:password_confirmation => password)
u.skip_confirmation!
u.save!
end
When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
#Given %{I am not logged in}
When %{I go to the sign in page}
And %{I fill in "user_email" with "#{email}"}
And %{I fill in "user_password" with "#{password}"}
And %{I press "Log Me In"}
end
Then /^I should be signed in$/ do
Then %{I should see "Sign out"}
end
Then /^I should be signed in$/ do
Then %{I should see "Sign out"}
end
Then /^I sign out$/ do
visit('/account/logout')
end
and my cucumber scenario is:
Scenario: User signs in successfully with email
Given I am not logged in
And I am a user named "foo" with an email "user@test.com" and password "please"
When I go to the sign in page
And I sign in as "user@test.com/please"
Then I should be signed in
When I return next time
Then I should be already signed in
However this test fails to sign the user in. I have checked that the user is correctly created but after filling in the form I am redirected to the login page.
I am using capybara. What am I missing?