How to follow a redirect after click_link/button with cucumber and capybara in rails?
I'm currently trying to set up integration/acceptance testing for a new rails 3 application with cucumber and capybara. (I initially planed to use webrat, but it seems that it does not support rails 3, so I ended up with capybara)
I'm trying to get a basic login test working:
Feature: Login user
In order to access the non-public parts of the site,
as a user,
I want to login to the site
Scenario: login with valid credentials
Given I am on the login page
When I fill in "Email" with "bender@planetexpress.com"
And I fill in "Password" with "pass"
And I press "Login"
Then I should be on the users home page
And I should see "Login successful"
The problem now is, that the login form sends me to /user_session
which then redirects me to the users home /home
. Cucumber does not follow the redirect which causes the Then I should be on the users home page
line to fail.
How can I tell cucumber/capybara to follow the redirect so that I am on the right page after I hit a button of follow a link?
There seems to be a follow_redirect!
method in the rack_test driver which I am using, but it is private and开发者_如何学Python I have no clue as how to call that functionality.
thanks in advance,
SimonCapybara automatically follows redirects. Something else is broken.
Add this into your steps:
When /^I dump.* the response$/ do
puts body
end
Then, when your tests are misbehaving, you can add "And I dump the response" to your steps and see where it's going with the redirects or whatever.
Something that might work is switching the order of the statements:
Then I should see "Login successful"
And I should be on the users home page
Then the check for the current page will happen after the check for the page text. Cucumber tests do require a lot of debugging, good luck!
精彩评论