require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Itrigga::Cache::Memcache do before do Itrigga::Cache::Memcache.reset_instance ::Memcached.stub!(:new).and_return(@memcached = mock("Memcached")) @instance = Itrigga::Cache::Memcache.instance end it "should include Singleton" do Itrigga::Cache::Memcache.should include Singleton end describe "setup!" do it "should call Memcached.new with default server" do Memcached.should_receive(:new).with("localhost:11211",{}) Itrigga::Cache::Memcache.setup! end it "should call Memcached.new with given server" do Memcached.should_receive(:new).with("funky monkeys",{:abc => 123}) Itrigga::Cache::Memcache.setup!(:servers => "funky monkeys", :abc => 123) end it "should call Memcached.new with timeout" do Memcached.should_receive(:new).with("funky monkeys",{:default_ttl => 42}) Itrigga::Cache::Memcache.setup!(:servers => "funky monkeys", :timeout => 42) end it "should call Memcached.new with timeout" do Memcached.should_receive(:new).with("funky monkeys",{:default_ttl => 42}) Itrigga::Cache::Memcache.setup!(:servers => "funky monkeys", :default_ttl => 42) end it "should assign the memcached instance" do Itrigga::Cache::Memcache.setup!(:servers => "funky monkeys", :default_ttl => 42) Itrigga::Cache::Memcache.instance.cache.should == @memcached end end describe "instance_methods" do before do @instance.stub!(:cache).and_return(@cache = mock("Memcached")) end describe "get" do it "should call cache.get" do @cache.should_receive(:get).with("key") @instance.get("key") end end describe "set" do it "should call cache.set" do @cache.should_receive(:set).with("key","content",42) @instance.set("key","content",{:timeout => 42}) end end describe "delete" do it "should call cache.delete" do @cache.should_receive(:delete).with("key") @instance.delete("key") end end end end