Sha256: 1b80069da3ece726e4dd601bf55191a86713420a32c435fe45202f2e8f4bb33a

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

describe '#rpoplpush(source, destination)' do
  before do
    @list1 = 'mock-redis-test:rpoplpush-list1'
    @list2 = 'mock-redis-test:rpoplpush-list2'

    @redises.lpush(@list1, 'b')
    @redises.lpush(@list1, 'a')

    @redises.lpush(@list2, 'y')
    @redises.lpush(@list2, 'x')
  end

  it "returns the value moved" do
    @redises.rpoplpush(@list1, @list2).should == "b"
  end

  it "takes the last element of destination and prepends it to source" do
    @redises.rpoplpush(@list1, @list2)

    @redises.lrange(@list1, 0, -1).should == %w[a]
    @redises.lrange(@list2, 0, -1).should == %w[b x y]
  end

  it "rotates a list when source and destination are the same" do
    @redises.rpoplpush(@list1, @list1)
    @redises.lrange(@list1, 0, -1).should == %w[b a]
  end

  it "removes empty lists" do
    @redises.llen(@list1).times { @redises.rpoplpush(@list1, @list2) }
    @redises.get(@list1).should be_nil
  end

  it "raises an error for non-list source value" do
    @redises.set(@list1, 'string value')

    lambda do
      @redises.rpoplpush(@list1, @list2)
    end.should raise_error(RuntimeError)
  end

  it_should_behave_like "a list-only command"
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
mock_redis-0.6.6 spec/commands/rpoplpush_spec.rb
mock_redis-0.6.5 spec/commands/rpoplpush_spec.rb
mock_redis-0.6.4 spec/commands/rpoplpush_spec.rb
mock_redis-0.6.3 spec/commands/rpoplpush_spec.rb
mock_redis-0.6.2 spec/commands/rpoplpush_spec.rb
mock_redis-0.6.1 spec/commands/rpoplpush_spec.rb
mock_redis-0.6.0 spec/commands/rpoplpush_spec.rb
mock_redis-0.5.5 spec/commands/rpoplpush_spec.rb
mock_redis-0.5.4 spec/commands/rpoplpush_spec.rb
mock_redis-0.5.3 spec/commands/rpoplpush_spec.rb
mock_redis-0.5.2 spec/commands/rpoplpush_spec.rb
mock_redis-0.5.1 spec/commands/rpoplpush_spec.rb
mock_redis-0.5.0 spec/commands/rpoplpush_spec.rb
mock_redis-0.4.1 spec/commands/rpoplpush_spec.rb
mock_redis-0.4.0 spec/commands/rpoplpush_spec.rb
mock_redis-0.3.0 spec/commands/rpoplpush_spec.rb
ryansch-mock_redis-0.3.0 spec/commands/rpoplpush_spec.rb
ryansch-mock_redis-0.2.0.2 spec/commands/rpoplpush_spec.rb
ryansch-mock_redis-0.2.0.1 spec/commands/rpoplpush_spec.rb
mock_redis-0.2.0 spec/commands/rpoplpush_spec.rb