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?
Borrowing a trick from another auth gem Sorcery's wiki: Integration Testing with Rspec, Capybara and Fabricator, they use:
Which basically calls the
user_sessions_controller#create
method, so make sure the args match up. So for me, I did:I was searching for this for a few days. and
UserSession.create!
hadn't been able to work for me. Although this is an old question, I'm on Rails 4, hopefully it may help others stuck too.A bit late to the show as usual but this works for me on Rails 3.0.10.
In
features/support/authlogic.rb
:Then in
features/step_definitions/user_sessions_steps.rb
Obviously, you can pass a username into the step definition if you want to login a specific user.
Full details are in this blog post: http://laserlemon.com/blog/2011/05/20/make-authlogic-and-cucumber-play-nice/
you can use Background in cucumber..ie
that will DRY up your scenarios.
http://github.com/aslakhellesoy/cucumber/wiki/background