Sha256: 70668cde6e40ea85911a916813c8373c03c6fe3d06d6f82b2b0e36972240ed19

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'spec/spec_helper'

class TestRedis
  def self.to_s
    'Redis'
  end

  def initialize
    @wrapped = {}
  end

  def set(key, object)
    @wrapped[key] = object
  end

  def expire(key, seconds)
  end

  def [](x)
    @wrapped[x]
  end

  def clear
    @wrapped.clear
  end

  def del(key)
    @wrapped.delete(key)
  end
end

describe "Cachy::RedisWrapper" do
  before :all do
    @cache = TestRedis.new
    Cachy.cache_store = @cache
  end

  before do
    @cache.clear
  end

  it "is wrapped" do
    Cachy.cache_store.class.should == Cachy::RedisWrapper
  end

  it "can cache" do
    Cachy.cache(:x){ 'SUCCESS' }
    Cachy.cache(:x){ 'FAIL' }.should == 'SUCCESS'
  end

  it "can cache without expires" do
    @cache.should_receive(:set).with('x_v1', "--- SUCCESS\n")
    @cache.should_not_receive(:expire)
    Cachy.cache(:x){ 'SUCCESS' }.should == 'SUCCESS'
  end

  it "can cache with expires" do
    @cache.should_receive(:set).with('x_v1', "--- SUCCESS\n")
    @cache.should_receive(:expire).with('x_v1', 1)
    Cachy.cache(:x, :expires_in=>1){ 'SUCCESS' }.should == 'SUCCESS'
  end

  it "can expire" do
    @cache.should_receive(:del).with('x_v1')
    Cachy.expire(:x)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cachy-0.2.1 spec/cachy/redis_wrapper_spec.rb
cachy-0.2.0 spec/cachy/redis_wrapper_spec.rb
cachy-0.1.7 spec/cachy/redis_wrapper_spec.rb
cachy-0.1.6 spec/cachy/redis_wrapper_spec.rb
cachy-0.1.5 spec/cachy/redis_wrapper_spec.rb