Sha256: f1421d489ccb9fe266be6e9e37297422ed465719a3575101eb176280bf0fa577

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe '#blpop(key [, key, ...,], timeout)' do
  before do
    @list1 = 'mock-redis-test:blpop1'
    @list2 = 'mock-redis-test:blpop2'

    @redises.rpush(@list1, 'one')
    @redises.rpush(@list1, 'two')
    @redises.rpush(@list2, 'ten')
    @redises.rpush(@list2, 'eleven')
  end

  it "returns [first-nonempty-list, popped-value]" do
    @redises.blpop(@list1, @list2, 1).should == [@list1, 'one']
  end

  it "pops that value off the list" do
    @redises.blpop(@list1, @list2, 1)
    @redises.blpop(@list1, @list2, 1)

    @redises.blpop(@list1, @list2, 1).should == [@list2, 'ten']
  end

  it "ignores empty keys" do
    @redises.blpop('mock-redis-test:not-here', @list1, 1).should ==
      [@list1, 'one']
  end

  it "allows subsecond timeouts" do
    lambda do
      @redises.blpop(@list1, @list2, 0.5)
    end.should_not raise_error(Redis::CommandError)
  end

  it "raises an error on negative timeout" do
    lambda do
      @redises.blpop(@list1, @list2, -1)
    end.should raise_error(Redis::CommandError)
  end

  it_should_behave_like "a list-only command"

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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mock_redis-0.11.0 spec/commands/blpop_spec.rb
mock_redis-0.10.0 spec/commands/blpop_spec.rb
mock_redis-0.9.0 spec/commands/blpop_spec.rb
mock_redis-0.8.2 spec/commands/blpop_spec.rb
mock_redis-0.8.1 spec/commands/blpop_spec.rb
mock_redis-0.8.0 spec/commands/blpop_spec.rb
mock_redis-0.7.0 spec/commands/blpop_spec.rb
mock_redis-0.6.6 spec/commands/blpop_spec.rb
mock_redis-0.6.5 spec/commands/blpop_spec.rb
mock_redis-0.6.4 spec/commands/blpop_spec.rb
mock_redis-0.6.3 spec/commands/blpop_spec.rb
mock_redis-0.6.2 spec/commands/blpop_spec.rb
mock_redis-0.6.1 spec/commands/blpop_spec.rb
mock_redis-0.6.0 spec/commands/blpop_spec.rb
mock_redis-0.5.5 spec/commands/blpop_spec.rb
mock_redis-0.5.4 spec/commands/blpop_spec.rb
mock_redis-0.5.3 spec/commands/blpop_spec.rb
mock_redis-0.5.2 spec/commands/blpop_spec.rb
mock_redis-0.5.1 spec/commands/blpop_spec.rb
mock_redis-0.5.0 spec/commands/blpop_spec.rb