DEV: Properly flush `DistributedMemoizer` in spec.

DEV: Properly flush DistributedMemoizer in spec.

  • $redis.flushall may hide state leak from other tests.
diff --git a/lib/distributed_memoizer.rb b/lib/distributed_memoizer.rb
index e80b687..3be9266 100644
--- a/lib/distributed_memoizer.rb
+++ b/lib/distributed_memoizer.rb
@@ -46,6 +46,11 @@ class DistributedMemoizer
     "memoize_" << key
   end
 
+  # Used for testing
+  def self.flush!
+    $redis.scan_each(match: "memoize_*").each { |key| $redis.del(key) }
+  end
+
   protected
 
   def self.get_lock(redis, redis_lock_key)
diff --git a/spec/requests/static_controller_spec.rb b/spec/requests/static_controller_spec.rb
index b3613be..7db1cdb 100644
--- a/spec/requests/static_controller_spec.rb
+++ b/spec/requests/static_controller_spec.rb
@@ -9,7 +9,7 @@ describe StaticController do
     before { FinalDestination.stubs(:lookup_ip).returns("1.2.3.4") }
 
     after do
-      $redis.flushall
+      DistributedMemoizer.flush!
     end
 
     it 'returns the default favicon for a missing download' do

GitHub sha: 72d14a11

2 Likes

Now you understand why $redis.flushall is a bad idea :wink:

1 Like