Sha256: 290b910d249ea095f73b9e059f41e7c7f35e10574b668eff2aeda148bca1dc82

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe '#del(key [, key, ...])' do
  before :all do
    sleep 1 - (Time.now.to_f % 1)
  end

  before :each do
    # TODO: Redis appears to be returning a timestamp a few seconds in the future
    # so we're ignoring the last 5 digits (time in milliseconds)
    @redises._gsub(/\d{5}-\d/, '...-.')
  end

  it 'returns the number of keys deleted' do
    @redises.set('mock-redis-test:1', 1)
    @redises.set('mock-redis-test:2', 1)

    @redises.del(
      'mock-redis-test:1',
      'mock-redis-test:2',
      'mock-redis-test:other'
    ).should == 2
  end

  it 'actually removes the key' do
    @redises.set('mock-redis-test:1', 1)
    @redises.del('mock-redis-test:1')

    @redises.get('mock-redis-test:1').should be_nil
  end

  it 'accepts an array of keys' do
    @redises.set('mock-redis-test:1', 1)
    @redises.set('mock-redis-test:2', 2)

    @redises.del(%w[mock-redis-test:1 mock-redis-test:2])

    @redises.get('mock-redis-test:1').should be_nil
    @redises.get('mock-redis-test:2').should be_nil
  end

  it 'raises an error if an empty array is given' do
    expect { @redises.del [] }.to raise_error Redis::CommandError
  end

  it 'removes a stream key' do
    @redises.xadd('mock-redis-stream', { key: 'value' }, maxlen: 0)
    expect(@redises.exists?('mock-redis-stream')).to eq true
    @redises.del('mock-redis-stream')
    expect(@redises.exists?('mock-redis-stream')).to eq false
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mock_redis-0.32.0 spec/commands/del_spec.rb
mock_redis-0.31.0 spec/commands/del_spec.rb
mock_redis-0.30.0 spec/commands/del_spec.rb
mock_redis-0.29.0 spec/commands/del_spec.rb
mock_redis-0.28.0 spec/commands/del_spec.rb
mock_redis-0.27.3 spec/commands/del_spec.rb
mock_redis-0.27.2 spec/commands/del_spec.rb
mock_redis-0.27.1 spec/commands/del_spec.rb
mock_redis-0.27.0 spec/commands/del_spec.rb