Sha256: 3b794a08a6d986148099bcf4782031bb20e7ce29443c5b608a97079974c1b5f6

Contents?: true

Size: 1.27 KB

Versions: 28

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe '#hscan_each' do
  subject { MockRedis::Database.new(self) }

  let(:key) { 'mock-redis-test:hscan_each' }

  before do
    allow(subject).to receive(:hgetall).and_return(collection)
  end

  context 'when no keys are found' do
    let(:collection) { [] }

    it 'does not iterate over any elements' do
      results = subject.hscan_each(key).map do |k, v|
        [k, v]
      end
      expect(results).to match_array(collection)
    end
  end

  context 'when keys are found' do
    context 'when no match filter is supplied' do
      let(:collection) { Array.new(20) { |i| ["k#{i}", "v#{i}"] } }

      it 'iterates over each item in the collection' do
        results = subject.hscan_each(key).map do |k, v|
          [k, v]
        end
        expect(results).to match_array(collection)
      end
    end

    context 'when giving a custom match filter' do
      let(:match) { 'k1*' }
      let(:collection) { Array.new(12) { |i| ["k#{i}", "v#{i}"] } }
      let(:expected) { [%w[k1 v1], %w[k10 v10], %w[k11 v11]] }

      it 'iterates over each item in the filtered collection' do
        results = subject.hscan_each(key, match: match).map do |k, v|
          [k, v]
        end
        expect(results).to match_array(expected)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/hscan_each_spec.rb
mock_redis-0.35.0 spec/commands/hscan_each_spec.rb
mock_redis-0.34.0 spec/commands/hscan_each_spec.rb
mock_redis-0.33.0 spec/commands/hscan_each_spec.rb
mock_redis-0.32.0 spec/commands/hscan_each_spec.rb
mock_redis-0.31.0 spec/commands/hscan_each_spec.rb
mock_redis-0.30.0 spec/commands/hscan_each_spec.rb
mock_redis-0.29.0 spec/commands/hscan_each_spec.rb
mock_redis-0.28.0 spec/commands/hscan_each_spec.rb
mock_redis-0.27.3 spec/commands/hscan_each_spec.rb
mock_redis-0.27.2 spec/commands/hscan_each_spec.rb
mock_redis-0.27.1 spec/commands/hscan_each_spec.rb
mock_redis-0.27.0 spec/commands/hscan_each_spec.rb
mock_redis-0.26.0 spec/commands/hscan_each_spec.rb
mock_redis-0.25.0 spec/commands/hscan_each_spec.rb
mock_redis-0.24.0 spec/commands/hscan_each_spec.rb
mock_redis-0.23.0 spec/commands/hscan_each_spec.rb
mock_redis-0.22.0 spec/commands/hscan_each_spec.rb
mock_redis-0.21.0 spec/commands/hscan_each_spec.rb
mock_redis-0.20.0 spec/commands/hscan_each_spec.rb