Sha256: 85f25ce57bd2f6c039e66878ed42eb04e83acf4466d3186161e5755875b76b58

Contents?: true

Size: 1.42 KB

Versions: 12

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

require 'spec_helper'

describe '#brpoplpush(source, destination, timeout)' do
  before do
    @list1 = 'mock-redis-test:brpoplpush1'
    @list2 = 'mock-redis-test:brpoplpush2'

    @redises.rpush(@list1, 'A')
    @redises.rpush(@list1, 'B')

    @redises.rpush(@list2, 'alpha')
    @redises.rpush(@list2, 'beta')
  end

  it "takes the last element of source and prepends it to destination" do
    @redises.brpoplpush(@list1, @list2, 0)
    @redises.lrange(@list1, 0, -1).should == %w[A]
    @redises.lrange(@list2, 0, -1).should == %w[B alpha beta]
  end

  it "returns the moved element" do
    @redises.brpoplpush(@list1, @list2, 0).should == "B"
  end

  it "raises an error on non-integer timeout" do
    lambda do
      @redises.brpoplpush(@list1, @list2, 0.5)
    end.should raise_error(RuntimeError)
  end

  it "raises an error on negative timeout" do
    lambda do
      @redises.brpoplpush(@list1, @list2, -1)
    end.should raise_error(RuntimeError)
  end

  it_should_behave_like "a list-only command"

  context "[mock only]" do
    it "ignores positive timeouts and returns nil" do
      @redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 1).
        should be_nil
    end

    it "raises WouldBlock on zero timeout (no blocking in the mock)" do
      lambda do
        @redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 0)
      end.should raise_error(MockRedis::WouldBlock)
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
mock_redis-0.4.1 spec/commands/brpoplpush_spec.rb
mock_redis-0.4.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.3.0 spec/commands/brpoplpush_spec.rb
ryansch-mock_redis-0.3.0 spec/commands/brpoplpush_spec.rb
ryansch-mock_redis-0.2.0.2 spec/commands/brpoplpush_spec.rb
ryansch-mock_redis-0.2.0.1 spec/commands/brpoplpush_spec.rb
mock_redis-0.2.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.1.2 spec/commands/brpoplpush_spec.rb
mock_redis-0.1.1 spec/commands/brpoplpush_spec.rb
mock_redis-0.1.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.0.2 spec/commands/brpoplpush_spec.rb
mock_redis-0.0.1 spec/commands/brpoplpush_spec.rb