Sha256: a399c9c3dc3a7182827c92b22dd589c36a589b5e38f992f957eb465ebcadc79f

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

describe '#zrange(key, start, stop [, :with_scores => true])' do
  before do
    @key = 'mock-redis-test:zrange'
    @redises.zadd(@key, 1, 'Washington')
    @redises.zadd(@key, 2, 'Adams')
    @redises.zadd(@key, 3, 'Jefferson')
    @redises.zadd(@key, 4, 'Madison')
  end

  context 'when the zset is empty' do
    before do
      @redises.del(@key)
    end

    it 'should return an empty array' do
      @redises.exists(@key).should == false
      @redises.zrange(@key, 0, 4).should == []
    end
  end

  it 'returns the elements when the range is given as strings' do
    @redises.zrange(@key, '0', '1').should == %w[Washington Adams]
  end

  it 'returns the elements in order by score' do
    @redises.zrange(@key, 0, 1).should == %w[Washington Adams]
  end

  it 'returns the elements in order by score (negative indices)' do
    @redises.zrange(@key, -2, -1).should == %w[Jefferson Madison]
  end

  it 'returns empty list when start is too large' do
    @redises.zrange(@key, 5, -1).should == []
  end

  it 'returns the scores when :with_scores is specified' do
    @redises.zrange(@key, 0, 1, :with_scores => true).
      should == [['Washington', 1.0], ['Adams', 2.0]]
  end

  it 'returns the scores when :withscores is specified' do
    @redises.zrange(@key, 0, 1, :withscores => true).
      should == [['Washington', 1.0], ['Adams', 2.0]]
  end

  it_should_behave_like 'a zset-only command'
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mock_redis-0.15.3 spec/commands/zrange_spec.rb
mock_redis-0.15.2 spec/commands/zrange_spec.rb
mock_redis-0.15.1 spec/commands/zrange_spec.rb
mock_redis-0.15.0 spec/commands/zrange_spec.rb