Sha256: dc942d840adc051cd2c9a90c840e84b8fd3f2538387b4d7b44bc5d3c07bbb773

Contents?: true

Size: 1022 Bytes

Versions: 1

Compression:

Stored size: 1022 Bytes

Contents

require 'spec_helper'

describe APICache::Cache do
  before :each do
    @options = {
      :cache => 1,    # After this time fetch new data
      :valid => 2   # Maximum time to use old data
    }
  end

  it "should set and get" do
    cache = APICache::Cache.new('flubble', @options)

    cache.set('Hello world')
    cache.get.should == 'Hello world'
  end

  it "should md5 encode the provided key" do
    cache = APICache::Cache.new('test_md5', @options)
    APICache.store.should_receive(:set).
      with('9050bddcf415f2d0518804e551c1be98', 'md5ing?')
    cache.set('md5ing?')
  end

  it "should report correct invalid states" do
    cache = APICache::Cache.new('foo', @options)

    cache.state.should == :missing
    cache.set('foo')
    cache.state.should == :current
    sleep 1
    cache.state.should == :refetch
    sleep 1
    cache.state.should == :invalid
  end

  it "should initially have invalid state" do
    cache = APICache::Cache.new('foo', @options)
    cache.state.should == :invalid
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api_cache-0.3.0 spec/cache_spec.rb