views:

28

answers:

1

I have a number of Cucumber scenarios which run with capybara on a project I am working on.

Most of these scenarios start with a "Given I am logged in" step. Currently my implementation of this is:

  visit path_to('the login page')
  fill_in('Username', :with => 'user')
  fill_in('Password', :with => 'password')
  click_button('Login')

This works fine, however it is becoming a bit time consuming having to load and submit the login form before every single scenario.

Is there a way to simply set up the session in this step without having to go through the form every single time?

A: 

you can use Background in cucumber..ie

Background:
    Given I am a logged-in admin user

that will DRY up your scenarios.

http://github.com/aslakhellesoy/cucumber/wiki/background

Thanks for the answer. I actually had that already, the problem was in the implementation of that step - physically having to go the form every time and fill in the page was slow, and a little unnecessary - I only need to test that once. In the end we solved this by stubbing the user session.
AlistairH