mock_redis 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/.travis.yml +9 -10
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -2
- data/README.md +2 -2
- data/lib/mock_redis/database.rb +6 -5
- data/lib/mock_redis/geospatial_methods.rb +10 -18
- data/lib/mock_redis/hash_methods.rb +4 -4
- data/lib/mock_redis/indifferent_hash.rb +0 -8
- data/lib/mock_redis/list_methods.rb +2 -2
- data/lib/mock_redis/pipelined_wrapper.rb +25 -6
- data/lib/mock_redis/set_methods.rb +15 -4
- data/lib/mock_redis/stream.rb +62 -0
- data/lib/mock_redis/stream/id.rb +53 -0
- data/lib/mock_redis/stream_methods.rb +87 -0
- data/lib/mock_redis/string_methods.rb +5 -8
- data/lib/mock_redis/transaction_wrapper.rb +25 -12
- data/lib/mock_redis/utility_methods.rb +1 -1
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset_methods.rb +2 -2
- data/mock_redis.gemspec +6 -5
- data/spec/commands/geodist_spec.rb +8 -4
- data/spec/commands/geohash_spec.rb +4 -4
- data/spec/commands/geopos_spec.rb +4 -4
- data/spec/commands/get_spec.rb +1 -0
- data/spec/commands/hdel_spec.rb +2 -2
- data/spec/commands/mget_spec.rb +34 -15
- data/spec/commands/mset_spec.rb +14 -0
- data/spec/commands/pipelined_spec.rb +52 -0
- data/spec/commands/spop_spec.rb +15 -0
- data/spec/commands/watch_spec.rb +8 -3
- data/spec/commands/xadd_spec.rb +102 -0
- data/spec/commands/xlen_spec.rb +20 -0
- data/spec/commands/xrange_spec.rb +141 -0
- data/spec/commands/xrevrange_spec.rb +130 -0
- data/spec/commands/xtrim_spec.rb +30 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/redis_multiplexer.rb +17 -1
- data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +14 -0
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -0
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -0
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -0
- data/spec/support/shared_examples/only_operates_on_zsets.rb +2 -0
- data/spec/transactions_spec.rb +17 -29
- metadata +38 -12
- data/spec/commands/hash_operator_spec.rb +0 -21
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#xtrim("mystream", 1000, approximate: true)' do
|
4
|
+
before { @key = 'mock-redis-test:xtrim' }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-0')
|
8
|
+
@redises.xadd(@key, { key2: 'value2' }, id: '1234567891245-0')
|
9
|
+
@redises.xadd(@key, { key3: 'value3' }, id: '1234567891245-1')
|
10
|
+
@redises.xadd(@key, { key4: 'value4' }, id: '1234567891278-0')
|
11
|
+
@redises.xadd(@key, { key5: 'value5' }, id: '1234567891278-1')
|
12
|
+
@redises.xadd(@key, { key6: 'value6' }, id: '1234567891299-0')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns the number of elements deleted' do
|
16
|
+
expect(@redises.xtrim(@key, 4)).to eq 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'deletes the oldes elements' do
|
20
|
+
@redises.xtrim(@key, 4)
|
21
|
+
expect(@redises.xrange(@key, '-', '+')).to eq(
|
22
|
+
[
|
23
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
24
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
25
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
26
|
+
['1234567891299-0', { 'key6' => 'value6' }]
|
27
|
+
]
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,7 @@ require 'rspec/its'
|
|
12
12
|
require 'redis'
|
13
13
|
$LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, '..', '..', 'lib')))
|
14
14
|
require 'mock_redis'
|
15
|
+
require 'timecop'
|
15
16
|
|
16
17
|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
17
18
|
Dir['spec/support/**/*.rb'].each { |x| require x }
|
@@ -59,5 +60,6 @@ RSpec.configure do |config|
|
|
59
60
|
@redises.send_without_checking(:del, key)
|
60
61
|
end
|
61
62
|
end
|
63
|
+
@redises._gsub_clear
|
62
64
|
end
|
63
65
|
end
|
@@ -10,6 +10,16 @@ class RedisMultiplexer < BlankSlate
|
|
10
10
|
def initialize(*a)
|
11
11
|
@mock_redis = MockRedis.new(*a)
|
12
12
|
@real_redis = Redis.new(*a)
|
13
|
+
_gsub_clear
|
14
|
+
end
|
15
|
+
|
16
|
+
def _gsub(from, to)
|
17
|
+
@gsub_from = from
|
18
|
+
@gsub_to = to
|
19
|
+
end
|
20
|
+
|
21
|
+
def _gsub_clear
|
22
|
+
@gsub_from = @gsub_to = ''
|
13
23
|
end
|
14
24
|
|
15
25
|
def method_missing(method, *args, &blk)
|
@@ -71,8 +81,10 @@ class RedisMultiplexer < BlankSlate
|
|
71
81
|
def equalish?(a, b)
|
72
82
|
if a == b
|
73
83
|
true
|
84
|
+
elsif a.is_a?(String) && b.is_a?(String)
|
85
|
+
masked(a) == masked(b)
|
74
86
|
elsif a.is_a?(Array) && b.is_a?(Array)
|
75
|
-
a.collect(
|
87
|
+
a.collect { |c| masked(c.to_s) }.sort == b.collect { |c| masked(c.to_s) }.sort
|
76
88
|
elsif a.is_a?(Exception) && b.is_a?(Exception)
|
77
89
|
a.class == b.class && a.message == b.message
|
78
90
|
elsif a.is_a?(Float) && b.is_a?(Float)
|
@@ -83,6 +95,10 @@ class RedisMultiplexer < BlankSlate
|
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
98
|
+
def masked(str)
|
99
|
+
str.gsub(@gsub_from, @gsub_to)
|
100
|
+
end
|
101
|
+
|
86
102
|
def mock
|
87
103
|
@mock_redis
|
88
104
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
shared_examples_for 'does not remove empty strings on error' do
|
2
|
+
it 'does not remove empty strings on error' do |example|
|
3
|
+
key = 'mock-redis-test:not-a-string'
|
4
|
+
|
5
|
+
method = method_from_description(example)
|
6
|
+
args = args_for_method(method).unshift(key)
|
7
|
+
|
8
|
+
@redises.set(key, '')
|
9
|
+
lambda do
|
10
|
+
@redises.send(method, *args)
|
11
|
+
end.should raise_error(RuntimeError)
|
12
|
+
@redises.get(key).should == ''
|
13
|
+
end
|
14
|
+
end
|
data/spec/transactions_spec.rb
CHANGED
@@ -10,11 +10,11 @@ describe 'transactions (multi/exec/discard)' do
|
|
10
10
|
@redises.multi.should == 'OK'
|
11
11
|
end
|
12
12
|
|
13
|
-
it '
|
13
|
+
it 'does not permit nesting' do
|
14
14
|
@redises.multi
|
15
15
|
lambda do
|
16
16
|
@redises.multi
|
17
|
-
end.should raise_error(Redis::CommandError)
|
17
|
+
end.should raise_error(Redis::CommandError, 'ERR MULTI calls can not be nested')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'cleans state of transaction wrapper if exception occurs during transaction' do
|
@@ -41,18 +41,18 @@ describe 'transactions (multi/exec/discard)' do
|
|
41
41
|
r.set('test', 1)
|
42
42
|
r.incr('counter')
|
43
43
|
end
|
44
|
-
@redises.get('counter').should
|
45
|
-
@redises.get('test').should
|
44
|
+
@redises.get('counter').should eq '6'
|
45
|
+
@redises.get('test').should eq '1'
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
48
|
+
it 'permits nesting via blocks' do
|
49
49
|
# Have to use only the mock here. redis-rb has a bug in it where
|
50
50
|
# nested #multi calls raise NoMethodError because it gets a nil
|
51
51
|
# where it's not expecting one.
|
52
52
|
@redises.mock.multi do |r|
|
53
53
|
lambda do
|
54
54
|
r.multi {}
|
55
|
-
end.
|
55
|
+
end.should_not raise_error
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -64,27 +64,15 @@ describe 'transactions (multi/exec/discard)' do
|
|
64
64
|
pr.incr('counter')
|
65
65
|
end
|
66
66
|
end
|
67
|
-
@redises.get('counter').should
|
68
|
-
@redises.get('test').should
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'allows multi blocks within pipelined blocks' do
|
72
|
-
@redises.set('counter', 5)
|
73
|
-
@redises.pipelined do |pr|
|
74
|
-
pr.multi do |r|
|
75
|
-
r.set('test', 1)
|
76
|
-
r.incr('counter')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
@redises.get('counter').should == '6'
|
80
|
-
@redises.get('test').should == '1'
|
67
|
+
@redises.get('counter').should eq '6'
|
68
|
+
@redises.get('test').should eq '1'
|
81
69
|
end
|
82
70
|
end
|
83
71
|
|
84
72
|
context '#discard' do
|
85
73
|
it "responds with 'OK' after #multi" do
|
86
74
|
@redises.multi
|
87
|
-
@redises.discard.should
|
75
|
+
@redises.discard.should eq 'OK'
|
88
76
|
end
|
89
77
|
|
90
78
|
it "can't be run outside of #multi/#exec" do
|
@@ -110,8 +98,8 @@ describe 'transactions (multi/exec/discard)' do
|
|
110
98
|
end
|
111
99
|
|
112
100
|
it "makes commands respond with 'QUEUED'" do
|
113
|
-
@redises.set(@string, 'string').should
|
114
|
-
@redises.lpush(@list, 'list').should
|
101
|
+
@redises.set(@string, 'string').should eq 'QUEUED'
|
102
|
+
@redises.lpush(@list, 'list').should eq 'QUEUED'
|
115
103
|
end
|
116
104
|
|
117
105
|
it "gives you the commands' responses when you call #exec" do
|
@@ -119,7 +107,7 @@ describe 'transactions (multi/exec/discard)' do
|
|
119
107
|
@redises.lpush(@list, 'list')
|
120
108
|
@redises.lpush(@list, 'list')
|
121
109
|
|
122
|
-
@redises.exec.should
|
110
|
+
@redises.exec.should eq ['OK', 1, 2]
|
123
111
|
end
|
124
112
|
|
125
113
|
it "does not raise exceptions, but rather puts them in #exec's response" do
|
@@ -128,9 +116,9 @@ describe 'transactions (multi/exec/discard)' do
|
|
128
116
|
@redises.lpush(@list, 'list')
|
129
117
|
|
130
118
|
responses = @redises.exec
|
131
|
-
responses[0].should
|
119
|
+
responses[0].should eq 'OK'
|
132
120
|
responses[1].should be_a(Redis::CommandError)
|
133
|
-
responses[2].should
|
121
|
+
responses[2].should eq 1
|
134
122
|
end
|
135
123
|
end
|
136
124
|
|
@@ -151,9 +139,9 @@ describe 'transactions (multi/exec/discard)' do
|
|
151
139
|
second_lpush_response = mult.lpush(@list, 'list')
|
152
140
|
end
|
153
141
|
|
154
|
-
set_response.value.should
|
155
|
-
lpush_response.value.should
|
156
|
-
second_lpush_response.value.should
|
142
|
+
set_response.value.should eq 'OK'
|
143
|
+
lpush_response.value.should eq 1
|
144
|
+
second_lpush_response.value.should eq 2
|
157
145
|
end
|
158
146
|
end
|
159
147
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Shane da Silva
|
8
8
|
- Samuel Merritt
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -37,14 +37,14 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.1.0
|
41
41
|
type: :development
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.1.0
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,10 +73,24 @@ dependencies:
|
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: timecop
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.1
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.1
|
76
90
|
description: Instantiate one with `redis = MockRedis.new` and treat it like you would
|
77
91
|
a normal Redis object. It supports all the usual Redis operations.
|
78
92
|
email:
|
79
|
-
-
|
93
|
+
- shane@dasilva.io
|
80
94
|
executables: []
|
81
95
|
extensions: []
|
82
96
|
extra_rdoc_files: []
|
@@ -109,6 +123,9 @@ files:
|
|
109
123
|
- lib/mock_redis/pipelined_wrapper.rb
|
110
124
|
- lib/mock_redis/set_methods.rb
|
111
125
|
- lib/mock_redis/sort_method.rb
|
126
|
+
- lib/mock_redis/stream.rb
|
127
|
+
- lib/mock_redis/stream/id.rb
|
128
|
+
- lib/mock_redis/stream_methods.rb
|
112
129
|
- lib/mock_redis/string_methods.rb
|
113
130
|
- lib/mock_redis/transaction_wrapper.rb
|
114
131
|
- lib/mock_redis/undef_redis_methods.rb
|
@@ -151,7 +168,6 @@ files:
|
|
151
168
|
- spec/commands/getbit_spec.rb
|
152
169
|
- spec/commands/getrange_spec.rb
|
153
170
|
- spec/commands/getset_spec.rb
|
154
|
-
- spec/commands/hash_operator_spec.rb
|
155
171
|
- spec/commands/hdel_spec.rb
|
156
172
|
- spec/commands/hexists_spec.rb
|
157
173
|
- spec/commands/hget_spec.rb
|
@@ -240,6 +256,11 @@ files:
|
|
240
256
|
- spec/commands/type_spec.rb
|
241
257
|
- spec/commands/unwatch_spec.rb
|
242
258
|
- spec/commands/watch_spec.rb
|
259
|
+
- spec/commands/xadd_spec.rb
|
260
|
+
- spec/commands/xlen_spec.rb
|
261
|
+
- spec/commands/xrange_spec.rb
|
262
|
+
- spec/commands/xrevrange_spec.rb
|
263
|
+
- spec/commands/xtrim_spec.rb
|
243
264
|
- spec/commands/zadd_spec.rb
|
244
265
|
- spec/commands/zcard_spec.rb
|
245
266
|
- spec/commands/zcount_spec.rb
|
@@ -261,6 +282,7 @@ files:
|
|
261
282
|
- spec/mock_redis_spec.rb
|
262
283
|
- spec/spec_helper.rb
|
263
284
|
- spec/support/redis_multiplexer.rb
|
285
|
+
- spec/support/shared_examples/does_not_cleanup_empty_strings.rb
|
264
286
|
- spec/support/shared_examples/only_operates_on_hashes.rb
|
265
287
|
- spec/support/shared_examples/only_operates_on_lists.rb
|
266
288
|
- spec/support/shared_examples/only_operates_on_sets.rb
|
@@ -268,7 +290,7 @@ files:
|
|
268
290
|
- spec/support/shared_examples/only_operates_on_zsets.rb
|
269
291
|
- spec/support/shared_examples/sorts_enumerables.rb
|
270
292
|
- spec/transactions_spec.rb
|
271
|
-
homepage: https://github.com/
|
293
|
+
homepage: https://github.com/sds/mock_redis
|
272
294
|
licenses:
|
273
295
|
- MIT
|
274
296
|
metadata: {}
|
@@ -280,15 +302,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
280
302
|
requirements:
|
281
303
|
- - ">="
|
282
304
|
- !ruby/object:Gem::Version
|
283
|
-
version: '2.
|
305
|
+
version: '2.4'
|
284
306
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
285
307
|
requirements:
|
286
308
|
- - ">="
|
287
309
|
- !ruby/object:Gem::Version
|
288
310
|
version: '0'
|
289
311
|
requirements: []
|
290
|
-
|
291
|
-
rubygems_version: 2.7.3
|
312
|
+
rubygems_version: 3.0.3
|
292
313
|
signing_key:
|
293
314
|
specification_version: 4
|
294
315
|
summary: Redis mock that just lives in memory; useful for testing.
|
@@ -327,7 +348,6 @@ test_files:
|
|
327
348
|
- spec/commands/getbit_spec.rb
|
328
349
|
- spec/commands/getrange_spec.rb
|
329
350
|
- spec/commands/getset_spec.rb
|
330
|
-
- spec/commands/hash_operator_spec.rb
|
331
351
|
- spec/commands/hdel_spec.rb
|
332
352
|
- spec/commands/hexists_spec.rb
|
333
353
|
- spec/commands/hget_spec.rb
|
@@ -416,6 +436,11 @@ test_files:
|
|
416
436
|
- spec/commands/type_spec.rb
|
417
437
|
- spec/commands/unwatch_spec.rb
|
418
438
|
- spec/commands/watch_spec.rb
|
439
|
+
- spec/commands/xadd_spec.rb
|
440
|
+
- spec/commands/xlen_spec.rb
|
441
|
+
- spec/commands/xrange_spec.rb
|
442
|
+
- spec/commands/xrevrange_spec.rb
|
443
|
+
- spec/commands/xtrim_spec.rb
|
419
444
|
- spec/commands/zadd_spec.rb
|
420
445
|
- spec/commands/zcard_spec.rb
|
421
446
|
- spec/commands/zcount_spec.rb
|
@@ -437,6 +462,7 @@ test_files:
|
|
437
462
|
- spec/mock_redis_spec.rb
|
438
463
|
- spec/spec_helper.rb
|
439
464
|
- spec/support/redis_multiplexer.rb
|
465
|
+
- spec/support/shared_examples/does_not_cleanup_empty_strings.rb
|
440
466
|
- spec/support/shared_examples/only_operates_on_hashes.rb
|
441
467
|
- spec/support/shared_examples/only_operates_on_lists.rb
|
442
468
|
- spec/support/shared_examples/only_operates_on_sets.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#[](key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hash_operator'
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns nil for a nonexistent value' do
|
9
|
-
@redises['mock-redis-test:does-not-exist'].should be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns a stored string value' do
|
13
|
-
@redises[@key] = 'forsooth'
|
14
|
-
@redises[@key].should == 'forsooth'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'treats integers as strings' do
|
18
|
-
@redises[@key] = 100
|
19
|
-
@redises[@key].should == '100'
|
20
|
-
end
|
21
|
-
end
|