Sha256: b7f08ae78b8cee2292ec83e13a900f5dcd084cc10182ebc3d6e871ed069425cd

Contents?: true

Size: 1.25 KB

Versions: 28

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

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

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

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

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

    it 'does not iterate over any elements' do
      results = subject.zscan_each(key).map do |m, s|
        [m, s]
      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| ["m#{i}", i] } }

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

    context 'when giving a custom match filter' do
      let(:match) { 'm1*' }
      let(:collection) { Array.new(12) { |i| ["m#{i}", i] } }
      let(:expected) { [['m1', 1], ['m10', 10], ['m11', 11]] }

      it 'iterates over each item in the filtered collection' do
        results = subject.zscan_each(key, match: match).map do |m, s|
          [m, s]
        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/zscan_each_spec.rb
mock_redis-0.35.0 spec/commands/zscan_each_spec.rb
mock_redis-0.34.0 spec/commands/zscan_each_spec.rb
mock_redis-0.33.0 spec/commands/zscan_each_spec.rb
mock_redis-0.32.0 spec/commands/zscan_each_spec.rb
mock_redis-0.31.0 spec/commands/zscan_each_spec.rb
mock_redis-0.30.0 spec/commands/zscan_each_spec.rb
mock_redis-0.29.0 spec/commands/zscan_each_spec.rb
mock_redis-0.28.0 spec/commands/zscan_each_spec.rb
mock_redis-0.27.3 spec/commands/zscan_each_spec.rb
mock_redis-0.27.2 spec/commands/zscan_each_spec.rb
mock_redis-0.27.1 spec/commands/zscan_each_spec.rb
mock_redis-0.27.0 spec/commands/zscan_each_spec.rb
mock_redis-0.26.0 spec/commands/zscan_each_spec.rb
mock_redis-0.25.0 spec/commands/zscan_each_spec.rb
mock_redis-0.24.0 spec/commands/zscan_each_spec.rb
mock_redis-0.23.0 spec/commands/zscan_each_spec.rb
mock_redis-0.22.0 spec/commands/zscan_each_spec.rb
mock_redis-0.21.0 spec/commands/zscan_each_spec.rb
mock_redis-0.20.0 spec/commands/zscan_each_spec.rb