Remove extremely confusing spec involving too many doubles

Remove extremely confusing spec involving too many doubles

We should never use “double” in specs on mini profiler, it is fragile
confusing and had a tiny test surface.

Instead test the actual behavior of classes

From 18640ac1d9d196d0c6ebfbf3357e7a5ae6a5658a Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Mon, 10 Dec 2018 14:22:18 +1100
Subject: [PATCH] Remove extremely confusing spec involving too many doubles

We should never use "double" in specs on mini profiler, it is fragile
confusing and had a tiny test surface.

Instead test the actual behavior of classes

diff --git a/lib/mini_profiler/storage/memory_store.rb b/lib/mini_profiler/storage/memory_store.rb
index 5d741ba..6a4936f 100644
--- a/lib/mini_profiler/storage/memory_store.rb
+++ b/lib/mini_profiler/storage/memory_store.rb
@@ -71,7 +71,7 @@ module Rack
         cleanup_cycle    = args.fetch(:cleanup_cycle)    { CLEANUP_CYCLE }
         t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do
           until Thread.current[:should_exit] do
-            CacheCleanupThread.current.sleepy_run
+            t.sleepy_run
           end
         end
         at_exit { t[:should_exit] = true }
diff --git a/spec/lib/storage/memory_store_spec.rb b/spec/lib/storage/memory_store_spec.rb
index cc2ce77..bfcef2a 100644
--- a/spec/lib/storage/memory_store_spec.rb
+++ b/spec/lib/storage/memory_store_spec.rb
@@ -83,56 +83,4 @@ describe Rack::MiniProfiler::MemoryStore do
     end
   end
 
-  describe 'cache cleanup thread' do
-    let(:described) { Rack::MiniProfiler::MemoryStore::CacheCleanupThread }
-    before do
-      store = double()
-      allow(store).to receive(:cleanup_cache)
-      @cleaner = described.new(1, 2, store) do
-        self.sleepy_run
-      end
-    end
-
-    it "just run on start" do
-      expect(@cleaner.should_cleanup?).to eq(false)
-    end
-
-    it "when number of runs * interval gets bigger than cycle, it should cleanup" do
-      @cleaner.increment_cycle
-      expect(@cleaner.should_cleanup?).to eq(true)
-    end
-
-    describe 'cleanup' do
-      before do
-        store = double()
-        expect(store).to receive(:cleanup_cache) { true }
-        @cleaner = described.new(1, 2, store) do
-          self.sleepy_run
-        end
-      end
-      it "calls store" do
-        @cleaner.cleanup
-      end
-
-      it "resets counter" do
-        @cleaner.increment_cycle
-        expect(@cleaner.cycle_count).to eq(2)
-        @cleaner.cleanup
-        expect(@cleaner.cycle_count).to eq(1)
-      end
-    end
-
-    describe 'sleepy_run' do
-      before do
-        store = double()
-        allow(store).to receive(:cleanup_cache)
-        @cleaner = described.new(0, 0, store) do
-          self.sleepy_run
-        end
-      end
-      it "works" do
-        @cleaner.sleepy_run
-      end
-    end
-  end
 end

GitHub

1 Like