Stub #with on delegator

This commit is contained in:
hakanensari 2014-04-09 13:15:00 +01:00
parent 0640a53cdf
commit f0a53f474e
2 changed files with 6 additions and 5 deletions

View file

@ -66,7 +66,7 @@ module Rack
class DalliProxy < SimpleDelegator
def initialize(client)
super(client)
stub_with_method_on_older_clients
stub_with_method_if_missing
end
def read(key)
@ -99,10 +99,11 @@ module Rack
private
# So we support Dalli < 2.7.0
def stub_with_method_on_older_clients
def stub_with_method_if_missing
unless __getobj__.respond_to?(:with)
def __getobj__.with; yield self; end
class << self
def with; yield __getobj__; end
end
end
end

View file

@ -146,7 +146,7 @@ describe Rack::Attack::Cache do
describe "given an older Dalli::Client" do
it "should stub #with" do
proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new)
proxy.must_respond_to :with
proxy.with {} # will not raise an error
end
end