Sha256: 10ea84b568d447667c1292ee98c38e86794927b2706144b37123dd5261bae2e1

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

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

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

  it "returns the scores when :with_scores is specified" do
    @redises.zrangebyscore(@key, 1, 2, :with_scores => true).
      should == ["Washington", "1", "Adams", "2"]
  end

  it "returns the scores when :withscores is specified" do
    @redises.zrangebyscore(@key, 1, 2, :withscores => true).
      should == ["Washington", "1", "Adams", "2"]
  end

  it "honors the :limit => [offset count] argument" do
    @redises.zrangebyscore(@key, -100, 100, :limit => [1, 2]).
      should == ["Adams", "Jefferson"]
  end

  it "raises an error if :limit isn't a 2-tuple" do
    lambda do
      @redises.zrangebyscore(@key, -100, 100, :limit => [1, 2, 3])
    end.should raise_error(RuntimeError)

    lambda do
      @redises.zrangebyscore(@key, -100, 100, :limit => "1, 2")
    end.should raise_error(RuntimeError)
  end

  it_should_behave_like "a zset-only command"
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mock_redis-0.1.0 spec/commands/zrangebyscore_spec.rb
mock_redis-0.0.2 spec/commands/zrangebyscore_spec.rb
mock_redis-0.0.1 spec/commands/zrangebyscore_spec.rb