Session Management with Capybara and Rails 3

I have two capybara tests, the first of which is with the user, and the second is for testing functions that are available only to the registered user.

However, I can’t get the second test, because the session is not supported in the tests (as, apparently, it should be).

require 'integration_test_helper'

class SignupTest < ActionController::IntegrationTest

  test 'sign up' do  
    visit '/'
    click_link 'Sign Up!'
    fill_in 'Email', :with => 'bob@wagonlabs.com'
    click_button 'Sign up'
    assert page.has_content?("Password can't be blank")
    fill_in 'Email', :with => 'bob@wagonlabs.com'
    fill_in 'Password', :with => 'password'
    fill_in 'Password confirmation', :with => 'password'
    click_button 'Sign up'
    assert page.has_content?("You have signed up successfully.")
  end

  test 'create a product' do
    visit '/admin'
    save_and_open_page
  end

end

The page generated by the save_and_open_page call is the global login screen, not the administrator’s home page, as you would expect (registration will register you). What am I doing wrong here?

+5
source share
2 answers

, , . , , :

def login
  visit '/'
  fill_in 'Email', :with => 'bob@wagonlabs.com'
  fill_in 'Password', :with => 'password'
  fill_in 'Password confirmation', :with => 'password'
  click_button 'Sign up'
end

test 'sign up' do
 ...
 login
 assert page.has_content?("You have signed up successfully.")
end

test 'create a product' do
  login
  visit '/admin'
  save_and_open_page
end
+6

. , setup teardown, Rails guide.

+3

All Articles