Sha256: 56143426cc4b0520aa2e98a5a3aab4077110b433221dfa7fa2eba1907b323667

Contents?: true

Size: 1.27 KB

Versions: 13

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe '#hdel(key, field)' do
  before do
    @key = 'mock-redis-test:hdel'
    @redises.hset(@key, 'k1', 'v1')
    @redises.hset(@key, 'k2', 'v2')
  end

  it 'returns 1 when it removes a field' do
    @redises.hdel(@key, 'k1').should == 1
  end

  it 'returns 0 when it does not remove a field' do
    @redises.hdel(@key, 'nonesuch').should == 0
  end

  it 'actually removes the field' do
    @redises.hdel(@key, 'k1')
    @redises.hget(@key, 'k1').should be_nil
  end

  it 'treats the field as a string' do
    field = 2
    @redises.hset(@key, field, 'two')
    @redises.hdel(@key, field)
    @redises.hget(@key, field).should be_nil
  end

  it 'removes only the field specified' do
    @redises.hdel(@key, 'k1')
    @redises.hget(@key, 'k2').should == 'v2'
  end

  it 'cleans up empty hashes' do
    @redises.hdel(@key, 'k1')
    @redises.hdel(@key, 'k2')
    @redises.get(@key).should be_nil
  end

  it 'supports a variable number of arguments' do
    @redises.hdel(@key, %w[k1 k2])
    @redises.get(@key).should be_nil
  end

  it 'treats variable arguments as strings' do
    field = 2
    @redises.hset(@key, field, 'two')
    @redises.hdel(@key, [field])
    @redises.hget(@key, field).should be_nil
  end

  it_should_behave_like 'a hash-only command'
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mock_redis-0.19.0 spec/commands/hdel_spec.rb
mock_redis-0.18.0 spec/commands/hdel_spec.rb
mock_redis-0.17.3 spec/commands/hdel_spec.rb
mock_redis-0.17.2 spec/commands/hdel_spec.rb
mock_redis-0.17.1 spec/commands/hdel_spec.rb
mock_redis-0.17.0 spec/commands/hdel_spec.rb
mock_redis-0.16.1 spec/commands/hdel_spec.rb
mock_redis-0.16.0 spec/commands/hdel_spec.rb
mock_redis-0.15.4 spec/commands/hdel_spec.rb
mock_redis-0.15.3 spec/commands/hdel_spec.rb
mock_redis-0.15.2 spec/commands/hdel_spec.rb
mock_redis-0.15.1 spec/commands/hdel_spec.rb
mock_redis-0.15.0 spec/commands/hdel_spec.rb