Sha256: 125706769e06d1b886e3225f05ec5b42f0be2210d5b970aefa8d4257d748e3e3

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Garterbelt do
  describe 'cache module level methods' do
    describe '#cache_hash' do
      it 'creates a default hash when accessed the first time' do
        cache_hash = Garterbelt.cache_hash.dup
        cache_hash.class.should == Hash
        cache_hash[:default].is_a?(Moneta::Memory).should == true
        cache_hash.keys.size.should == 1
      end
      
      it 'gives direct access to the hash' do
        Garterbelt.cache_hash[:foo] = 'foo'
        Garterbelt.cache_hash[:foo].should == 'foo'
      end
    end
    
    describe '#cache' do
      it 'returns the :default if no arugment is received' do
        Garterbelt.cache.should == Garterbelt.cache_hash[:default]
      end
      
      it 'returns an alternative cache by key' do
        Garterbelt.cache_hash[:foo] = 'foo'
        Garterbelt.cache(:foo).should == 'foo'
      end
      
      it 'raises an error when accessing via a key that has no been configured' do
        Garterbelt.cache_hash[:bar].should be_nil
        lambda { Garterbelt.cache(:bar) }.should raise_error( "Cache :bar has not yet been configured" )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
garterbelt-0.0.7 spec/garterbelt_spec.rb
garterbelt-0.0.6 spec/garterbelt_spec.rb
garterbelt-0.0.5 spec/garterbelt_spec.rb