Sha256: d5f13d68bd2e2c98f33b69466f0c0d1d8a6de8e3fa4cf801ddee439bd406db0f

Contents?: true

Size: 1.21 KB

Versions: 33

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe '#ltrim(key, start, stop)' do
  before do
    @key = 'mock-redis-test:22310'

    %w[v0 v1 v2 v3 v4].reverse_each { |v| @redises.lpush(@key, v) }
  end

  it "returns 'OK'" do
    @redises.ltrim(@key, 1, 3).should == 'OK'
  end

  it 'trims the list to include only the specified elements' do
    @redises.ltrim(@key, 1, 3)
    @redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
  end

  it 'trims the list when start and stop are strings' do
    @redises.ltrim(@key, '1', '3')
    @redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
  end

  it 'trims the list to include only the specified elements (negative indices)' do
    @redises.ltrim(@key, -2, -1)
    @redises.lrange(@key, 0, -1).should == %w[v3 v4]
  end

  it 'trims the list to include only the specified elements (out of range negative indices)' do
    @redises.ltrim(@key, -10, -2)
    @redises.lrange(@key, 0, -1).should == %w[v0 v1 v2 v3]
  end

  it 'does not crash on overly-large indices' do
    @redises.ltrim(@key, 100, 200)
    @redises.lrange(@key, 0, -1).should == %w[]
  end

  it 'removes empty lists' do
    @redises.ltrim(@key, 1, 0)
    @redises.get(@key).should be_nil
  end

  it_should_behave_like 'a list-only command'
end

Version data entries

33 entries across 33 versions & 1 rubygems

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