Sha256: ce6776add9305e14834f9605cf1ca2c17e16fcbbdfce80f15f8f6df495d9b744

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'


describe MethodCacheable do
  before(:each) do
    @user = User.new
    @uniq ||= 0
    @uniq += 1
  end

  describe '' do
    describe 'calling a cached method' do
      describe 'fetch' do
        it 'should return the result of the normal method' do
          @user.cache.foo(@uniq).should == @user.foo(@uniq)
        end

        it 'should bypass the normal method if the cache is written' do
          @user.cache(:write).foo(@uniq)
          @user.should_not_receive(:foo)
          @user.cache(:fetch).foo(@uniq)
        end

        it 'should bypass the normal method if the cache has been fetched before' do
          @user.cache(:fetch).foo(@uniq)
          @user.should_not_receive(:foo)
          @user.cache(:fetch).foo(@uniq)
        end

        it 'should call the normal method if the cache has been not fetched before' do
          @user.should_receive(:foo)
          @user.cache(:fetch).foo(@uniq)
        end

        it 'should call the normal method if the cache has been not fetched before' do
          @user.should_receive(:foo)
          @user.cache.foo(@uniq)
        end

      end

      describe 'read' do
        it 'read should return nil if cache has not been set yet' do
          @user.cache(:read).foo(@uniq).should eq(nil)
        end

        it 'read should return value if cache has been set' do
          result = @user.cache.foo(@uniq)
          @user.cache(:read).foo(@uniq).should eq(result)
        end
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
method_cacheable-0.0.3 spec/method_cacheable_spec.rb
method_cacheable-0.0.2 spec/method_cacheable_spec.rb