forked from sds/mock_redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_each_spec.rb
39 lines (30 loc) · 1.05 KB
/
scan_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
require 'spec_helper'
describe '#scan_each' do
subject { MockRedis::Database.new(double('base', logger: nil)) }
let(:match) { '*' }
before do
allow(subject).to receive_message_chain(:data, :keys).and_return(collection)
end
context 'when no keys are found' do
let(:collection) { [] }
it 'does not iterate over any elements' do
expect(subject.scan_each.to_a).to be_empty
end
end
context 'when keys are found' do
context 'when no match filter is supplied' do
let(:collection) { Array.new(20) { |i| "mock:key#{i}" } }
it 'iterates over each item in the collection' do
expect(subject.scan_each.to_a).to match_array(collection)
end
end
context 'when giving a custom match filter' do
let(:match) { 'mock:key*' }
let(:collection) { %w[mock:key mock:key2 mock:otherkey] }
let(:expected) { %w[mock:key mock:key2] }
it 'iterates over each item in the filtered collection' do
expect(subject.scan_each(match: match).to_a).to match_array(expected)
end
end
end
end