How to follow the redirection after the click_link / button with cucumber and capybara in rails?

I'm currently trying to configure integration / acceptance testing for a new rails 3 application with cucumber and capybara. (I originally planned to use webrat, but it doesn't seem to support rails 3, so I ended up with capybara)

I am trying to run a basic login test:

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" 

Now the problem is that the login form sends me to /user_session , which then redirects me to the /home users /home . Cucumber does not redirect, due to which the line Then I should be on the users home page fails.

How can I tell the cucumber / capybara to follow the redirect, so that I am on the right page after I click the button after the link?

There seems to be a follow_redirect! method follow_redirect! in the rack_test driver that I use, but it's closed, and I donโ€™t know what to call this functionality.

early,
Simon

+7
redirect ruby-on-rails cucumber capybara
source share
3 answers

Capybara automatically follows redirects. Something else is broken.

+14
source share

Add this to your steps:

 When /^I dump.* the response$/ do puts body end 

Then, when your tests are wrong, you can add โ€œAnd I will give a responseโ€ to your steps and see where this happens with a redirect or something else.

+6
source share

Something that might work is switching the order of instructions:

 Then I should see "Login successful" And I should be on the users home page 

Then, checking the current page will occur after checking the text of the page. Tests for cucumbers require a lot of debugging, good luck!

+1
source share

All Articles