Sha256: de0bf60a24d989e56100c8a0eb9aa83f4f601c72bae166d3ec26849a3803418a

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 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 be_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 == ['Washington', 'Adams']
  end

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

  it "returns the elements in order by score (negative indices)" do
    @redises.zrange(@key, -2, -1).should == ['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

6 entries across 6 versions & 1 rubygems

Version Path
mock_redis-0.13.2 spec/commands/zrange_spec.rb
mock_redis-0.13.1 spec/commands/zrange_spec.rb
mock_redis-0.13.0 spec/commands/zrange_spec.rb
mock_redis-0.12.1 spec/commands/zrange_spec.rb
mock_redis-0.12.0 spec/commands/zrange_spec.rb
mock_redis-0.11.0 spec/commands/zrange_spec.rb