Sha256: 4382cdafd3f8becfb305a106f40ea9d7888e6c2a310a082d2d52a057689031fe

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

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

describe Garterbelt do
  describe 'wrap length' do
    after :all do
      Garterbelt.wrap_length = 80
    end
    
    it 'is 80 by default' do
      Garterbelt.wrap_length.should == 80
    end
    
    it 'can be customized' do
      Garterbelt.wrap_length = 50
      Garterbelt.wrap_length.should == 50
    end
  end
  
  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

4 entries across 4 versions & 1 rubygems

Version Path
garterbelt-0.1.1 spec/garterbelt_spec.rb
garterbelt-0.1.0 spec/garterbelt_spec.rb
garterbelt-0.0.9 spec/garterbelt_spec.rb
garterbelt-0.0.8 spec/garterbelt_spec.rb