Sha256: b19ec2ade4f8f28bb02f9dea4b7cbf22bf540304c75595de6e0185c79837b625

Contents?: true

Size: 1.46 KB

Versions: 33

Compression:

Stored size: 1.46 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)
    @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).should == 'B'
  end

  it 'raises an error on negative timeout' do
    lambda do
      @redises.brpoplpush(@list1, @list2, :timeout => -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.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 1).
        should be_nil
    end

    it 'ignores positive legacy 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, :timeout => 0)
      end.should raise_error(MockRedis::WouldBlock)
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
mock_redis-0.19.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.18.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.17.3 spec/commands/brpoplpush_spec.rb
mock_redis-0.17.2 spec/commands/brpoplpush_spec.rb
mock_redis-0.17.1 spec/commands/brpoplpush_spec.rb
mock_redis-0.17.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.16.1 spec/commands/brpoplpush_spec.rb
mock_redis-0.16.0 spec/commands/brpoplpush_spec.rb
mock_redis-0.15.4 spec/commands/brpoplpush_spec.rb
mock_redis-0.15.3 spec/commands/brpoplpush_spec.rb
mock_redis-0.15.2 spec/commands/brpoplpush_spec.rb
mock_redis-0.15.1 spec/commands/brpoplpush_spec.rb
mock_redis-0.15.0 spec/commands/brpoplpush_spec.rb