Move offline case to separate file

This commit is contained in:
hakanensari 2014-04-15 16:17:27 +01:00
parent f0a53f474e
commit bf40123c04
3 changed files with 51 additions and 59 deletions

View file

@ -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

View file

@ -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)

View file

@ -34,3 +34,7 @@ class MiniTest::Spec
end
end
end
class Minitest::SharedExamples < Module
include Minitest::Spec::DSL
end