Skip to content

Commit

Permalink
Fix Rails test not being ran (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
santib committed Jan 10, 2024
1 parent cb82b9f commit 5124a17
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
8 changes: 5 additions & 3 deletions spec/acceptance/cache_store_config_for_allow2ban_spec.rb
Expand Up @@ -12,9 +12,11 @@
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

Expand Down
8 changes: 5 additions & 3 deletions spec/acceptance/cache_store_config_for_fail2ban_spec.rb
Expand Up @@ -12,9 +12,11 @@
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

Expand Down
8 changes: 5 additions & 3 deletions spec/acceptance/cache_store_config_for_throttle_spec.rb
Expand Up @@ -9,9 +9,11 @@
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

Expand Down
10 changes: 6 additions & 4 deletions spec/acceptance/cache_store_config_with_rails_spec.rb
Expand Up @@ -11,10 +11,12 @@
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
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -20,14 +20,15 @@ def safe_require(name)

safe_require "connection_pool"
safe_require "dalli"
safe_require "rails"
safe_require "redis"
safe_require "redis-store"

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
Expand Down

0 comments on commit 5124a17

Please sign in to comment.