mock_redis 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- data/spec/cloning_spec.rb +17 -18
- data/spec/commands/append_spec.rb +4 -4
- data/spec/commands/auth_spec.rb +1 -1
- data/spec/commands/bgrewriteaof_spec.rb +2 -2
- data/spec/commands/bgsave_spec.rb +2 -2
- data/spec/commands/bitcount_spec.rb +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
@@ -1,5 +1,5 @@
|
|
1
|
-
shared_examples_for
|
2
|
-
it
|
1
|
+
shared_examples_for 'a hash-only command' do
|
2
|
+
it 'raises an error for non-hash values' do |example|
|
3
3
|
key = 'mock-redis-test:hash-only'
|
4
4
|
|
5
5
|
method = method_from_description(example)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
shared_examples_for
|
2
|
-
it
|
1
|
+
shared_examples_for 'a list-only command' do
|
2
|
+
it 'raises an error for non-list values' do |example|
|
3
3
|
key = 'mock-redis-test:list-only'
|
4
4
|
|
5
5
|
method = method_from_description(example)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
shared_examples_for
|
2
|
-
it
|
1
|
+
shared_examples_for 'a set-only command' do
|
2
|
+
it 'raises an error for non-set values' do |example|
|
3
3
|
key = 'mock-redis-test:set-only'
|
4
4
|
|
5
5
|
method = method_from_description(example)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
shared_examples_for
|
2
|
-
it
|
3
|
-
key =
|
1
|
+
shared_examples_for 'a string-only command' do
|
2
|
+
it 'raises an error for non-string values' do |example|
|
3
|
+
key = 'mock-redis-test:string-only-command'
|
4
4
|
|
5
5
|
method = method_from_description(example)
|
6
6
|
args = args_for_method(method).unshift(key)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
shared_examples_for
|
2
|
-
it
|
1
|
+
shared_examples_for 'a zset-only command' do
|
2
|
+
it 'raises an error for non-zset values' do |example|
|
3
3
|
key = 'mock-redis-test:zset-only'
|
4
4
|
|
5
5
|
method = method_from_description(example)
|
@@ -12,17 +12,17 @@ shared_examples_for "a zset-only command" do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
shared_examples_for
|
15
|
+
shared_examples_for 'arg 1 is a score' do
|
16
16
|
before { @_arg_index = 1 }
|
17
|
-
it_should_behave_like
|
17
|
+
it_should_behave_like 'arg N is a score'
|
18
18
|
end
|
19
19
|
|
20
|
-
shared_examples_for
|
20
|
+
shared_examples_for 'arg 2 is a score' do
|
21
21
|
before { @_arg_index = 2 }
|
22
|
-
it_should_behave_like
|
22
|
+
it_should_behave_like 'arg N is a score'
|
23
23
|
end
|
24
24
|
|
25
|
-
shared_examples_for
|
25
|
+
shared_examples_for 'arg N is a score' do
|
26
26
|
before do |example|
|
27
27
|
key = 'mock-redis-test:zset-only'
|
28
28
|
|
@@ -30,27 +30,27 @@ shared_examples_for "arg N is a score" do
|
|
30
30
|
@args = args_for_method(@method).unshift(key)
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'is okay with positive ints' do
|
34
34
|
@args[@_arg_index] = 1
|
35
35
|
lambda { @redises.send(@method, *@args) }.should_not raise_error
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it 'is okay with negative ints' do
|
39
39
|
@args[@_arg_index] = -1
|
40
40
|
lambda { @redises.send(@method, *@args) }.should_not raise_error
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'is okay with positive floats' do
|
44
44
|
@args[@_arg_index] = 1.5
|
45
45
|
lambda { @redises.send(@method, *@args) }.should_not raise_error
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'is okay with negative floats' do
|
49
49
|
@args[@_arg_index] = -1.5
|
50
50
|
lambda { @redises.send(@method, *@args) }.should_not raise_error
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'rejects non-numbers' do
|
54
54
|
@args[@_arg_index] = 'foo'
|
55
55
|
lambda { @redises.send(@method, *@args) }.should raise_error(RuntimeError)
|
56
56
|
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
shared_examples_for
|
1
|
+
shared_examples_for 'a sortable' do
|
2
2
|
it 'returns empty array on nil' do
|
3
3
|
@redises.sort(nil).should == []
|
4
4
|
end
|
5
5
|
|
6
6
|
context 'ordering' do
|
7
7
|
it 'orders ascending by default' do
|
8
|
-
@redises.sort(@key).should == [
|
8
|
+
@redises.sort(@key).should == %w[1 2]
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'orders by descending when specified' do
|
12
|
-
@redises.sort(@key, :order =>
|
12
|
+
@redises.sort(@key, :order => 'DESC').should == %w[2 1]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'projections' do
|
17
17
|
it 'projects element when :get is "#"' do
|
18
|
-
@redises.sort(@key, :get => '#').should == [
|
18
|
+
@redises.sort(@key, :get => '#').should == %w[1 2]
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'projects through a key pattern' do
|
22
|
-
@redises.sort(@key, :get => 'mock-redis-test:values_*').should == [
|
22
|
+
@redises.sort(@key, :get => 'mock-redis-test:values_*').should == %w[a b]
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'projects through a key pattern and reflects element' do
|
26
|
-
@redises.sort(@key, :get => ['#', 'mock-redis-test:values_*']).should == [[
|
26
|
+
@redises.sort(@key, :get => ['#', 'mock-redis-test:values_*']).should == [%w[1 a], %w[2 b]]
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'projects through a hash key pattern' do
|
30
|
-
@redises.sort(@key, :get => 'mock-redis-test:hash_*->key').should == [
|
30
|
+
@redises.sort(@key, :get => 'mock-redis-test:hash_*->key').should == %w[x y]
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'weights' do
|
35
35
|
it 'weights by projecting through a key pattern' do
|
36
|
-
@redises.sort(@key, :by =>
|
36
|
+
@redises.sort(@key, :by => 'mock-redis-test:weight_*').should == %w[2 1]
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'weights by projecting through a key pattern and a specific order' do
|
40
|
-
@redises.sort(@key, :order =>
|
40
|
+
@redises.sort(@key, :order => 'DESC', :by => 'mock-redis-test:weight_*').should == %w[1 2]
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -49,8 +49,8 @@ shared_examples_for "a sortable" do
|
|
49
49
|
|
50
50
|
context 'store' do
|
51
51
|
it 'stores into another key' do
|
52
|
-
@redises.sort(@key, :store =>
|
53
|
-
@redises.lrange(
|
52
|
+
@redises.sort(@key, :store => 'mock-redis-test:some_bucket').should == 2
|
53
|
+
@redises.lrange('mock-redis-test:some_bucket', 0, -1).should == %w[1 2]
|
54
54
|
end
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|
data/spec/transactions_spec.rb
CHANGED
@@ -5,21 +5,21 @@ describe 'transactions (multi/exec/discard)' do
|
|
5
5
|
@redises.discard rescue nil
|
6
6
|
end
|
7
7
|
|
8
|
-
context
|
8
|
+
context '#multi' do
|
9
9
|
it "responds with 'OK'" do
|
10
10
|
@redises.multi.should == 'OK'
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'forbids nesting' do
|
14
14
|
@redises.multi
|
15
15
|
lambda do
|
16
16
|
@redises.multi
|
17
17
|
end.should raise_error(RuntimeError)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'cleans state of tansaction wrapper if exception occurs during transaction' do
|
21
21
|
lambda do
|
22
|
-
@redises.mock.multi do |
|
22
|
+
@redises.mock.multi do |_r|
|
23
23
|
raise "i'm a command that fails"
|
24
24
|
end
|
25
25
|
end.should raise_error(RuntimeError)
|
@@ -34,18 +34,18 @@ describe 'transactions (multi/exec/discard)' do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
38
|
-
it
|
39
|
-
@redises.set(
|
37
|
+
context '#blocks' do
|
38
|
+
it 'implicitly runs exec when finished' do
|
39
|
+
@redises.set('counter', 5)
|
40
40
|
@redises.multi do |r|
|
41
|
-
r.set(
|
42
|
-
r.incr(
|
41
|
+
r.set('test', 1)
|
42
|
+
r.incr('counter')
|
43
43
|
end
|
44
|
-
@redises.get(
|
45
|
-
@redises.get(
|
44
|
+
@redises.get('counter').should == '6'
|
45
|
+
@redises.get('test').should == '1'
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'forbids 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.
|
@@ -57,7 +57,7 @@ describe 'transactions (multi/exec/discard)' do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
context
|
60
|
+
context '#discard' do
|
61
61
|
it "responds with 'OK' after #multi" do
|
62
62
|
@redises.multi
|
63
63
|
@redises.discard.should == 'OK'
|
@@ -70,15 +70,15 @@ describe 'transactions (multi/exec/discard)' do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context
|
74
|
-
it
|
73
|
+
context '#exec' do
|
74
|
+
it 'raises an error outside of #multi' do
|
75
75
|
lambda do
|
76
76
|
@redises.exec.should raise_error
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
context
|
81
|
+
context 'saving up commands for later' do
|
82
82
|
before(:each) do
|
83
83
|
@redises.multi
|
84
84
|
@string = 'mock-redis-test:string'
|
@@ -110,13 +110,13 @@ describe 'transactions (multi/exec/discard)' do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
context
|
113
|
+
context 'saving commands with multi block' do
|
114
114
|
before(:each) do
|
115
115
|
@string = 'mock-redis-test:string'
|
116
116
|
@list = 'mock-redis-test:list'
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
119
|
+
it 'commands return response after exec is called' do
|
120
120
|
set_response = nil
|
121
121
|
lpush_response = nil
|
122
122
|
second_lpush_response = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brigade Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- ".mailmap"
|
80
80
|
- ".overcommit.yml"
|
81
81
|
- ".rspec"
|
82
|
+
- ".rubocop.yml"
|
83
|
+
- ".simplecov"
|
82
84
|
- ".travis.yml"
|
83
85
|
- CHANGELOG.md
|
84
86
|
- Gemfile
|
@@ -263,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
265
|
version: '0'
|
264
266
|
requirements: []
|
265
267
|
rubyforge_project:
|
266
|
-
rubygems_version: 2.4.
|
268
|
+
rubygems_version: 2.4.8
|
267
269
|
signing_key:
|
268
270
|
specification_version: 4
|
269
271
|
summary: Redis mock that just lives in memory; useful for testing.
|