Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have a very simple integration test

require 'integration_test_helper'

Capybara.current_driver = :rack_test

class AdminSignsInTest < ActionDispatch::IntegrationTest

  test 'can sign in' do

    email = '[email protected]'

    password = 'secret_password'

    Admin.create email: email, password: password

    visit new_admin_session_path

    fill_in 'admin_email', with: email

    fill_in 'admin_password', with: password

    click_button I18n.t('devise.views.sign_in')

    assert_equal I18n.t('devise.sessions.signed_in'), find('p.notice').text

  end

end

When I set the Capybara driver to rack_test test passes, but when I set it to selenium, it fails with 'Invalid email or password.' on the login page (I'm using Devise). What am I doing wrong?

1 Answer

0 votes
by (62.9k points)

You'll have to check use_transactional_fixtures. When using transactional fixtures, because Selenium (or, any of the external drivers, which aren't Rack::Test) do not have access to information that has been written to the database. (as the transaction hasn't been "Committed")

You can resolve this within your test_helper.rb using the below code snippet:

 class ActionDispatch::IntegrationTest

self.use_transactional_fixtures = false

end

At the same time, you may want to look into something like Database Cleaner, as without transactional fixtures, your database will become untidy.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...