views:

377

answers:

2

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 "[email protected]"
  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

A: 

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!

Karl
A: 

Capybara or Rack::Test automatically follows redirects. Something else is broken.

henning-koch
Thats the answer that I feared most, but I also heard that from another source. Need to investigate that...
Simon
d'oh! Something was wrong with my test data. No wonder it didn't work if the user didn't exist in the db. Thanks for the help!
Simon