My problem is that I have to create a new user and login for each individual capybara test.
The following is an example:
require 'spec_helper'
describe "users" do
describe "user registration" do
it "should create a new user and log in" do
visit signup_path
fill_in 'Email', with: 'testuser'
fill_in 'Password', with: 'testpass'
fill_in 'Password confirmation', with: 'testpass'
click_button 'Create User'
current_path.should == root_path
page.should have_content 'Thank you for signing up!'
end
end
describe "user login" do
it "should log in" do
visit login_path
fill_in 'Email', with: 'testuser'
fill_in 'Password', with: 'testpass'
click_button 'Log In'
current_path.should == root_path
page.should have_content 'Logged in!'
end
end
end
The login test fails because the user no longer exists in the database for this test.
This could be fixed simply by putting both in the same test, but I think this is bad practice.
Also, I have another file that is currently logging and logging between each test using before_do, which also seems pretty bad ... you can see this code here .
For the record, this is my first rails app, so maybe I'm trying to get it wrong. I would like to dry it as much as possible.
capybara , ?