mock_redis 0.14.1 → 0.15.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/.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,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe '#zremrangebyscore(key, min, max)' do
|
5
5
|
before do
|
6
6
|
@key = 'mock-redis-test:zremrangebyscore'
|
7
7
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -10,24 +10,26 @@ describe "#zremrangebyscore(key, min, max)" do
|
|
10
10
|
@redises.zadd(@key, 4, 'Madison')
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'returns the number of elements in range' do
|
14
14
|
@redises.zremrangebyscore(@key, 2, 3).should == 2
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'removes the elements' do
|
18
18
|
@redises.zremrangebyscore(@key, 2, 3)
|
19
19
|
@redises.zrange(@key, 0, -1).should == %w[Washington Madison]
|
20
20
|
end
|
21
21
|
|
22
22
|
# As seen in http://redis.io/commands/zremrangebyscore
|
23
|
-
it
|
23
|
+
it 'removes the elements for complex statements' do
|
24
24
|
@redises.zremrangebyscore(@key, '-inf', '(4')
|
25
25
|
@redises.zrange(@key, 0, -1).should == %w[Madison]
|
26
26
|
end
|
27
27
|
|
28
|
-
it_should_behave_like
|
28
|
+
it_should_behave_like 'a zset-only command'
|
29
29
|
|
30
|
-
it
|
31
|
-
expect
|
30
|
+
it 'throws a command error' do
|
31
|
+
expect do
|
32
|
+
@redises.zrevrangebyscore(@key, DateTime.now, '-inf')
|
33
|
+
end.to raise_error(Redis::CommandError)
|
32
34
|
end
|
33
35
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrevrange(key, start, stop [, :with_scores => true])' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrevrange'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -20,27 +20,27 @@ describe "#zrevrange(key, start, stop [, :with_scores => true])" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
@redises.zrevrange(@key, 0, 1).should == [
|
23
|
+
it 'returns the elements in order by score' do
|
24
|
+
@redises.zrevrange(@key, 0, 1).should == %w[Madison Jefferson]
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
@redises.zrevrange(@key, -2, -1).should == [
|
27
|
+
it 'returns the elements in order by score (negative indices)' do
|
28
|
+
@redises.zrevrange(@key, -2, -1).should == %w[Adams Washington]
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns empty list when start is too large' do
|
32
32
|
@redises.zrevrange(@key, 5, -1).should == []
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'returns the scores when :with_scores is specified' do
|
36
36
|
@redises.zrevrange(@key, 2, 3, :with_scores => true).
|
37
|
-
should == [[
|
37
|
+
should == [['Adams', 2.0], ['Washington', 1.0]]
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'returns the scores when :withscores is specified' do
|
41
41
|
@redises.zrevrange(@key, 2, 3, :withscores => true).
|
42
|
-
should == [[
|
42
|
+
should == [['Adams', 2.0], ['Washington', 1.0]]
|
43
43
|
end
|
44
44
|
|
45
|
-
it_should_behave_like
|
45
|
+
it_should_behave_like 'a zset-only command'
|
46
46
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrevrangebyscore'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -20,28 +20,28 @@ describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
@redises.zrevrangebyscore(@key, 4, 3).should == [
|
23
|
+
it 'returns the elements in order by score' do
|
24
|
+
@redises.zrevrangebyscore(@key, 4, 3).should == %w[Madison Jefferson]
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'returns the scores when :with_scores is specified' do
|
28
28
|
@redises.zrevrangebyscore(@key, 4, 3, :with_scores => true).
|
29
|
-
should == [[
|
29
|
+
should == [['Madison', 4.0], ['Jefferson', 3.0]]
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'returns the scores when :withscores is specified' do
|
33
33
|
@redises.zrevrangebyscore(@key, 4, 3, :withscores => true).
|
34
|
-
should == [[
|
34
|
+
should == [['Madison', 4.0], ['Jefferson', 3.0]]
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
@redises.zrevrangebyscore(@key,
|
37
|
+
it 'treats +inf as positive infinity' do
|
38
|
+
@redises.zrevrangebyscore(@key, '+inf', 3).
|
39
39
|
should == %w[Madison Jefferson]
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it 'honors the :limit => [offset count] argument' do
|
43
43
|
@redises.zrevrangebyscore(@key, 100, -100, :limit => [1, 2]).
|
44
|
-
should == [
|
44
|
+
should == %w[Jefferson Adams]
|
45
45
|
end
|
46
46
|
|
47
47
|
it "raises an error if :limit isn't a 2-tuple" do
|
@@ -50,9 +50,9 @@ describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [
|
|
50
50
|
end.should raise_error(RuntimeError)
|
51
51
|
|
52
52
|
lambda do
|
53
|
-
@redises.zrevrangebyscore(@key, 100, -100, :limit =>
|
54
|
-
end.should raise_error
|
53
|
+
@redises.zrevrangebyscore(@key, 100, -100, :limit => '1, 2')
|
54
|
+
end.should raise_error(RedisMultiplexer::MismatchedResponse)
|
55
55
|
end
|
56
56
|
|
57
|
-
it_should_behave_like
|
57
|
+
it_should_behave_like 'a zset-only command'
|
58
58
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrevrank(key, member)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrevrank'
|
6
6
|
|
@@ -13,17 +13,17 @@ describe "#zrevrank(key, member)" do
|
|
13
13
|
@redises.zrevrank(@key, 'foo').should be_nil
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'returns the index of the member in the set (ordered by -score)' do
|
17
17
|
@redises.zrevrank(@key, 'one').should == 2
|
18
18
|
@redises.zrevrank(@key, 'two').should == 1
|
19
19
|
@redises.zrevrank(@key, 'three').should == 0
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'handles integer members correctly' do
|
23
23
|
member = 11
|
24
24
|
@redises.zadd(@key, 4, member)
|
25
25
|
@redises.zrevrank(@key, member).should == 0
|
26
26
|
end
|
27
27
|
|
28
|
-
it_should_behave_like
|
28
|
+
it_should_behave_like 'a zset-only command'
|
29
29
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zscore(key, member)' do
|
4
4
|
before { @key = 'mock-redis-test:zscore' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the score as a string' do
|
7
7
|
@redises.zadd(@key, 0.25, 'foo').should == true
|
8
8
|
@redises.zscore(@key, 'foo').should == 0.25
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'handles integer members correctly' do
|
12
12
|
member = 11
|
13
13
|
@redises.zadd(@key, 0.25, member).should == true
|
14
14
|
@redises.zscore(@key, member).should == 0.25
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'returns nil if member is not present in the set' do
|
18
18
|
@redises.zscore(@key, 'foo').should be_nil
|
19
19
|
end
|
20
20
|
|
21
|
-
it_should_behave_like
|
21
|
+
it_should_behave_like 'a zset-only command'
|
22
22
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])' do
|
4
4
|
before do
|
5
5
|
@set1 = 'mock-redis-test:zunionstore1'
|
6
6
|
@set2 = 'mock-redis-test:zunionstore2'
|
@@ -17,45 +17,45 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
17
17
|
@redises.zadd(@set3, 3, 'three')
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'returns the number of elements in the new set' do
|
21
21
|
@redises.zunionstore(@dest, [@set1, @set2, @set3]).should == 3
|
22
22
|
end
|
23
23
|
|
24
24
|
it "sums the members' scores by default" do
|
25
25
|
@redises.zunionstore(@dest, [@set1, @set2, @set3])
|
26
26
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
27
|
-
[[
|
27
|
+
[['one', 3.0], ['three', 3.0], ['two', 4.0]]
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'removes existing elements in destination' do
|
31
31
|
@redises.zadd(@dest, 10, 'ten')
|
32
32
|
|
33
33
|
@redises.zunionstore(@dest, [@set1])
|
34
34
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
35
|
-
[[
|
35
|
+
[['one', 1.0]]
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it 'raises an error if keys is empty' do
|
39
39
|
lambda do
|
40
40
|
@redises.zunionstore(@dest, [])
|
41
41
|
end.should raise_error(RuntimeError)
|
42
42
|
end
|
43
43
|
|
44
|
-
context
|
45
|
-
it
|
44
|
+
context 'the :weights argument' do
|
45
|
+
it 'multiplies the scores by the weights while aggregating' do
|
46
46
|
@redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [2, 3, 5])
|
47
47
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
48
|
-
[[
|
48
|
+
[['one', 10.0], ['three', 15.0], ['two', 16.0]]
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'raises an error if the number of weights != the number of keys' do
|
52
52
|
lambda do
|
53
|
-
@redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [1,2])
|
53
|
+
@redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [1, 2])
|
54
54
|
end.should raise_error(RuntimeError)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
context
|
58
|
+
context 'the :aggregate argument' do
|
59
59
|
before do
|
60
60
|
@smalls = 'mock-redis-test:zunionstore:smalls'
|
61
61
|
@bigs = 'mock-redis-test:zunionstore:bigs'
|
@@ -66,19 +66,19 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
66
66
|
@redises.zadd(@bigs, 200, 'ernie')
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
69
|
+
it 'aggregates scores with min when :aggregate => :min is specified' do
|
70
70
|
@redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :min)
|
71
71
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
72
|
-
[[
|
72
|
+
[['bert', 1.0], ['ernie', 2.0]]
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
75
|
+
it 'aggregates scores with max when :aggregate => :max is specified' do
|
76
76
|
@redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :max)
|
77
77
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
78
|
-
[[
|
78
|
+
[['bert', 100.0], ['ernie', 200.0]]
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it 'ignores scores for missing members' do
|
82
82
|
@redises.zadd(@smalls, 3, 'grover')
|
83
83
|
@redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :min)
|
84
84
|
@redises.zscore(@dest, 'grover').should == 3.0
|
@@ -95,7 +95,7 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
95
95
|
@redises.zscore(@dest, 'bert').should == 1.0
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
98
|
+
it 'raises an error for unknown aggregation function' do
|
99
99
|
lambda do
|
100
100
|
@redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :mix)
|
101
101
|
end.should raise_error(RuntimeError)
|
data/spec/mock_redis_spec.rb
CHANGED
@@ -58,11 +58,21 @@ describe MockRedis do
|
|
58
58
|
its(:now) { should == now }
|
59
59
|
end
|
60
60
|
|
61
|
+
describe '.time' do
|
62
|
+
let(:now) { 'Now' }
|
63
|
+
let(:time_stub) { double 'Time', :now => now }
|
64
|
+
let(:options) { { :time_class => time_stub } }
|
65
|
+
|
66
|
+
subject { MockRedis.new(options) }
|
67
|
+
|
68
|
+
its(:time) { should == now }
|
69
|
+
end
|
70
|
+
|
61
71
|
describe '.expireat' do
|
62
72
|
let(:time_at) { 'expireat' }
|
63
73
|
let(:time_stub) { double 'Time' }
|
64
74
|
let(:options) { { :time_class => time_stub } }
|
65
|
-
let(:timestamp) {
|
75
|
+
let(:timestamp) { 123_456 }
|
66
76
|
|
67
77
|
subject { MockRedis.new(options) }
|
68
78
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
|
-
|
1
|
+
if ENV['TRAVIS']
|
2
|
+
# When running in Travis, report coverage stats to Coveralls.
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
else
|
6
|
+
# Otherwise render coverage information in coverage/index.html and display
|
7
|
+
# coverage percentage in the console.
|
8
|
+
require 'simplecov'
|
9
|
+
end
|
10
|
+
|
2
11
|
require 'rspec/its'
|
3
12
|
require 'redis'
|
4
|
-
$LOAD_PATH.unshift(File.expand_path(File.join(__FILE__,
|
13
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, '..', '..', 'lib')))
|
5
14
|
require 'mock_redis'
|
6
15
|
|
7
16
|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
8
|
-
Dir[
|
17
|
+
Dir['spec/support/**/*.rb'].each { |x| require x }
|
9
18
|
|
10
19
|
module TypeCheckingHelper
|
11
20
|
def method_from_description(example)
|
@@ -45,7 +54,7 @@ RSpec.configure do |config|
|
|
45
54
|
# databases mentioned in our tests
|
46
55
|
[1, 0].each do |db|
|
47
56
|
@redises.send_without_checking(:select, db)
|
48
|
-
@redises.send_without_checking(:keys,
|
57
|
+
@redises.send_without_checking(:keys, 'mock-redis-test:*').each do |key|
|
49
58
|
@redises.send_without_checking(:del, key)
|
50
59
|
end
|
51
60
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
class BlankSlate
|
2
|
-
instance_methods.each
|
2
|
+
instance_methods.each do |m|
|
3
|
+
undef_method(m) unless m =~ /^__/ || %w[inspect object_id].include?(m.to_s)
|
4
|
+
end
|
3
5
|
end
|
4
6
|
|
5
7
|
class RedisMultiplexer < BlankSlate
|
@@ -11,50 +13,54 @@ class RedisMultiplexer < BlankSlate
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def method_missing(method, *args, &blk)
|
14
|
-
#
|
15
|
-
# on the Redis implementation that the
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# If we're in a Redis command that accepts a block, and we execute more
|
17
|
+
# redis commands, ONLY execute them on the Redis implementation that the
|
18
|
+
# block came from.
|
19
|
+
# e.g. if a pipelined command is started on a MockRedis object, DON'T send
|
20
|
+
# commands inside the pipelined block to the real Redis object, as that one
|
21
|
+
# WON'T be inside a pipelined command, and we'll see weird behaviour
|
18
22
|
if blk
|
19
23
|
@in_mock_block = false
|
20
24
|
@in_redis_block = true
|
21
25
|
end
|
22
|
-
real_retval, real_error =
|
26
|
+
real_retval, real_error =
|
27
|
+
catch_errors { @in_mock_block ? :no_op : @real_redis.send(method, *args, &blk) }
|
23
28
|
|
24
29
|
if blk
|
25
30
|
@in_mock_block = true
|
26
31
|
@in_redis_block = false
|
27
32
|
end
|
28
|
-
mock_retval, mock_error =
|
33
|
+
mock_retval, mock_error =
|
34
|
+
catch_errors { @in_redis_block ? :no_op : @mock_redis.send(method, *args, &blk) }
|
29
35
|
|
30
36
|
if blk
|
31
37
|
@in_mock_block = false
|
32
38
|
@in_redis_block = false
|
33
39
|
end
|
34
40
|
|
35
|
-
if
|
36
|
-
|
37
|
-
elsif
|
41
|
+
if mock_retval == :no_op || real_retval == :no_op
|
42
|
+
# ignore, we were inside a block (like pipelined)
|
43
|
+
elsif !equalish?(mock_retval, real_retval) && !mock_error && !real_error
|
38
44
|
# no exceptions, just different behavior
|
39
45
|
raise MismatchedResponse,
|
40
|
-
"Mock failure: responses not equal.\n"
|
41
|
-
"Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n"
|
46
|
+
"Mock failure: responses not equal.\n" \
|
47
|
+
"Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" \
|
42
48
|
"MockRedis.#{method}(#{args.inspect}) returned #{mock_retval.inspect}\n"
|
43
|
-
elsif
|
49
|
+
elsif !mock_error && real_error
|
44
50
|
raise MismatchedResponse,
|
45
|
-
"Mock failure: didn't raise an error when it should have.\n"
|
46
|
-
"Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n"
|
47
|
-
"MockRedis.#{method}(#{args.inspect}) raised nothing "
|
51
|
+
"Mock failure: didn't raise an error when it should have.\n" \
|
52
|
+
"Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" \
|
53
|
+
"MockRedis.#{method}(#{args.inspect}) raised nothing " \
|
48
54
|
"and returned #{mock_retval.inspect}"
|
49
|
-
elsif
|
55
|
+
elsif !real_error && mock_error
|
50
56
|
raise MismatchedResponse,
|
51
|
-
"Mock failure: raised an error when it shouldn't have.\n"
|
52
|
-
"Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n"
|
57
|
+
"Mock failure: raised an error when it shouldn't have.\n" \
|
58
|
+
"Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" \
|
53
59
|
"MockRedis.#{method}(#{args.inspect}) raised #{mock_error.inspect}"
|
54
|
-
elsif
|
60
|
+
elsif mock_error && real_error && !equalish?(mock_error, real_error)
|
55
61
|
raise MismatchedResponse,
|
56
|
-
"Mock failure: raised the wrong error.\n"
|
57
|
-
"Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n"
|
62
|
+
"Mock failure: raised the wrong error.\n" \
|
63
|
+
"Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" \
|
58
64
|
"MockRedis.#{method}(#{args.inspect}) raised #{mock_error.inspect}"
|
59
65
|
end
|
60
66
|
|
@@ -77,8 +83,13 @@ class RedisMultiplexer < BlankSlate
|
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
def mock
|
81
|
-
|
86
|
+
def mock
|
87
|
+
@mock_redis
|
88
|
+
end
|
89
|
+
|
90
|
+
def real
|
91
|
+
@real_redis
|
92
|
+
end
|
82
93
|
|
83
94
|
# Used in cleanup before() blocks.
|
84
95
|
def send_without_checking(method, *args)
|
@@ -87,12 +98,9 @@ class RedisMultiplexer < BlankSlate
|
|
87
98
|
end
|
88
99
|
|
89
100
|
def catch_errors
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
[nil, e]
|
95
|
-
end
|
101
|
+
retval = yield
|
102
|
+
[retval, nil]
|
103
|
+
rescue StandardError => e
|
104
|
+
[nil, e]
|
96
105
|
end
|
97
106
|
end
|
98
|
-
|