I\'m using Rails 3.1.0.rc4 and I\'m working on doing integration tests with capybara\'s new Steak-like DSL and Rspec (using Devise authentication)
The issue I\'m hav
The manual way of doing it is very simple:
it "does something after login" do
password = "secretpass"
user = Factory(:user, :password => password)
visit login_path
fill_in "Email", :with => user.email
fill_in "Password", :with => password
click_button "Log in"
visit # somewhere else and do something
end
You can then break this out into a function in your 'spec_helper.rb':
# at the bottom of 'spec_helper.rb'
def make_user_and_login
password = "secretpass"
@user = Factory(:user, :password => password)
visit login_path
fill_in "Email", :with => @user.email
fill_in "Password", :with => password
click_button "Log in"
end
and use it in any of your tests (probably request specs):
it "does something after login" do
make_user_and_login
# now test something that requires a logged in user
# you have access to the @user instance variable
end