mock_redis 0.36.0 → 0.37.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.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +1 -1
  4. data/lib/mock_redis/database.rb +1 -1
  5. data/lib/mock_redis/hash_methods.rb +1 -1
  6. data/lib/mock_redis/list_methods.rb +7 -2
  7. data/lib/mock_redis/multi_db_wrapper.rb +1 -1
  8. data/lib/mock_redis/pipelined_wrapper.rb +12 -14
  9. data/lib/mock_redis/set_methods.rb +6 -1
  10. data/lib/mock_redis/stream.rb +3 -3
  11. data/lib/mock_redis/string_methods.rb +3 -3
  12. data/lib/mock_redis/transaction_wrapper.rb +5 -7
  13. data/lib/mock_redis/utility_methods.rb +4 -2
  14. data/lib/mock_redis/version.rb +1 -1
  15. data/lib/mock_redis/zset.rb +4 -2
  16. data/lib/mock_redis/zset_methods.rb +3 -3
  17. data/lib/mock_redis.rb +1 -2
  18. metadata +19 -360
  19. data/.github/workflows/lint.yml +0 -31
  20. data/.github/workflows/tests.yml +0 -63
  21. data/.gitignore +0 -5
  22. data/.mailmap +0 -2
  23. data/.overcommit.yml +0 -21
  24. data/.rspec +0 -1
  25. data/.rubocop.yml +0 -148
  26. data/.rubocop_todo.yml +0 -35
  27. data/.simplecov +0 -4
  28. data/Gemfile +0 -13
  29. data/Rakefile +0 -2
  30. data/mock_redis.gemspec +0 -32
  31. data/spec/client_spec.rb +0 -36
  32. data/spec/cloning_spec.rb +0 -95
  33. data/spec/commands/append_spec.rb +0 -24
  34. data/spec/commands/auth_spec.rb +0 -7
  35. data/spec/commands/bgrewriteaof_spec.rb +0 -7
  36. data/spec/commands/bgsave_spec.rb +0 -7
  37. data/spec/commands/bitcount_spec.rb +0 -25
  38. data/spec/commands/bitfield_spec.rb +0 -169
  39. data/spec/commands/blmove_spec.rb +0 -52
  40. data/spec/commands/blpop_spec.rb +0 -53
  41. data/spec/commands/brpop_spec.rb +0 -59
  42. data/spec/commands/brpoplpush_spec.rb +0 -52
  43. data/spec/commands/connected_spec.rb +0 -7
  44. data/spec/commands/connection_spec.rb +0 -15
  45. data/spec/commands/dbsize_spec.rb +0 -18
  46. data/spec/commands/decr_spec.rb +0 -34
  47. data/spec/commands/decrby_spec.rb +0 -34
  48. data/spec/commands/del_spec.rb +0 -52
  49. data/spec/commands/disconnect_spec.rb +0 -7
  50. data/spec/commands/dump_spec.rb +0 -19
  51. data/spec/commands/echo_spec.rb +0 -11
  52. data/spec/commands/eval_spec.rb +0 -7
  53. data/spec/commands/evalsha_spec.rb +0 -10
  54. data/spec/commands/exists_spec.rb +0 -43
  55. data/spec/commands/expire_spec.rb +0 -111
  56. data/spec/commands/expireat_spec.rb +0 -47
  57. data/spec/commands/flushall_spec.rb +0 -38
  58. data/spec/commands/flushdb_spec.rb +0 -38
  59. data/spec/commands/future_spec.rb +0 -30
  60. data/spec/commands/geoadd_spec.rb +0 -58
  61. data/spec/commands/geodist_spec.rb +0 -118
  62. data/spec/commands/geohash_spec.rb +0 -52
  63. data/spec/commands/geopos_spec.rb +0 -55
  64. data/spec/commands/get_spec.rb +0 -31
  65. data/spec/commands/getbit_spec.rb +0 -34
  66. data/spec/commands/getdel.rb +0 -24
  67. data/spec/commands/getrange_spec.rb +0 -22
  68. data/spec/commands/getset_spec.rb +0 -23
  69. data/spec/commands/hdel_spec.rb +0 -77
  70. data/spec/commands/hexists_spec.rb +0 -27
  71. data/spec/commands/hget_spec.rb +0 -28
  72. data/spec/commands/hgetall_spec.rb +0 -32
  73. data/spec/commands/hincrby_spec.rb +0 -58
  74. data/spec/commands/hincrbyfloat_spec.rb +0 -58
  75. data/spec/commands/hkeys_spec.rb +0 -19
  76. data/spec/commands/hlen_spec.rb +0 -19
  77. data/spec/commands/hmget_spec.rb +0 -46
  78. data/spec/commands/hmset_spec.rb +0 -69
  79. data/spec/commands/hscan_each_spec.rb +0 -48
  80. data/spec/commands/hscan_spec.rb +0 -27
  81. data/spec/commands/hset_spec.rb +0 -42
  82. data/spec/commands/hsetnx_spec.rb +0 -44
  83. data/spec/commands/hvals_spec.rb +0 -19
  84. data/spec/commands/incr_spec.rb +0 -34
  85. data/spec/commands/incrby_spec.rb +0 -44
  86. data/spec/commands/incrbyfloat_spec.rb +0 -44
  87. data/spec/commands/info_spec.rb +0 -62
  88. data/spec/commands/keys_spec.rb +0 -139
  89. data/spec/commands/lastsave_spec.rb +0 -8
  90. data/spec/commands/lindex_spec.rb +0 -49
  91. data/spec/commands/linsert_spec.rb +0 -68
  92. data/spec/commands/llen_spec.rb +0 -16
  93. data/spec/commands/lmove_spec.rb +0 -72
  94. data/spec/commands/lpop_spec.rb +0 -35
  95. data/spec/commands/lpush_spec.rb +0 -43
  96. data/spec/commands/lpushx_spec.rb +0 -46
  97. data/spec/commands/lrange_spec.rb +0 -51
  98. data/spec/commands/lrem_spec.rb +0 -80
  99. data/spec/commands/lset_spec.rb +0 -43
  100. data/spec/commands/ltrim_spec.rb +0 -45
  101. data/spec/commands/mapped_hmget_spec.rb +0 -29
  102. data/spec/commands/mapped_hmset_spec.rb +0 -47
  103. data/spec/commands/mapped_mget_spec.rb +0 -22
  104. data/spec/commands/mapped_mset_spec.rb +0 -19
  105. data/spec/commands/mapped_msetnx_spec.rb +0 -26
  106. data/spec/commands/mget_spec.rb +0 -65
  107. data/spec/commands/move_spec.rb +0 -147
  108. data/spec/commands/mset_spec.rb +0 -43
  109. data/spec/commands/msetnx_spec.rb +0 -40
  110. data/spec/commands/persist_spec.rb +0 -48
  111. data/spec/commands/pexpire_spec.rb +0 -86
  112. data/spec/commands/pexpireat_spec.rb +0 -48
  113. data/spec/commands/ping_spec.rb +0 -11
  114. data/spec/commands/pipelined_spec.rb +0 -114
  115. data/spec/commands/psetex_spec.rb +0 -44
  116. data/spec/commands/pttl_spec.rb +0 -41
  117. data/spec/commands/quit_spec.rb +0 -7
  118. data/spec/commands/randomkey_spec.rb +0 -20
  119. data/spec/commands/rename_spec.rb +0 -42
  120. data/spec/commands/renamenx_spec.rb +0 -41
  121. data/spec/commands/restore_spec.rb +0 -47
  122. data/spec/commands/rpop_spec.rb +0 -35
  123. data/spec/commands/rpoplpush_spec.rb +0 -50
  124. data/spec/commands/rpush_spec.rb +0 -43
  125. data/spec/commands/rpushx_spec.rb +0 -46
  126. data/spec/commands/sadd_spec.rb +0 -45
  127. data/spec/commands/save_spec.rb +0 -7
  128. data/spec/commands/scan_each_spec.rb +0 -39
  129. data/spec/commands/scan_spec.rb +0 -64
  130. data/spec/commands/scard_spec.rb +0 -18
  131. data/spec/commands/script_spec.rb +0 -9
  132. data/spec/commands/sdiff_spec.rb +0 -47
  133. data/spec/commands/sdiffstore_spec.rb +0 -58
  134. data/spec/commands/select_spec.rb +0 -61
  135. data/spec/commands/set_spec.rb +0 -134
  136. data/spec/commands/setbit_spec.rb +0 -55
  137. data/spec/commands/setex_spec.rb +0 -38
  138. data/spec/commands/setnx_spec.rb +0 -25
  139. data/spec/commands/setrange_spec.rb +0 -30
  140. data/spec/commands/sinter_spec.rb +0 -39
  141. data/spec/commands/sinterstore_spec.rb +0 -53
  142. data/spec/commands/sismember_spec.rb +0 -29
  143. data/spec/commands/smembers_spec.rb +0 -28
  144. data/spec/commands/smismember_spec.rb +0 -34
  145. data/spec/commands/smove_spec.rb +0 -41
  146. data/spec/commands/sort_list_spec.rb +0 -21
  147. data/spec/commands/sort_set_spec.rb +0 -21
  148. data/spec/commands/sort_zset_spec.rb +0 -21
  149. data/spec/commands/spop_spec.rb +0 -40
  150. data/spec/commands/srandmember_spec.rb +0 -49
  151. data/spec/commands/srem_spec.rb +0 -45
  152. data/spec/commands/sscan_each_spec.rb +0 -48
  153. data/spec/commands/sscan_spec.rb +0 -39
  154. data/spec/commands/strlen_spec.rb +0 -18
  155. data/spec/commands/sunion_spec.rb +0 -42
  156. data/spec/commands/sunionstore_spec.rb +0 -59
  157. data/spec/commands/ttl_spec.rb +0 -40
  158. data/spec/commands/type_spec.rb +0 -36
  159. data/spec/commands/unwatch_spec.rb +0 -7
  160. data/spec/commands/watch_spec.rb +0 -21
  161. data/spec/commands/xadd_spec.rb +0 -122
  162. data/spec/commands/xlen_spec.rb +0 -22
  163. data/spec/commands/xrange_spec.rb +0 -164
  164. data/spec/commands/xread_spec.rb +0 -66
  165. data/spec/commands/xrevrange_spec.rb +0 -130
  166. data/spec/commands/xtrim_spec.rb +0 -36
  167. data/spec/commands/zadd_spec.rb +0 -129
  168. data/spec/commands/zcard_spec.rb +0 -19
  169. data/spec/commands/zcount_spec.rb +0 -39
  170. data/spec/commands/zincrby_spec.rb +0 -31
  171. data/spec/commands/zinterstore_spec.rb +0 -130
  172. data/spec/commands/zpopmax_spec.rb +0 -60
  173. data/spec/commands/zpopmin_spec.rb +0 -60
  174. data/spec/commands/zrange_spec.rb +0 -80
  175. data/spec/commands/zrangebyscore_spec.rb +0 -83
  176. data/spec/commands/zrank_spec.rb +0 -29
  177. data/spec/commands/zrem_spec.rb +0 -50
  178. data/spec/commands/zremrangebyrank_spec.rb +0 -27
  179. data/spec/commands/zremrangebyscore_spec.rb +0 -35
  180. data/spec/commands/zrevrange_spec.rb +0 -56
  181. data/spec/commands/zrevrangebyscore_spec.rb +0 -58
  182. data/spec/commands/zrevrank_spec.rb +0 -29
  183. data/spec/commands/zscan_each_spec.rb +0 -48
  184. data/spec/commands/zscan_spec.rb +0 -26
  185. data/spec/commands/zscore_spec.rb +0 -22
  186. data/spec/commands/zunionstore_spec.rb +0 -137
  187. data/spec/mock_redis_spec.rb +0 -93
  188. data/spec/spec_helper.rb +0 -74
  189. data/spec/support/redis_multiplexer.rb +0 -123
  190. data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +0 -14
  191. data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -15
  192. data/spec/support/shared_examples/only_operates_on_lists.rb +0 -15
  193. data/spec/support/shared_examples/only_operates_on_sets.rb +0 -15
  194. data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
  195. data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -59
  196. data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
  197. data/spec/transactions_spec.rb +0 -163
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zrevrange(key, start, stop [, :with_scores => true])' do
4
- before do
5
- @key = 'mock-redis-test:zrevrange'
6
- @redises.zadd(@key, 1, 'Washington')
7
- @redises.zadd(@key, 2, 'Adams')
8
- @redises.zadd(@key, 3, 'Jefferson')
9
- @redises.zadd(@key, 4, 'Madison')
10
- end
11
-
12
- context 'when the zset is empty' do
13
- before do
14
- @redises.del(@key)
15
- end
16
-
17
- it 'should return an empty array' do
18
- @redises.exists?(@key).should == false
19
- @redises.zrevrange(@key, 0, 4).should == []
20
- end
21
- end
22
-
23
- it 'returns the elements in order by score' do
24
- @redises.zrevrange(@key, 0, 1).should == %w[Madison Jefferson]
25
- end
26
-
27
- context 'when a subset of elements have the same score' do
28
- before do
29
- @redises.zadd(@key, 1, 'Martha')
30
- end
31
-
32
- it 'returns the elements in descending lexicographical order' do
33
- @redises.zrevrange(@key, 3, 4).should == %w[Washington Martha]
34
- end
35
- end
36
-
37
- it 'returns the elements in order by score (negative indices)' do
38
- @redises.zrevrange(@key, -2, -1).should == %w[Adams Washington]
39
- end
40
-
41
- it 'returns empty list when start is too large' do
42
- @redises.zrevrange(@key, 5, -1).should == []
43
- end
44
-
45
- it 'returns the scores when :with_scores is specified' do
46
- @redises.zrevrange(@key, 2, 3, :with_scores => true).
47
- should == [['Adams', 2.0], ['Washington', 1.0]]
48
- end
49
-
50
- it 'returns the scores when :withscores is specified' do
51
- @redises.zrevrange(@key, 2, 3, :withscores => true).
52
- should == [['Adams', 2.0], ['Washington', 1.0]]
53
- end
54
-
55
- it_should_behave_like 'a zset-only command'
56
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])' do
4
- before do
5
- @key = 'mock-redis-test:zrevrangebyscore'
6
- @redises.zadd(@key, 1, 'Washington')
7
- @redises.zadd(@key, 2, 'Adams')
8
- @redises.zadd(@key, 3, 'Jefferson')
9
- @redises.zadd(@key, 4, 'Madison')
10
- end
11
-
12
- context 'when the zset is empty' do
13
- before do
14
- @redises.del(@key)
15
- end
16
-
17
- it 'should return an empty array' do
18
- @redises.exists?(@key).should == false
19
- @redises.zrevrangebyscore(@key, 0, 4).should == []
20
- end
21
- end
22
-
23
- it 'returns the elements in order by score' do
24
- @redises.zrevrangebyscore(@key, 4, 3).should == %w[Madison Jefferson]
25
- end
26
-
27
- it 'returns the scores when :with_scores is specified' do
28
- @redises.zrevrangebyscore(@key, 4, 3, :with_scores => true).
29
- should == [['Madison', 4.0], ['Jefferson', 3.0]]
30
- end
31
-
32
- it 'returns the scores when :withscores is specified' do
33
- @redises.zrevrangebyscore(@key, 4, 3, :withscores => true).
34
- should == [['Madison', 4.0], ['Jefferson', 3.0]]
35
- end
36
-
37
- it 'treats +inf as positive infinity' do
38
- @redises.zrevrangebyscore(@key, '+inf', 3).
39
- should == %w[Madison Jefferson]
40
- end
41
-
42
- it 'honors the :limit => [offset count] argument' do
43
- @redises.zrevrangebyscore(@key, 100, -100, :limit => [1, 2]).
44
- should == %w[Jefferson Adams]
45
- end
46
-
47
- it "raises an error if :limit isn't a 2-tuple" do
48
- lambda do
49
- @redises.zrevrangebyscore(@key, 100, -100, :limit => [1, 2, 3])
50
- end.should raise_error(Redis::CommandError)
51
-
52
- lambda do
53
- @redises.zrevrangebyscore(@key, 100, -100, :limit => '1, 2')
54
- end.should raise_error(RedisMultiplexer::MismatchedResponse)
55
- end
56
-
57
- it_should_behave_like 'a zset-only command'
58
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zrevrank(key, member)' do
4
- before do
5
- @key = 'mock-redis-test:zrevrank'
6
-
7
- @redises.zadd(@key, 1, 'one')
8
- @redises.zadd(@key, 2, 'two')
9
- @redises.zadd(@key, 3, 'three')
10
- end
11
-
12
- it "returns nil if member wasn't present in the set" do
13
- @redises.zrevrank(@key, 'foo').should be_nil
14
- end
15
-
16
- it 'returns the index of the member in the set (ordered by -score)' do
17
- @redises.zrevrank(@key, 'one').should == 2
18
- @redises.zrevrank(@key, 'two').should == 1
19
- @redises.zrevrank(@key, 'three').should == 0
20
- end
21
-
22
- it 'handles integer members correctly' do
23
- member = 11
24
- @redises.zadd(@key, 4, member)
25
- @redises.zrevrank(@key, member).should == 0
26
- end
27
-
28
- it_should_behave_like 'a zset-only command'
29
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zscan_each' do
4
- subject { MockRedis::Database.new(self) }
5
-
6
- let(:key) { 'mock-redis-test:zscan_each' }
7
-
8
- before do
9
- allow(subject).to receive(:zrange).and_return(collection)
10
- end
11
-
12
- context 'when no keys are found' do
13
- let(:collection) { [] }
14
-
15
- it 'does not iterate over any elements' do
16
- results = subject.zscan_each(key).map do |m, s|
17
- [m, s]
18
- end
19
- expect(results).to match_array(collection)
20
- end
21
- end
22
-
23
- context 'when keys are found' do
24
- context 'when no match filter is supplied' do
25
- let(:collection) { Array.new(20) { |i| ["m#{i}", i] } }
26
-
27
- it 'iterates over each item in the collection' do
28
- results = subject.zscan_each(key).map do |m, s|
29
- [m, s]
30
- end
31
- expect(results).to match_array(collection)
32
- end
33
- end
34
-
35
- context 'when giving a custom match filter' do
36
- let(:match) { 'm1*' }
37
- let(:collection) { Array.new(12) { |i| ["m#{i}", i] } }
38
- let(:expected) { [['m1', 1], ['m10', 10], ['m11', 11]] }
39
-
40
- it 'iterates over each item in the filtered collection' do
41
- results = subject.zscan_each(key, match: match).map do |m, s|
42
- [m, s]
43
- end
44
- expect(results).to match_array(expected)
45
- end
46
- end
47
- end
48
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zscan' do
4
- let(:count) { 10 }
5
- let(:match) { '*' }
6
- let(:key) { 'mock-redis-test:zscan' }
7
-
8
- context 'when the zset does not exist' do
9
- it 'returns a 0 cursor and an empty collection' do
10
- expect(@redises.zscan(key, 0, count: count, match: match)).to eq(['0', []])
11
- end
12
- end
13
-
14
- context 'when the zset exists' do
15
- before do
16
- @redises.zadd(key, 1.0, 'member1')
17
- @redises.zadd(key, 2.0, 'member2')
18
- end
19
-
20
- it 'returns a 0 cursor and the collection' do
21
- result = @redises.zscan(key, 0)
22
- expect(result[0]).to eq('0')
23
- expect(result[1]).to match_array([['member1', 1.0], ['member2', 2.0]])
24
- end
25
- end
26
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zscore(key, member)' do
4
- before { @key = 'mock-redis-test:zscore' }
5
-
6
- it 'returns the score as a string' do
7
- @redises.zadd(@key, 0.25, 'foo').should == true
8
- @redises.zscore(@key, 'foo').should == 0.25
9
- end
10
-
11
- it 'handles integer members correctly' do
12
- member = 11
13
- @redises.zadd(@key, 0.25, member).should == true
14
- @redises.zscore(@key, member).should == 0.25
15
- end
16
-
17
- it 'returns nil if member is not present in the set' do
18
- @redises.zscore(@key, 'foo').should be_nil
19
- end
20
-
21
- it_should_behave_like 'a zset-only command'
22
- end
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])' do
4
- before do
5
- @set1 = 'mock-redis-test:zunionstore1'
6
- @set2 = 'mock-redis-test:zunionstore2'
7
- @set3 = 'mock-redis-test:zunionstore3'
8
- @dest = 'mock-redis-test:zunionstoredest'
9
-
10
- @redises.zadd(@set1, 1, 'one')
11
-
12
- @redises.zadd(@set2, 1, 'one')
13
- @redises.zadd(@set2, 2, 'two')
14
-
15
- @redises.zadd(@set3, 1, 'one')
16
- @redises.zadd(@set3, 2, 'two')
17
- @redises.zadd(@set3, 3, 'three')
18
- end
19
-
20
- it 'returns the number of elements in the new set' do
21
- @redises.zunionstore(@dest, [@set1, @set2, @set3]).should == 3
22
- end
23
-
24
- it "sums the members' scores by default" do
25
- @redises.zunionstore(@dest, [@set1, @set2, @set3])
26
- @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
27
- [['one', 3.0], ['three', 3.0], ['two', 4.0]]
28
- end
29
-
30
- it 'removes existing elements in destination' do
31
- @redises.zadd(@dest, 10, 'ten')
32
-
33
- @redises.zunionstore(@dest, [@set1])
34
- @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
35
- [['one', 1.0]]
36
- end
37
-
38
- it 'raises an error if keys is empty' do
39
- lambda do
40
- @redises.zunionstore(@dest, [])
41
- end.should raise_error(Redis::CommandError)
42
- end
43
-
44
- context 'when used with a set' do
45
- before do
46
- @set4 = 'mock-redis-test:zunionstore4'
47
-
48
- @redises.sadd(@set4, 'two')
49
- @redises.sadd(@set4, 'three')
50
- @redises.sadd(@set4, 'four')
51
- end
52
-
53
- it 'returns the number of elements in the new set' do
54
- @redises.zunionstore(@dest, [@set3, @set4]).should == 4
55
- end
56
-
57
- it 'sums the scores, substituting 1.0 for set values' do
58
- @redises.zunionstore(@dest, [@set3, @set4])
59
- @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
60
- [['four', 1.0], ['one', 1.0], ['two', 3.0], ['three', 4.0]]
61
- end
62
- end
63
-
64
- context 'when used with a non-coercible structure' do
65
- before do
66
- @non_set = 'mock-redis-test:zunionstore4'
67
-
68
- @redises.set(@non_set, 'one')
69
- end
70
- it 'raises an error for wrong value type' do
71
- lambda do
72
- @redises.zunionstore(@dest, [@set1, @non_set])
73
- end.should raise_error(Redis::CommandError)
74
- end
75
- end
76
-
77
- context 'the :weights argument' do
78
- it 'multiplies the scores by the weights while aggregating' do
79
- @redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [2, 3, 5])
80
- @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
81
- [['one', 10.0], ['three', 15.0], ['two', 16.0]]
82
- end
83
-
84
- it 'raises an error if the number of weights != the number of keys' do
85
- lambda do
86
- @redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [1, 2])
87
- end.should raise_error(Redis::CommandError)
88
- end
89
- end
90
-
91
- context 'the :aggregate argument' do
92
- before do
93
- @smalls = 'mock-redis-test:zunionstore:smalls'
94
- @bigs = 'mock-redis-test:zunionstore:bigs'
95
-
96
- @redises.zadd(@smalls, 1, 'bert')
97
- @redises.zadd(@smalls, 2, 'ernie')
98
- @redises.zadd(@bigs, 100, 'bert')
99
- @redises.zadd(@bigs, 200, 'ernie')
100
- end
101
-
102
- it 'aggregates scores with min when :aggregate => :min is specified' do
103
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :min)
104
- @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
105
- [['bert', 1.0], ['ernie', 2.0]]
106
- end
107
-
108
- it 'aggregates scores with max when :aggregate => :max is specified' do
109
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :max)
110
- @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
111
- [['bert', 100.0], ['ernie', 200.0]]
112
- end
113
-
114
- it 'ignores scores for missing members' do
115
- @redises.zadd(@smalls, 3, 'grover')
116
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :min)
117
- @redises.zscore(@dest, 'grover').should == 3.0
118
-
119
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :max)
120
- @redises.zscore(@dest, 'grover').should == 3.0
121
- end
122
-
123
- it "allows 'min', 'MIN', etc. as aliases for :min" do
124
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => 'min')
125
- @redises.zscore(@dest, 'bert').should == 1.0
126
-
127
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => 'MIN')
128
- @redises.zscore(@dest, 'bert').should == 1.0
129
- end
130
-
131
- it 'raises an error for unknown aggregation function' do
132
- lambda do
133
- @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :mix)
134
- end.should raise_error(Redis::CommandError)
135
- end
136
- end
137
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe MockRedis do
4
- let(:url) { 'redis://127.0.0.1:6379/1' }
5
-
6
- describe '.new' do
7
- subject { MockRedis.new(:url => url) }
8
-
9
- it 'correctly parses options' do
10
- subject.host.should == '127.0.0.1'
11
- subject.port.should == 6379
12
- subject.db.should == 1
13
- end
14
-
15
- its(:id) { should == url }
16
-
17
- its(:location) { should == url }
18
- end
19
-
20
- describe '.connect' do
21
- let(:url) { 'redis://127.0.0.1:6379/0' }
22
- subject { MockRedis.connect(:url => url) }
23
-
24
- it 'correctly parses options' do
25
- subject.host.should == '127.0.0.1'
26
- subject.port.should == 6379
27
- subject.db.should == 0
28
- end
29
-
30
- its(:id) { should == url }
31
- end
32
-
33
- describe 'Injecting a time class' do
34
- describe '.options' do
35
- let(:time_stub) { double 'Time' }
36
- let(:options) { { :time_class => time_stub } }
37
-
38
- it 'defaults to Time' do
39
- mock_redis = MockRedis.new
40
-
41
- mock_redis.options[:time_class].should == Time
42
- end
43
-
44
- it 'has a configurable Time class' do
45
- mock_redis = MockRedis.new(options)
46
-
47
- mock_redis.options[:time_class].should == time_stub
48
- end
49
- end
50
-
51
- describe '.now' do
52
- let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') }
53
- let(:options) { { :time_class => time_stub } }
54
-
55
- subject { MockRedis.new(options) }
56
-
57
- its(:now) { should == [1_546_398_246, 0] }
58
- end
59
-
60
- describe '.time' do
61
- let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') }
62
- let(:options) { { :time_class => time_stub } }
63
-
64
- subject { MockRedis.new(options) }
65
-
66
- its(:time) { should == [1_546_398_246, 0] }
67
- end
68
-
69
- describe '.expireat' do
70
- let(:time_at) { 'expireat' }
71
- let(:time_stub) { double 'Time' }
72
- let(:options) { { :time_class => time_stub } }
73
- let(:timestamp) { 123_456 }
74
-
75
- subject { MockRedis.new(options) }
76
-
77
- it 'Forwards time_at to the time_class' do
78
- time_stub.should_receive(:at).with(timestamp).and_return(time_at)
79
-
80
- subject.time_at(timestamp).should == time_at
81
- end
82
- end
83
- end
84
-
85
- describe 'supplying a logger' do
86
- it 'logs redis commands' do
87
- logger = double('Logger', debug?: true, debug: nil)
88
- mock_redis = MockRedis.new(logger: logger)
89
- expect(logger).to receive(:debug).with(/command=HMGET args="hash" "key1" "key2"/)
90
- mock_redis.hmget('hash', 'key1', 'key2')
91
- end
92
- end
93
- end
data/spec/spec_helper.rb DELETED
@@ -1,74 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter 'spec/'
4
-
5
- if ENV['CI']
6
- require 'simplecov-lcov'
7
-
8
- SimpleCov::Formatter::LcovFormatter.config do |c|
9
- c.report_with_single_file = true
10
- c.single_report_path = 'coverage/lcov.info'
11
- end
12
-
13
- formatter SimpleCov::Formatter::LcovFormatter
14
- end
15
- end
16
-
17
- require 'rspec/its'
18
- require 'redis'
19
- $LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, '..', '..', 'lib')))
20
- require 'mock_redis'
21
- require 'timecop'
22
-
23
- $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
24
- Dir['spec/support/**/*.rb'].sort.each { |x| require x }
25
-
26
- module TypeCheckingHelper
27
- def method_from_description(example)
28
- # extracting this from the RSpec description string may or may not
29
- # be a good idea. On the one hand, it enforces the convention of
30
- # putting the method name in the right place; on the other hand,
31
- # it's pretty magic-looking.
32
- example.full_description.match(/#(\w+)/).captures.first
33
- end
34
-
35
- def args_for_method(method)
36
- return [] if %w[spop zpopmin zpopmax].include?(method.to_s)
37
- method_arity = @redises.real.method(method).arity
38
- if method_arity < 0 # -1 comes from def foo(*args)
39
- [1, 2] # probably good enough
40
- else
41
- 1.upto(method_arity - 1).to_a
42
- end
43
- end
44
- end
45
-
46
- RSpec.configure do |config|
47
- config.expect_with :rspec do |c|
48
- c.syntax = [:expect, :should]
49
- end
50
-
51
- config.mock_with :rspec do |c|
52
- c.syntax = [:expect, :should]
53
- end
54
-
55
- config.include(TypeCheckingHelper)
56
-
57
- config.before(:all) do
58
- @redises = RedisMultiplexer.new
59
- end
60
-
61
- config.before(:each) do
62
- # databases mentioned in our tests
63
- [1, 0].each do |db|
64
- @redises.send_without_checking(:select, db)
65
- keys = @redises.send_without_checking(:keys, 'mock-redis-test:*')
66
- next unless keys.is_a?(Enumerable)
67
-
68
- keys.each do |key|
69
- @redises.send_without_checking(:del, key)
70
- end
71
- end
72
- @redises._gsub_clear
73
- end
74
- end
@@ -1,123 +0,0 @@
1
- class BlankSlate
2
- instance_methods.each do |m|
3
- undef_method(m) unless m =~ /^__/ || %w[inspect object_id].include?(m.to_s)
4
- end
5
- end
6
-
7
- class RedisMultiplexer < BlankSlate
8
- MismatchedResponse = Class.new(StandardError)
9
-
10
- def initialize(*a)
11
- @mock_redis = MockRedis.new(*a)
12
- Redis.exists_returns_integer = true
13
- @real_redis = Redis.new(*a)
14
- _gsub_clear
15
- end
16
-
17
- def _gsub(from, to)
18
- @gsub_from = from
19
- @gsub_to = to
20
- end
21
-
22
- def _gsub_clear
23
- @gsub_from = @gsub_to = ''
24
- end
25
-
26
- ruby2_keywords def method_missing(method, *args, &blk)
27
- # If we're in a Redis command that accepts a block, and we execute more
28
- # redis commands, ONLY execute them on the Redis implementation that the
29
- # block came from.
30
- # e.g. if a pipelined command is started on a MockRedis object, DON'T send
31
- # commands inside the pipelined block to the real Redis object, as that one
32
- # WON'T be inside a pipelined command, and we'll see weird behaviour
33
- if blk
34
- @in_mock_block = false
35
- @in_redis_block = true
36
- end
37
- real_retval, real_error =
38
- catch_errors { @in_mock_block ? :no_op : @real_redis.send(method, *args, &blk) }
39
-
40
- if blk
41
- @in_mock_block = true
42
- @in_redis_block = false
43
- end
44
- mock_retval, mock_error =
45
- catch_errors { @in_redis_block ? :no_op : @mock_redis.send(method, *args, &blk) }
46
-
47
- if blk
48
- @in_mock_block = false
49
- @in_redis_block = false
50
- end
51
-
52
- if mock_retval == :no_op || real_retval == :no_op
53
- # ignore, we were inside a block (like pipelined)
54
- elsif !equalish?(mock_retval, real_retval) && !mock_error && !real_error
55
- # no exceptions, just different behavior
56
- raise MismatchedResponse,
57
- "Mock failure: responses not equal.\n" \
58
- "Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" \
59
- "MockRedis.#{method}(#{args.inspect}) returned #{mock_retval.inspect}\n"
60
- elsif !mock_error && real_error
61
- raise MismatchedResponse,
62
- "Mock failure: didn't raise an error when it should have.\n" \
63
- "Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" \
64
- "MockRedis.#{method}(#{args.inspect}) raised nothing " \
65
- "and returned #{mock_retval.inspect}"
66
- elsif !real_error && mock_error
67
- raise MismatchedResponse,
68
- "Mock failure: raised an error when it shouldn't have.\n" \
69
- "Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" \
70
- "MockRedis.#{method}(#{args.inspect}) raised #{mock_error.inspect}"
71
- elsif mock_error && real_error && !equalish?(mock_error, real_error)
72
- raise MismatchedResponse,
73
- "Mock failure: raised the wrong error.\n" \
74
- "Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" \
75
- "MockRedis.#{method}(#{args.inspect}) raised #{mock_error.inspect}"
76
- end
77
-
78
- raise mock_error if mock_error
79
- mock_retval
80
- end
81
-
82
- def equalish?(a, b)
83
- if a == b
84
- true
85
- elsif a.is_a?(String) && b.is_a?(String)
86
- masked(a) == masked(b)
87
- elsif a.is_a?(Array) && b.is_a?(Array)
88
- a.collect { |c| masked(c.to_s) }.sort == b.collect { |c| masked(c.to_s) }.sort
89
- elsif a.is_a?(Exception) && b.is_a?(Exception)
90
- a.class == b.class && a.message == b.message
91
- elsif a.is_a?(Float) && b.is_a?(Float)
92
- delta = [a.abs, b.abs].min / 1_000_000.0
93
- (a - b).abs < delta
94
- else
95
- false
96
- end
97
- end
98
-
99
- def masked(str)
100
- str.gsub(@gsub_from, @gsub_to)
101
- end
102
-
103
- def mock
104
- @mock_redis
105
- end
106
-
107
- def real
108
- @real_redis
109
- end
110
-
111
- # Used in cleanup before() blocks.
112
- def send_without_checking(method, *args)
113
- @mock_redis.send(method, *args)
114
- @real_redis.send(method, *args)
115
- end
116
-
117
- def catch_errors
118
- retval = yield
119
- [retval, nil]
120
- rescue StandardError => e
121
- [nil, e]
122
- end
123
- end
@@ -1,14 +0,0 @@
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(defined?(default_error) ? default_error : RuntimeError)
12
- @redises.get(key).should == ''
13
- end
14
- end