Search code examples
ruby-on-rails-4capybaratestunitcapybara-webkit

TestUnit Capybara.reset_sessions! for every test


So the following code works in isolation but if I run the full test suite it breaks if I remove:

Capybara.reset_sessions!

From my investigation the user can't sign in as they are already signed in. So my question is, is it typical to need to call this before running new session tests? And if so, is there somewhere common I can put this so I don't need to have it in every setup method of tests?

require 'test_helper'

class SignInTest < ActionDispatch::IntegrationTest
  def setup
    Capybara.reset_sessions!
  end

  test 'user can sign in' do

  end
end

Solution

  • Add this to:

    test_helper.rb 
    

     

    class ActionDispatch::IntegrationTest
      include Capybara::DSL
      Capybara.default_driver = :webkit
    
      def teardown
        Capybara.reset_sessions!
      end
    end