From 79d0bbf0789b3d705503f06881e96062f6df39c8 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 25 Jul 2023 14:33:39 +1200 Subject: [PATCH] Optional Rails.cache reset before each test. --- spec/acceptance/cache_store_config_with_rails_spec.rb | 6 ------ spec/spec_helper.rb | 11 +++++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/spec/acceptance/cache_store_config_with_rails_spec.rb b/spec/acceptance/cache_store_config_with_rails_spec.rb index 20c32948..3d9ac22f 100644 --- a/spec/acceptance/cache_store_config_with_rails_spec.rb +++ b/spec/acceptance/cache_store_config_with_rails_spec.rb @@ -9,12 +9,6 @@ Rack::Attack.throttle("by ip", limit: 1, period: 60) do |request| request.ip end - - Rack::Attack.instance_variable_set(:@cache, nil) - end - - after do - Rack::Attack.instance_variable_set(:@cache, nil) end it "fails when Rails.cache is not set" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4ab8a1b0..ef715339 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,6 @@ require "minitest/autorun" require "minitest/pride" require "rack/test" -# require "rails" require "active_support" require "rack/attack" @@ -28,11 +27,11 @@ def safe_require(name) class MiniTest::Spec include Rack::Test::Methods - # if Object.const_defined?(:Rails) - # before do - # Rails.cache = nil - # end - # end + before do + if Object.const_defined?(:Rails) && Rails.respond_to?(:cache) + Rails.cache.clear + end + end after do Rack::Attack.clear_configuration