Ruby-on-rails – How to follow a redirect after click_link/button with cucumber and capybara in rails

capybaracucumberredirectruby-on-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 I have no clue as how to call that functionality.

thanks in advance,
Simon

Best Answer

Capybara automatically follows redirects. Something else is broken.

Related Topic