CircleCI for testing, Ruby on Rails environment, using Redis for caching and postgres as the db. Rspec + cucumber for testing. I have tried everything but I still get failing tests, in quite a few different spec files, completely randomly. Whenever I run the tests individually, they pass.
This means that there's data left over from previous tests, or that some of my random FactoryGirl data is messing up sometimes. But, they always pass individually.
First, I tried to fix tests manually, but I realized it was a bigger problem. Now, I'm trying to flush the db and Redis on each and every test, but even that doesn't work.
I have a flushall in my before/after each in spec_helper, which should apply to every single test. I know I shouldn't even need before AND after, but why not.
Then, I use database cleaner gem with the following settings:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
What else could I be missing? I've been digging into this for a very long time now.
Could it be that I'm using different Redis databases? I use this:
Sidekiq.redis do |connection|
connection.incr(company.message_count_key)
connection.incr(company.all_time_message_count_key)
end
But then I built a wrapper around Redis. called RED. and is that a different redis? Would doing RED.flushall not be sufficient for wiping all REDIS?