Skip to content

Commit

Permalink
Extract clear_redis helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bray committed Jan 31, 2024
1 parent 8c18b44 commit 99f1687
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 1 addition & 6 deletions spec/sidekiq_publisher/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

before do
stub_const("TestWorker", worker_class)

Sidekiq.redis do |conn|
conn.scan_each do |key|
conn.del(key)
end
end
clear_redis
end

describe ".sidekiq_client_push" do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
config.after do |example|
DatabaseCleaner.clean unless example.metadata.fetch(:skip_db_clean, false)
end

config.include RedisHelpers
end

Shoulda::Matchers.configure do |config|
Expand Down
15 changes: 15 additions & 0 deletions spec/support/helpers/redis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module RedisHelpers
# This uses redis-namespace to scope by a namespace.
# We should clear the keys like this rather than `flushdb`, which doesn't
# respect the namespace (in case the user hasn't configured a different
# Redis DB for these specs).
def clear_redis
Sidekiq.redis do |conn|
conn.scan_each do |key|
conn.del(key)
end
end
end
end

0 comments on commit 99f1687

Please sign in to comment.