diff --git a/spec/integration/offline_spec.rb b/spec/integration/offline_spec.rb new file mode 100644 index 0000000..43f564f --- /dev/null +++ b/spec/integration/offline_spec.rb @@ -0,0 +1,47 @@ +require 'active_support/cache' +require 'active_support/cache/redis_store' +require 'dalli' +require_relative '../spec_helper' + +OfflineExamples = Minitest::SharedExamples.new do + + it 'should write' do + @cache.write('cache-test-key', 'foobar', 1) + end + + it 'should read' do + @cache.read('cache-test-key') + end + + it 'should count' do + @cache.send(:do_count, 'rack::attack::cache-test-key', 1) + end + +end + +describe 'when Redis is offline' do + include OfflineExamples + + before { + @cache = Rack::Attack::Cache.new + # Use presumably unused port for Redis client + @cache.store = ActiveSupport::Cache::RedisStore.new(:host => '127.0.0.1', :port => 3333) + } + +end + +describe 'when Memcached is offline' do + include OfflineExamples + + before { + Dalli.logger.level = Logger::FATAL + + @cache = Rack::Attack::Cache.new + @cache.store = Dalli::Client.new('127.0.0.1:22122') + } + + after { + Dalli.logger.level = Logger::INFO + } + +end diff --git a/spec/integration/rack_attack_cache_spec.rb b/spec/integration/rack_attack_cache_spec.rb index c3be000..df92c41 100644 --- a/spec/integration/rack_attack_cache_spec.rb +++ b/spec/integration/rack_attack_cache_spec.rb @@ -84,65 +84,6 @@ describe Rack::Attack::Cache do end - describe "should not error if redis is not running" do - before { - @cache = Rack::Attack::Cache.new - @key = "rack::attack:cache-test-key" - @expires_in = 1 - # Use presumably unused port for Redis client - @cache.store = ActiveSupport::Cache::RedisStore.new(:host => '127.0.0.1', :port => 3333) - } - describe "write" do - it "should not raise exception" do - @cache.write("cache-test-key", "foobar", 1) - end - end - - describe "read" do - it "should not raise exception" do - @cache.read("cache-test-key") - end - end - - describe "do_count" do - it "should not raise exception" do - @cache.send(:do_count, @key, @expires_in) - end - end - end - - describe "should not error if memcached is not running" do - before { - Dalli.logger.level = Logger::FATAL - @cache = Rack::Attack::Cache.new - @key = "rack::attack:cache-test-key" - @expires_in = 1 - @cache.store = Dalli::Client.new('127.0.0.1:22122') - } - - after { - Dalli.logger.level = Logger::INFO - } - - describe "write" do - it "should not raise exception" do - @cache.write("cache-test-key", "foobar", 1) - end - end - - describe "read" do - it "should not raise exception" do - @cache.read("cache-test-key") - end - end - - describe "do_count" do - it "should not raise exception" do - @cache.send(:do_count, @key, @expires_in) - end - end - end - describe "given an older Dalli::Client" do it "should stub #with" do proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7fe36a6..dec8563 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,3 +34,7 @@ class MiniTest::Spec end end end + +class Minitest::SharedExamples < Module + include Minitest::Spec::DSL +end