lib/rspectacular/plugins/sidekiq.rb



begin
  require 'sidekiq/testing'

  RSpec.configure do |config|
    config.before(:each) do |example|
      # Clears out the jobs for tests using the fake testing
      Sidekiq::Worker.clear_all

      if example.metadata[:queue] == :stub
        Sidekiq::Testing.fake!
      elsif example.metadata[:queue] == :immediately_execute
        Sidekiq::Testing.inline!
        @redis_connection = Redis.new

        allow(Sidekiq::RedisConnection).to receive(:build_client).
                                           and_return(@redis_connection)
      elsif example.metadata[:type] == :feature
        Sidekiq::Testing.inline!
        @redis_connection = Redis.new

        allow(Sidekiq::RedisConnection).to receive(:build_client).
                                           and_return(@redis_connection)
      else
        Sidekiq::Testing.fake!
      end
    end
  end
rescue LoadError
end