Sha256: b3e976a898941f8bd094e21895843cc5e2b7b71247392a65ede3cee515ea5aab

Contents?: true

Size: 850 Bytes

Versions: 8

Compression:

Stored size: 850 Bytes

Contents

require 'spec_helper'

describe "#ttl(key)" do
  before do
    @key = 'mock-redis-test:persist'
    @redises.set(@key, 'spork')
  end

  it "returns -1 for a key with no expiration" do
    @redises.ttl(@key).should == -1
  end

  it "returns -1 for a key that does not exist" do
    @redises.ttl('mock-redis-test:nonesuch').should == -1
  end

  it "stringifies key" do
    @redises.expire(@key, 9)
    @redises.ttl(@key.to_sym).should > 0
  end

  context "[mock only]" do
    # These are mock-only since we can't actually manipulate time in
    # the real Redis.

    before(:all) do
      @mock = @redises.mock
    end

    before do
      @now = Time.now
      Time.stub!(:now).and_return(@now)
    end

    it "gives you the key's remaining lifespan in seconds" do
      @mock.expire(@key, 5)
      @mock.ttl(@key).should == 5
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mock_redis-0.10.0 spec/commands/ttl_spec.rb
mock_redis-0.9.0 spec/commands/ttl_spec.rb
mock_redis-0.8.2 spec/commands/ttl_spec.rb
mock_redis-0.8.1 spec/commands/ttl_spec.rb
mock_redis-0.8.0 spec/commands/ttl_spec.rb
mock_redis-0.7.0 spec/commands/ttl_spec.rb
mock_redis-0.6.6 spec/commands/ttl_spec.rb
mock_redis-0.6.5 spec/commands/ttl_spec.rb