diff --git a/spec/acceptance/cache_store_config_for_allow2ban_spec.rb b/spec/acceptance/cache_store_config_for_allow2ban_spec.rb index ce99499..45f8f5c 100644 --- a/spec/acceptance/cache_store_config_for_allow2ban_spec.rb +++ b/spec/acceptance/cache_store_config_for_allow2ban_spec.rb @@ -12,9 +12,11 @@ describe "Cache store config when using allow2ban" do end end - it "gives semantic error if no store was configured" do - assert_raises(Rack::Attack::MissingStoreError) do - get "/scarce-resource" + unless defined?(Rails) + it "gives semantic error if no store was configured" do + assert_raises(Rack::Attack::MissingStoreError) do + get "/scarce-resource" + end end end diff --git a/spec/acceptance/cache_store_config_for_fail2ban_spec.rb b/spec/acceptance/cache_store_config_for_fail2ban_spec.rb index 6fd7980..b46f9fe 100644 --- a/spec/acceptance/cache_store_config_for_fail2ban_spec.rb +++ b/spec/acceptance/cache_store_config_for_fail2ban_spec.rb @@ -12,9 +12,11 @@ describe "Cache store config when using fail2ban" do end end - it "gives semantic error if no store was configured" do - assert_raises(Rack::Attack::MissingStoreError) do - get "/private-place" + unless defined?(Rails) + it "gives semantic error if no store was configured" do + assert_raises(Rack::Attack::MissingStoreError) do + get "/private-place" + end end end diff --git a/spec/acceptance/cache_store_config_for_throttle_spec.rb b/spec/acceptance/cache_store_config_for_throttle_spec.rb index 9be6e59..a89b827 100644 --- a/spec/acceptance/cache_store_config_for_throttle_spec.rb +++ b/spec/acceptance/cache_store_config_for_throttle_spec.rb @@ -9,9 +9,11 @@ describe "Cache store config when throttling without Rails" do end end - it "gives semantic error if no store was configured" do - assert_raises(Rack::Attack::MissingStoreError) do - get "/", {}, "REMOTE_ADDR" => "1.2.3.4" + unless defined?(Rails) + it "gives semantic error if no store was configured" do + assert_raises(Rack::Attack::MissingStoreError) do + get "/", {}, "REMOTE_ADDR" => "1.2.3.4" + end end end diff --git a/spec/acceptance/cache_store_config_with_rails_spec.rb b/spec/acceptance/cache_store_config_with_rails_spec.rb index 3d9ac22..66bb76a 100644 --- a/spec/acceptance/cache_store_config_with_rails_spec.rb +++ b/spec/acceptance/cache_store_config_with_rails_spec.rb @@ -11,10 +11,12 @@ describe "Cache store config with Rails" do end end - it "fails when Rails.cache is not set" do - Object.stub_const(:Rails, OpenStruct.new(cache: nil)) do - assert_raises(Rack::Attack::MissingStoreError) do - get "/", {}, "REMOTE_ADDR" => "1.2.3.4" + unless defined?(Rails) + it "fails when Rails.cache is not set" do + Object.stub_const(:Rails, OpenStruct.new(cache: nil)) do + assert_raises(Rack::Attack::MissingStoreError) do + get "/", {}, "REMOTE_ADDR" => "1.2.3.4" + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f529e6a..48ed773 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,6 +20,7 @@ end safe_require "connection_pool" safe_require "dalli" +safe_require "rails" safe_require "redis" safe_require "redis-store" @@ -27,7 +28,7 @@ class Minitest::Spec include Rack::Test::Methods before do - if Object.const_defined?(:Rails) && Rails.respond_to?(:cache) + if Object.const_defined?(:Rails) && Rails.respond_to?(:cache) && Rails.cache.respond_to?(:clear) Rails.cache.clear end end