Issue with cleaning my database after tests (Rspec/Capybara/Poltergeist)
Not solved Solved
3 months ago

Hi guys,

I have an issue that drives me crazy. Each time I run my test, the database is not erased at the end. And it keeps accumulating. Which at some point create failed tests.

I'm sure it has something to do with the settings i did this afternoon, to have Poltergeist shared the same db connection with Rspec (otherwise, I couldn't have it worked properly for some reasons).

Here are my settings files :

  • rails_helper:
  • spec_helper:
  • gemfile :
  • database_cleaner:
  • sharedbconnection:

If you guys have an idea, that would be great. These db connection issues are just too complicated for me.

Thanks a lot

3 months ago

Someone much smarter than me once wrote this article

It explains it so much better than I ever could

3 months ago

please not that 'selenium' is an older way of doing javascript testing, so read it as if he is talking about poltergeist and PhantomJS instead of selenium and a browser

3 months ago

gem 'database_cleaner', '~> 1.4.1', require: false in the test group, and something like this in the rails_helper:

RSpec.configure do |config|
  config.before :suite do
    DatabaseCleaner.clean_with :truncation
    DatabaseCleaner.strategy = :truncation, { except: config.seed_tables }
  config.before :example do |example|
    if example.metadata[:js] || example.metadata[:type] == :feature
      DatabaseCleaner.strategy = :deletion, { except: config.seed_tables }
  config.after :example do |example|
3 months ago

Wow !!! Thank you so much guys. I'll try that tomorrow (I'm in Japan, it's already the end of the day here). Thx a lot

3 months ago

It seems that the file database_cleaner.rb isn't loaded in your rails_helper.

I think uncommenting the line #28 in rails_helper.rb -> # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } should solve your problem.

But your database_cleaner.rb file should match the provided path, so be sure to put it in specs/support/database_cleaner.rb

Hope this helped ;)

3 months ago

@kevcha : you found it ! It was just this... Sorry. After a full day of coding, I couldn't see straight. Even when it's obvious like this. Thank you all. I will have a look at the article you posted @arnoFleming

Submit your answer