Sha256: a8de508c1e26e4633f1660b730412c4133fd4dc5bfcd48de1acb6b677a2d1020

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

describe '#psetex(key, miliseconds, value)' do
  before { @key = 'mock-redis-test:setex' }

  it "responds with 'OK'" do
    @redises.psetex(@key, 10, 'value').should == 'OK'
  end

  it 'sets the value' do
    @redises.psetex(@key, 10_000, 'value')
    @redises.get(@key).should == 'value'
  end

  it 'sets the expiration time' do
    @redises.psetex(@key, 10_000, 'value')

    # no guarantee these are the same
    @redises.real.ttl(@key).should > 0
    @redises.mock.ttl(@key).should > 0
  end

  it 'converts time correctly' do
    @redises.psetex(@key, 10_000_000, 'value')

    @redises.mock.ttl(@key).should > 9_000
  end

  context 'when expiration time is zero' do
    it 'raises Redis::CommandError' do
      expect do
        @redises.psetex(@key, 0, 'value')
      end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
    end
  end

  context 'when expiration time is negative' do
    it 'raises Redis::CommandError' do
      expect do
        @redises.psetex(@key, -2, 'value')
      end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/psetex_spec.rb
mock_redis-0.35.0 spec/commands/psetex_spec.rb
mock_redis-0.34.0 spec/commands/psetex_spec.rb
mock_redis-0.33.0 spec/commands/psetex_spec.rb
mock_redis-0.32.0 spec/commands/psetex_spec.rb