Sha256: fdb68a03c36f12274321ccc5b2a1817b0bdbd9f96dcb6fedc8c756c5ea7b5fa3

Contents?: true

Size: 972 Bytes

Versions: 33

Compression:

Stored size: 972 Bytes

Contents

require 'spec_helper'

describe '#pttl(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.pttl(@key).should == -1
  end

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

  it 'stringifies key' do
    @redises.expire(@key, 8)
    # Don't check against Redis since millisecond timing differences are likely
    @redises.send_without_checking(:pttl, @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.round
      Time.stub(:now).and_return(@now)
    end

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/pttl_spec.rb
mock_redis-0.35.0 spec/commands/pttl_spec.rb
mock_redis-0.34.0 spec/commands/pttl_spec.rb
mock_redis-0.33.0 spec/commands/pttl_spec.rb
mock_redis-0.32.0 spec/commands/pttl_spec.rb
mock_redis-0.31.0 spec/commands/pttl_spec.rb
mock_redis-0.30.0 spec/commands/pttl_spec.rb
mock_redis-0.29.0 spec/commands/pttl_spec.rb
mock_redis-0.28.0 spec/commands/pttl_spec.rb
mock_redis-0.27.3 spec/commands/pttl_spec.rb
mock_redis-0.27.2 spec/commands/pttl_spec.rb
mock_redis-0.27.1 spec/commands/pttl_spec.rb
mock_redis-0.27.0 spec/commands/pttl_spec.rb
mock_redis-0.26.0 spec/commands/pttl_spec.rb
mock_redis-0.25.0 spec/commands/pttl_spec.rb
mock_redis-0.24.0 spec/commands/pttl_spec.rb
mock_redis-0.23.0 spec/commands/pttl_spec.rb
mock_redis-0.22.0 spec/commands/pttl_spec.rb
mock_redis-0.21.0 spec/commands/pttl_spec.rb
mock_redis-0.20.0 spec/commands/pttl_spec.rb