rspec tests randomly failing

时间:2015-10-31 00:13:19

标签: ruby-on-rails postgresql rspec redis circleci

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?

1 个答案:

答案 0 :(得分:0)

您在应用中使用不同的redis实例。在初始化程序中,您初始化一个redis,然后使用不同的redis来设置计数器,但是您从不同的redis(RED)中读取它们

RED =! Sidekiq.redis,这就是为什么它试图阅读不同的redis。

我承诺拆分redis数据库之后的PS。

相关问题