# frozen_string_literal: true RSpec.configure do |config| config.before(:each, :queue => lambda { |v| !!v }) do |example| config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}") # Clears out the jobs for tests using the fake testing ::Sidekiq::Worker.clear_all ::Sidekiq::Queues.clear_all # Sidekiq Enterprise Doesn't Like Having the Cache Cleared Between Runs # rubocop:disable Metrics/BlockNesting unless defined?(::Sidekiq::Enterprise) ::Sidekiq.redis do |client| connection = client.__send__(:instance_variable_get, :@redis) || client.__send__(:instance_variable_get, :@client) connection.call([:flushdb]) end ::Sidekiq.redis do |client| client.keys.each do |key| client.del(key) end end end # rubocop:enable Metrics/BlockNesting if [:stub, :fake].include?(example.metadata[:queue]) ::Sidekiq::Testing.fake! elsif [:inline, :immediately_execute].include?(example.metadata[:queue]) ::Sidekiq::Testing.inline! elsif [:system, :feature].include?(example.metadata[:type]) ::Sidekiq::Testing.inline! else ::Sidekiq::Testing.fake! end config.rspeckled_logger.debug("Before Each - End - #{__FILE__}") end config.after(:each, :queue => lambda { |v| !!v }) do |_example| config.rspeckled_logger.debug("After Each - Start - #{__FILE__}") ::Sidekiq::Testing.fake! config.rspeckled_logger.debug("After Each - End - #{__FILE__}") end end