Sha256: ac9072190e08df2950b1ee19d01e3deea45c834949d702c7ce1f1665fd423f6c

Contents?: true

Size: 1.26 KB

Versions: 33

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

describe '#lindex(key, index)' do
  before { @key = 'mock-redis-test:69312' }

  it 'gets an element from the list by its index' do
    @redises.lpush(@key, 20)
    @redises.lpush(@key, 10)

    @redises.lindex(@key, 0).should == '10'
    @redises.lindex(@key, 1).should == '20'
  end

  it 'treats negative indices as coming from the right' do
    @redises.lpush(@key, 20)
    @redises.lpush(@key, 10)

    @redises.lindex(@key, -1).should == '20'
    @redises.lindex(@key, -2).should == '10'
  end

  it 'gets an element from the list by its index when index is a string' do
    @redises.lpush(@key, 20)
    @redises.lpush(@key, 10)

    @redises.lindex(@key, '0').should == '10'
    @redises.lindex(@key, '1').should == '20'
    @redises.lindex(@key, '-1').should == '20'
    @redises.lindex(@key, '-2').should == '10'
  end

  it 'returns nil if the index is too large (and positive)' do
    @redises.lpush(@key, 20)

    @redises.lindex(@key, 100).should be_nil
  end

  it 'returns nil if the index is too large (and negative)' do
    @redises.lpush(@key, 20)

    @redises.lindex(@key, -100).should be_nil
  end

  it 'returns nil for nonexistent values' do
    @redises.lindex(@key, 0).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/lindex_spec.rb
mock_redis-0.35.0 spec/commands/lindex_spec.rb
mock_redis-0.34.0 spec/commands/lindex_spec.rb
mock_redis-0.33.0 spec/commands/lindex_spec.rb
mock_redis-0.32.0 spec/commands/lindex_spec.rb
mock_redis-0.31.0 spec/commands/lindex_spec.rb
mock_redis-0.30.0 spec/commands/lindex_spec.rb
mock_redis-0.29.0 spec/commands/lindex_spec.rb
mock_redis-0.28.0 spec/commands/lindex_spec.rb
mock_redis-0.27.3 spec/commands/lindex_spec.rb
mock_redis-0.27.2 spec/commands/lindex_spec.rb
mock_redis-0.27.1 spec/commands/lindex_spec.rb
mock_redis-0.27.0 spec/commands/lindex_spec.rb
mock_redis-0.26.0 spec/commands/lindex_spec.rb
mock_redis-0.25.0 spec/commands/lindex_spec.rb
mock_redis-0.24.0 spec/commands/lindex_spec.rb
mock_redis-0.23.0 spec/commands/lindex_spec.rb
mock_redis-0.22.0 spec/commands/lindex_spec.rb
mock_redis-0.21.0 spec/commands/lindex_spec.rb
mock_redis-0.20.0 spec/commands/lindex_spec.rb