spec/itrigga-cache_spec.rb in itrigga-cache-0.2.1 vs spec/itrigga-cache_spec.rb in itrigga-cache-0.3.0

- old
+ new

@@ -18,10 +18,11 @@ describe Itrigga::Cache do before do + Itrigga::Cache.setup!(:backend=>:filecache) @klass = TriggaCacheTestClass.new @klass.stub!(:cache_log) # stub out the logging method in tests end describe "included" do @@ -59,23 +60,33 @@ Itrigga::Cache.setup!(@opts) end end describe "instance" do + before(:each) do + Itrigga::Cache.setup!(:backend=>:filecache) + end + it "should initialize the memcache client" do Itrigga::Cache::Memcache.should_receive(:instance).and_return(@instance = mock("Instance")) Itrigga::Cache.instance(:backend => :memcached).should == @instance end it "should initialize the filecache client" do Itrigga::Cache::Filecache.should_receive(:instance).and_return(@instance = mock("Instance")) Itrigga::Cache.instance(:backend => :filecache).should == @instance end - - it "should return the default @@ITRIGGA_CACHE_TYPE" do - Itrigga::Cache::Filecache.should_receive(:instance).and_return(@instance = mock("Instance", :cache => "a cache")) + context "when no backend given" do + it "should call instance on the default @@ITRIGGA_CACHE_TYPE" do + Itrigga::Cache::Filecache.should_receive(:instance).and_return(@instance = mock("Instance", :cache => "a cache")) + Itrigga::Cache.instance() + end + end + + it "should return the subclass instance" do + Itrigga::Cache::Filecache.stub!(:instance).and_return(@instance = mock("Instance", :cache => "a cache")) Itrigga::Cache.instance().should == @instance end end @@ -167,15 +178,21 @@ describe "get_from_cache" do before do Itrigga::Cache.stub!(:instance).and_return(@cache = mock("Cache")) @cache.stub!(:get).and_return("funky") + @cache.stub!(:enabled).and_return(true) end - it "should return nil if caching disabled" do - Itrigga::Cache.should_receive(:instance).and_return(nil) - @klass.class.send("get_from_cache","monkeys").should == nil + context "if caching disabled" do + before(:each) do + @cache.stub!(:enabled).and_return(false) + end + it "should return nil" do + @klass.class.send("get_from_cache","monkeys").should == nil + end + end it "should call get with the key" do @cache.should_receive(:get).with("monkeys") @klass.class.send("get_from_cache","monkeys") @@ -196,10 +213,11 @@ describe "set_to_cache" do before do Itrigga::Cache.stub!(:instance).and_return(@cache = mock("Cache")) @cache.stub!(:set) + @cache.stub!(:enabled).and_return(true) end describe "when no timeout" do before do @opts = {} @@ -355,11 +373,20 @@ @controller.stub!(:performed?).and_return(true) @controller.with_controller_cache(@opts) { nil } end it "should call render" do - @controller.should_receive(:render).with(:text => "content", :content_type => "text/html") + @controller.should_receive(:render).with(hash_including(:text => "content", :content_type => "text/html")) @controller.with_controller_cache(@opts) { "content" } + end + + + it "should call render with status set from the instance variable @status" do + @controller.should_receive(:render).with(hash_including(:status => 418)) + @controller.send(:instance_variable_set, "@status", 418) + @controller.with_controller_cache(@opts) { + "content" + } end it "should return the content" do @controller.with_controller_cache(@opts) { "content" }.should == "content" end \ No newline at end of file