Sha256: c867cd8ee9749318e3bc984bc15e31561c7e700ccd4652307fd15c45edcb9908

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe '#mget(key [, key, ...])' do
  before do
    @key1 = 'mock-redis-test:mget1'
    @key2 = 'mock-redis-test:mget2'

    @redises.set(@key1, 1)
    @redises.set(@key2, 2)
  end

  context 'emulate param array' do
    it 'returns an array of values' do
      @redises.mget([@key1, @key2]).should == %w[1 2]
    end

    it 'returns an array of values' do
      @redises.mget([@key1, @key2]).should == %w[1 2]
    end

    it 'returns nil for non-string keys' do
      list = 'mock-redis-test:mget-list'

      @redises.lpush(list, 'bork bork bork')

      @redises.mget([@key1, @key2, list]).should == ['1', '2', nil]
    end
  end

  context 'emulate params strings' do
    it 'returns an array of values' do
      @redises.mget(@key1, @key2).should == %w[1 2]
    end

    it 'returns nil for missing keys' do
      @redises.mget(@key1, 'mock-redis-test:not-found', @key2).should == ['1', nil, '2']
    end

    it 'returns nil for non-string keys' do
      list = 'mock-redis-test:mget-list'

      @redises.lpush(list, 'bork bork bork')

      @redises.mget(@key1, @key2, list).should == ['1', '2', nil]
    end

    it 'raises an error if you pass it 0 arguments' do
      lambda do
        @redises.mget
      end.should raise_error(Redis::CommandError)
    end

    it 'raises an error if you pass it empty array' do
      lambda do
        @redises.mget([])
      end.should raise_error(Redis::CommandError)
    end
  end

  context 'emulate block' do
    it 'returns an array of values' do
      @redises.mget(@key1, @key2) { |values| values.map(&:to_i) }.should == [1, 2]
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/mget_spec.rb
mock_redis-0.35.0 spec/commands/mget_spec.rb
mock_redis-0.34.0 spec/commands/mget_spec.rb
mock_redis-0.33.0 spec/commands/mget_spec.rb
mock_redis-0.32.0 spec/commands/mget_spec.rb
mock_redis-0.31.0 spec/commands/mget_spec.rb
mock_redis-0.30.0 spec/commands/mget_spec.rb
mock_redis-0.29.0 spec/commands/mget_spec.rb
mock_redis-0.28.0 spec/commands/mget_spec.rb