mardi 19 septembre 2017

Ruby on Rails app using Mongo DB: Capybara/Selenium tests using js: fail on second test

I've got an RoR app that uses Mongo DB. The tested functions work correctly in development/production. The test suite used to work. However, ALL tests after the first one now fail.

Specifically, if there's a test using the :js flag:

it 'has activity log', :js do
    visit activity_log_site_settings_site_statistics_path
    expect(page).to have_content 'Activity Log'
end

the FIRST such test works. However, all subsequent tests with the :js flag fail, because Mongo can't find the record in the database:

Problem:
  Document(s) not found for class User with id(s) 59c145db9757d1ce3500000c.

The database is populated by driving the app, using FactoryGirl. I'm using DatabaseCleaner between tests (in rails_helper.rb):

  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

I've tried:

config.use_transactional_fixtures = false

and the shared_connection fix: http://ift.tt/1zEHIWD

Aucun commentaire:

Enregistrer un commentaire