forked from sds/mock_redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sscan_each_spec.rb
48 lines (39 loc) · 1.22 KB
/
sscan_each_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'spec_helper'
describe '#sscan_each' do
subject { MockRedis::Database.new(double('base', logger: nil)) }
let(:key) { 'mock-redis-test:sscan_each' }
before do
allow(subject).to receive(:smembers).and_return(collection)
end
context 'when no keys are found' do
let(:collection) { [] }
it 'does not iterate over any elements' do
results = subject.sscan_each(key).map do |k|
k
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}" } }
it 'iterates over each item in the collection' do
results = subject.sscan_each(key).map do |k|
k
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}" } }
let(:expected) { %w[k1 k10 k11] }
it 'iterates over each item in the filtered collection' do
results = subject.sscan_each(key, match: match).map do |k|
k
end
expect(results).to match_array(expected)
end
end
end
end