mock_redis 0.5.4 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/lint.yml +31 -0
  3. data/.github/workflows/tests.yml +63 -0
  4. data/.gitignore +1 -1
  5. data/.overcommit.yml +21 -0
  6. data/.rspec +1 -1
  7. data/.rubocop.yml +148 -0
  8. data/.rubocop_todo.yml +35 -0
  9. data/.simplecov +4 -0
  10. data/CHANGELOG.md +278 -0
  11. data/Gemfile +9 -5
  12. data/LICENSE.md +21 -0
  13. data/README.md +52 -16
  14. data/Rakefile +0 -8
  15. data/lib/mock_redis/assertions.rb +0 -1
  16. data/lib/mock_redis/connection_method.rb +13 -0
  17. data/lib/mock_redis/database.rb +193 -257
  18. data/lib/mock_redis/expire_wrapper.rb +2 -2
  19. data/lib/mock_redis/future.rb +23 -0
  20. data/lib/mock_redis/geospatial_methods.rb +240 -0
  21. data/lib/mock_redis/hash_methods.rb +83 -24
  22. data/lib/mock_redis/indifferent_hash.rb +11 -0
  23. data/lib/mock_redis/info_method.rb +160 -0
  24. data/lib/mock_redis/list_methods.rb +34 -19
  25. data/lib/mock_redis/multi_db_wrapper.rb +8 -7
  26. data/lib/mock_redis/pipelined_wrapper.rb +42 -16
  27. data/lib/mock_redis/set_methods.rb +62 -19
  28. data/lib/mock_redis/sort_method.rb +81 -0
  29. data/lib/mock_redis/stream/id.rb +58 -0
  30. data/lib/mock_redis/stream.rb +88 -0
  31. data/lib/mock_redis/stream_methods.rb +102 -0
  32. data/lib/mock_redis/string_methods.rb +235 -42
  33. data/lib/mock_redis/transaction_wrapper.rb +62 -28
  34. data/lib/mock_redis/utility_methods.rb +62 -11
  35. data/lib/mock_redis/version.rb +4 -1
  36. data/lib/mock_redis/zset.rb +24 -29
  37. data/lib/mock_redis/zset_methods.rb +187 -59
  38. data/lib/mock_redis.rb +77 -27
  39. data/mock_redis.gemspec +23 -15
  40. data/spec/client_spec.rb +29 -0
  41. data/spec/cloning_spec.rb +17 -18
  42. data/spec/commands/append_spec.rb +4 -4
  43. data/spec/commands/auth_spec.rb +1 -1
  44. data/spec/commands/bgrewriteaof_spec.rb +2 -2
  45. data/spec/commands/bgsave_spec.rb +2 -2
  46. data/spec/commands/bitcount_spec.rb +25 -0
  47. data/spec/commands/bitfield_spec.rb +169 -0
  48. data/spec/commands/blpop_spec.rb +19 -21
  49. data/spec/commands/brpop_spec.rb +25 -20
  50. data/spec/commands/brpoplpush_spec.rb +16 -17
  51. data/spec/commands/connected_spec.rb +7 -0
  52. data/spec/commands/connection_spec.rb +15 -0
  53. data/spec/commands/dbsize_spec.rb +3 -3
  54. data/spec/commands/decr_spec.rb +8 -8
  55. data/spec/commands/decrby_spec.rb +8 -8
  56. data/spec/commands/del_spec.rb +35 -3
  57. data/spec/commands/disconnect_spec.rb +7 -0
  58. data/spec/commands/dump_spec.rb +19 -0
  59. data/spec/commands/echo_spec.rb +4 -4
  60. data/spec/commands/eval_spec.rb +7 -0
  61. data/spec/commands/evalsha_spec.rb +10 -0
  62. data/spec/commands/exists_spec.rb +36 -7
  63. data/spec/commands/expire_spec.rb +48 -20
  64. data/spec/commands/expireat_spec.rb +12 -13
  65. data/spec/commands/flushall_spec.rb +5 -5
  66. data/spec/commands/flushdb_spec.rb +5 -5
  67. data/spec/commands/future_spec.rb +30 -0
  68. data/spec/commands/geoadd_spec.rb +58 -0
  69. data/spec/commands/geodist_spec.rb +118 -0
  70. data/spec/commands/geohash_spec.rb +52 -0
  71. data/spec/commands/geopos_spec.rb +55 -0
  72. data/spec/commands/get_spec.rb +14 -6
  73. data/spec/commands/getbit_spec.rb +7 -7
  74. data/spec/commands/getrange_spec.rb +9 -9
  75. data/spec/commands/getset_spec.rb +7 -7
  76. data/spec/commands/hdel_spec.rb +41 -11
  77. data/spec/commands/hexists_spec.rb +11 -11
  78. data/spec/commands/hget_spec.rb +7 -7
  79. data/spec/commands/hgetall_spec.rb +15 -5
  80. data/spec/commands/hincrby_spec.rb +16 -16
  81. data/spec/commands/hincrbyfloat_spec.rb +58 -0
  82. data/spec/commands/hkeys_spec.rb +5 -5
  83. data/spec/commands/hlen_spec.rb +5 -5
  84. data/spec/commands/hmget_spec.rb +19 -9
  85. data/spec/commands/hmset_spec.rb +38 -12
  86. data/spec/commands/hscan_each_spec.rb +48 -0
  87. data/spec/commands/hscan_spec.rb +27 -0
  88. data/spec/commands/hset_spec.rb +26 -12
  89. data/spec/commands/hsetnx_spec.rb +16 -16
  90. data/spec/commands/hvals_spec.rb +5 -5
  91. data/spec/commands/incr_spec.rb +8 -8
  92. data/spec/commands/incrby_spec.rb +13 -13
  93. data/spec/commands/incrbyfloat_spec.rb +13 -13
  94. data/spec/commands/info_spec.rb +54 -5
  95. data/spec/commands/keys_spec.rb +83 -31
  96. data/spec/commands/lastsave_spec.rb +2 -2
  97. data/spec/commands/lindex_spec.rb +20 -10
  98. data/spec/commands/linsert_spec.rb +14 -14
  99. data/spec/commands/llen_spec.rb +4 -4
  100. data/spec/commands/lpop_spec.rb +6 -6
  101. data/spec/commands/lpush_spec.rb +21 -15
  102. data/spec/commands/lpushx_spec.rb +24 -11
  103. data/spec/commands/lrange_spec.rb +24 -8
  104. data/spec/commands/lrem_spec.rb +16 -16
  105. data/spec/commands/lset_spec.rb +17 -12
  106. data/spec/commands/ltrim_spec.rb +17 -7
  107. data/spec/commands/mapped_hmget_spec.rb +13 -9
  108. data/spec/commands/mapped_hmset_spec.rb +12 -12
  109. data/spec/commands/mapped_mget_spec.rb +22 -0
  110. data/spec/commands/mapped_mset_spec.rb +19 -0
  111. data/spec/commands/mapped_msetnx_spec.rb +26 -0
  112. data/spec/commands/mget_spec.rb +48 -17
  113. data/spec/commands/move_spec.rb +37 -37
  114. data/spec/commands/mset_spec.rb +20 -6
  115. data/spec/commands/msetnx_spec.rb +14 -14
  116. data/spec/commands/persist_spec.rb +15 -16
  117. data/spec/commands/pexpire_spec.rb +86 -0
  118. data/spec/commands/pexpireat_spec.rb +48 -0
  119. data/spec/commands/ping_spec.rb +6 -2
  120. data/spec/commands/pipelined_spec.rb +98 -7
  121. data/spec/commands/pttl_spec.rb +41 -0
  122. data/spec/commands/randomkey_spec.rb +3 -3
  123. data/spec/commands/rename_spec.rb +16 -12
  124. data/spec/commands/renamenx_spec.rb +13 -15
  125. data/spec/commands/restore_spec.rb +47 -0
  126. data/spec/commands/rpop_spec.rb +6 -6
  127. data/spec/commands/rpoplpush_spec.rb +13 -8
  128. data/spec/commands/rpush_spec.rb +21 -15
  129. data/spec/commands/rpushx_spec.rb +24 -11
  130. data/spec/commands/sadd_spec.rb +14 -10
  131. data/spec/commands/scan_each_spec.rb +39 -0
  132. data/spec/commands/scan_spec.rb +64 -0
  133. data/spec/commands/scard_spec.rb +3 -3
  134. data/spec/commands/script_spec.rb +9 -0
  135. data/spec/commands/sdiff_spec.rb +13 -13
  136. data/spec/commands/sdiffstore_spec.rb +13 -13
  137. data/spec/commands/select_spec.rb +13 -5
  138. data/spec/commands/set_spec.rb +112 -0
  139. data/spec/commands/setbit_spec.rb +25 -16
  140. data/spec/commands/setex_spec.rb +20 -4
  141. data/spec/commands/setnx_spec.rb +6 -6
  142. data/spec/commands/setrange_spec.rb +12 -12
  143. data/spec/commands/sinter_spec.rb +11 -13
  144. data/spec/commands/sinterstore_spec.rb +12 -12
  145. data/spec/commands/sismember_spec.rb +10 -10
  146. data/spec/commands/smembers_spec.rb +15 -5
  147. data/spec/commands/smove_spec.rb +13 -13
  148. data/spec/commands/sort_list_spec.rb +21 -0
  149. data/spec/commands/sort_set_spec.rb +21 -0
  150. data/spec/commands/sort_zset_spec.rb +21 -0
  151. data/spec/commands/spop_spec.rb +19 -4
  152. data/spec/commands/srandmember_spec.rb +28 -4
  153. data/spec/commands/srem_spec.rb +17 -12
  154. data/spec/commands/sscan_each_spec.rb +48 -0
  155. data/spec/commands/sscan_spec.rb +39 -0
  156. data/spec/commands/strlen_spec.rb +4 -5
  157. data/spec/commands/sunion_spec.rb +13 -11
  158. data/spec/commands/sunionstore_spec.rb +12 -12
  159. data/spec/commands/ttl_spec.rb +11 -6
  160. data/spec/commands/type_spec.rb +1 -1
  161. data/spec/commands/watch_spec.rb +9 -4
  162. data/spec/commands/xadd_spec.rb +122 -0
  163. data/spec/commands/xlen_spec.rb +22 -0
  164. data/spec/commands/xrange_spec.rb +164 -0
  165. data/spec/commands/xread_spec.rb +66 -0
  166. data/spec/commands/xrevrange_spec.rb +130 -0
  167. data/spec/commands/xtrim_spec.rb +36 -0
  168. data/spec/commands/zadd_spec.rb +100 -11
  169. data/spec/commands/zcard_spec.rb +4 -4
  170. data/spec/commands/zcount_spec.rb +18 -10
  171. data/spec/commands/zincrby_spec.rb +6 -6
  172. data/spec/commands/zinterstore_spec.rb +54 -20
  173. data/spec/commands/zpopmax_spec.rb +60 -0
  174. data/spec/commands/zpopmin_spec.rb +60 -0
  175. data/spec/commands/zrange_spec.rb +54 -13
  176. data/spec/commands/zrangebyscore_spec.rb +42 -27
  177. data/spec/commands/zrank_spec.rb +4 -4
  178. data/spec/commands/zrem_spec.rb +18 -12
  179. data/spec/commands/zremrangebyrank_spec.rb +5 -5
  180. data/spec/commands/zremrangebyscore_spec.rb +12 -5
  181. data/spec/commands/zrevrange_spec.rb +35 -10
  182. data/spec/commands/zrevrangebyscore_spec.rb +26 -15
  183. data/spec/commands/zrevrank_spec.rb +4 -4
  184. data/spec/commands/zscan_each_spec.rb +48 -0
  185. data/spec/commands/zscan_spec.rb +26 -0
  186. data/spec/commands/zscore_spec.rb +7 -7
  187. data/spec/commands/zunionstore_spec.rb +54 -21
  188. data/spec/mock_redis_spec.rb +61 -0
  189. data/spec/spec_helper.rb +35 -8
  190. data/spec/support/redis_multiplexer.rb +62 -37
  191. data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +14 -0
  192. data/spec/support/shared_examples/only_operates_on_hashes.rb +5 -3
  193. data/spec/support/shared_examples/only_operates_on_lists.rb +5 -3
  194. data/spec/support/shared_examples/only_operates_on_sets.rb +5 -3
  195. data/spec/support/shared_examples/only_operates_on_strings.rb +4 -4
  196. data/spec/support/shared_examples/only_operates_on_zsets.rb +18 -16
  197. data/spec/support/shared_examples/sorts_enumerables.rb +56 -0
  198. data/spec/transactions_spec.rb +79 -29
  199. metadata +162 -42
  200. data/LICENSE +0 -19
  201. data/spec/commands/hash_operator_spec.rb +0 -21
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])" do
3
+ describe '#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])' do
4
4
  before do
5
5
  @odds = 'mock-redis-test:zinterstore:odds'
6
6
  @primes = 'mock-redis-test:zinterstore:primes'
@@ -18,45 +18,79 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
18
18
  @redises.zadd(@primes, 7, 'seven')
19
19
  end
20
20
 
21
- it "returns the number of elements in the new set" do
21
+ it 'returns the number of elements in the new set' do
22
22
  @redises.zinterstore(@dest, [@odds, @primes]).should == 3
23
23
  end
24
24
 
25
25
  it "sums the members' scores by default" do
26
26
  @redises.zinterstore(@dest, [@odds, @primes])
27
27
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
28
- [["three", 6.0], ["five", 10.0], ["seven", 14.0]]
28
+ [['three', 6.0], ['five', 10.0], ['seven', 14.0]]
29
29
  end
30
30
 
31
- it "removes existing elements in destination" do
31
+ it 'removes existing elements in destination' do
32
32
  @redises.zadd(@dest, 10, 'ten')
33
33
 
34
34
  @redises.zinterstore(@dest, [@primes])
35
35
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
36
- [["two", 2.0], ["three", 3.0], ["five", 5.0], ["seven", 7.0]]
36
+ [['two', 2.0], ['three', 3.0], ['five', 5.0], ['seven', 7.0]]
37
37
  end
38
38
 
39
- it "raises an error if keys is empty" do
39
+ it 'raises an error if keys is empty' do
40
40
  lambda do
41
41
  @redises.zinterstore(@dest, [])
42
- end.should raise_error(RuntimeError)
42
+ end.should raise_error(Redis::CommandError)
43
43
  end
44
44
 
45
- context "the :weights argument" do
46
- it "multiplies the scores by the weights while aggregating" do
45
+ context 'when used with a set' do
46
+ before do
47
+ @primes_text = 'mock-redis-test:zinterstore:primes-text'
48
+
49
+ @redises.sadd(@primes_text, 'two')
50
+ @redises.sadd(@primes_text, 'three')
51
+ @redises.sadd(@primes_text, 'five')
52
+ @redises.sadd(@primes_text, 'seven')
53
+ end
54
+
55
+ it 'returns the number of elements in the new set' do
56
+ @redises.zinterstore(@dest, [@odds, @primes_text]).should == 3
57
+ end
58
+
59
+ it 'sums the scores, substituting 1.0 for set values' do
60
+ @redises.zinterstore(@dest, [@odds, @primes_text])
61
+ @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
62
+ [['three', 4.0], ['five', 6.0], ['seven', 8.0]]
63
+ end
64
+ end
65
+
66
+ context 'when used with a non-coercible structure' do
67
+ before do
68
+ @non_set = 'mock-redis-test:zinterstore:non-set'
69
+
70
+ @redises.set(@non_set, 'one')
71
+ end
72
+ it 'raises an error for wrong value type' do
73
+ lambda do
74
+ @redises.zinterstore(@dest, [@odds, @non_set])
75
+ end.should raise_error(Redis::CommandError)
76
+ end
77
+ end
78
+
79
+ context 'the :weights argument' do
80
+ it 'multiplies the scores by the weights while aggregating' do
47
81
  @redises.zinterstore(@dest, [@odds, @primes], :weights => [2, 3])
48
82
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
49
- [["three", 15.0], ["five", 25.0], ["seven", 35.0]]
83
+ [['three', 15.0], ['five', 25.0], ['seven', 35.0]]
50
84
  end
51
85
 
52
- it "raises an error if the number of weights != the number of keys" do
86
+ it 'raises an error if the number of weights != the number of keys' do
53
87
  lambda do
54
- @redises.zinterstore(@dest, [@odds, @primes], :weights => [1,2,3])
55
- end.should raise_error(RuntimeError)
88
+ @redises.zinterstore(@dest, [@odds, @primes], :weights => [1, 2, 3])
89
+ end.should raise_error(Redis::CommandError)
56
90
  end
57
91
  end
58
92
 
59
- context "the :aggregate argument" do
93
+ context 'the :aggregate argument' do
60
94
  before do
61
95
  @smalls = 'mock-redis-test:zinterstore:smalls'
62
96
  @bigs = 'mock-redis-test:zinterstore:bigs'
@@ -67,16 +101,16 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
67
101
  @redises.zadd(@bigs, 200, 'ernie')
68
102
  end
69
103
 
70
- it "aggregates scores with min when :aggregate => :min is specified" do
104
+ it 'aggregates scores with min when :aggregate => :min is specified' do
71
105
  @redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :min)
72
106
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
73
- [["bert", 1.0], ["ernie", 2.0]]
107
+ [['bert', 1.0], ['ernie', 2.0]]
74
108
  end
75
109
 
76
- it "aggregates scores with max when :aggregate => :max is specified" do
110
+ it 'aggregates scores with max when :aggregate => :max is specified' do
77
111
  @redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :max)
78
112
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
79
- [["bert", 100.0], ["ernie", 200.0]]
113
+ [['bert', 100.0], ['ernie', 200.0]]
80
114
  end
81
115
 
82
116
  it "allows 'min', 'MIN', etc. as aliases for :min" do
@@ -87,10 +121,10 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
87
121
  @redises.zscore(@dest, 'bert').should == 1.0
88
122
  end
89
123
 
90
- it "raises an error for unknown aggregation function" do
124
+ it 'raises an error for unknown aggregation function' do
91
125
  lambda do
92
126
  @redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :mix)
93
- end.should raise_error(RuntimeError)
127
+ end.should raise_error(Redis::CommandError)
94
128
  end
95
129
  end
96
130
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe '#zpopmax(key, count)' do
4
+ before(:each) do
5
+ @key = 'mock-redis-test:zpopmax'
6
+ @redises.del(@key)
7
+ @redises.zadd(@key, 1, 'one')
8
+ @redises.zadd(@key, 2, 'two')
9
+ @redises.zadd(@key, 3, 'three')
10
+ end
11
+
12
+ context 'when count is unspecified' do
13
+ it 'returns nil if the set does not exist' do
14
+ @redises.zpopmax('does-not-exist').should nil
15
+ end
16
+
17
+ it 'returns the highest ranked element' do
18
+ @redises.zpopmax(@key).should == ['three', 3]
19
+ @redises.zcard(@key).should == 2
20
+ end
21
+ end
22
+
23
+ context 'when count is 1' do
24
+ let(:count) { 1 }
25
+
26
+ it 'returns nil if the set does not exist' do
27
+ @redises.zpopmax('does-not-exist', count).should nil
28
+ end
29
+
30
+ it 'returns the highest ranked element' do
31
+ @redises.zpopmax(@key, count).should == ['three', 3]
32
+ @redises.zcard(@key).should == 2
33
+ end
34
+ end
35
+
36
+ context 'when count is greater than 1' do
37
+ let(:count) { 2 }
38
+
39
+ it 'returns empty array if the set does not exist' do
40
+ @redises.zpopmax('does-not-exist', count).should == []
41
+ end
42
+
43
+ it 'returns the highest ranked elements' do
44
+ @redises.zpopmax(@key, count).should == [['three', 3], ['two', 2]]
45
+ @redises.zcard(@key).should == 1
46
+ end
47
+ end
48
+
49
+ context 'when count is greater than the size of the set' do
50
+ let(:count) { 4 }
51
+
52
+ it 'returns the entire set' do
53
+ before = @redises.zrange(@key, 0, count, with_scores: true).reverse
54
+ @redises.zpopmax(@key, count).should == before
55
+ @redises.zcard(@key).should == 0
56
+ end
57
+ end
58
+
59
+ it_should_behave_like 'a zset-only command'
60
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe '#zpopmin(key, count)' do
4
+ before(:each) do
5
+ @key = 'mock-redis-test:zpopmin'
6
+ @redises.del(@key)
7
+ @redises.zadd(@key, 1, 'one')
8
+ @redises.zadd(@key, 2, 'two')
9
+ @redises.zadd(@key, 3, 'three')
10
+ end
11
+
12
+ context 'when count is unspecified' do
13
+ it 'returns nil if the set does not exist' do
14
+ @redises.zpopmin('does-not-exist').should nil
15
+ end
16
+
17
+ it 'returns the lowest ranked element' do
18
+ @redises.zpopmin(@key).should == ['one', 1]
19
+ @redises.zcard(@key).should == 2
20
+ end
21
+ end
22
+
23
+ context 'when count is 1' do
24
+ let(:count) { 1 }
25
+
26
+ it 'returns nil if the set does not exist' do
27
+ @redises.zpopmin('does-not-exist', count).should nil
28
+ end
29
+
30
+ it 'returns the lowest ranked element' do
31
+ @redises.zpopmin(@key, count).should == ['one', 1]
32
+ @redises.zcard(@key).should == 2
33
+ end
34
+ end
35
+
36
+ context 'when count is greater than 1' do
37
+ let(:count) { 2 }
38
+
39
+ it 'returns empty array if the set does not exist' do
40
+ @redises.zpopmin('does-not-exist', count).should == []
41
+ end
42
+
43
+ it 'returns the lowest ranked elements' do
44
+ @redises.zpopmin(@key, count).should == [['one', 1], ['two', 2]]
45
+ @redises.zcard(@key).should == 1
46
+ end
47
+ end
48
+
49
+ context 'when count is greater than the size of the set' do
50
+ let(:count) { 4 }
51
+
52
+ it 'returns the entire set' do
53
+ before = @redises.zrange(@key, 0, count, with_scores: true)
54
+ @redises.zpopmin(@key, count).should == before
55
+ @redises.zcard(@key).should == 0
56
+ end
57
+ end
58
+
59
+ it_should_behave_like 'a zset-only command'
60
+ end
@@ -1,39 +1,80 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrange(key, start, stop [, :with_scores => true])" do
3
+ describe '#zrange(key, start, stop [, :with_scores => true])' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrange'
6
+ @redises.zadd(@key, 3, 'Jefferson')
6
7
  @redises.zadd(@key, 1, 'Washington')
7
8
  @redises.zadd(@key, 2, 'Adams')
8
- @redises.zadd(@key, 3, 'Jefferson')
9
9
  @redises.zadd(@key, 4, 'Madison')
10
10
  end
11
11
 
12
- it "returns the elements when the range is given as strings" do
13
- @redises.zrange(@key, "0", "1").should == ['Washington', 'Adams']
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.zrange(@key, 0, 4).should == []
20
+ end
14
21
  end
15
22
 
16
- it "returns the elements in order by score" do
17
- @redises.zrange(@key, 0, 1).should == ['Washington', 'Adams']
23
+ it 'returns the elements when the range is given as strings' do
24
+ @redises.zrange(@key, '0', '1').should == %w[Washington Adams]
18
25
  end
19
26
 
20
- it "returns the elements in order by score (negative indices)" do
21
- @redises.zrange(@key, -2, -1).should == ['Jefferson', 'Madison']
27
+ it 'returns the elements in order by score' do
28
+ @redises.zrange(@key, 0, 1).should == %w[Washington Adams]
29
+ end
30
+
31
+ context 'when a subset of elements have the same score' do
32
+ before do
33
+ @redises.zadd(@key, 1, 'Martha')
34
+ end
35
+
36
+ it 'returns the elements in ascending lexicographical order' do
37
+ @redises.zrange(@key, 0, 1).should == %w[Martha Washington]
38
+ end
39
+ end
40
+
41
+ it 'returns the elements in order by score (negative indices)' do
42
+ @redises.zrange(@key, -2, -1).should == %w[Jefferson Madison]
22
43
  end
23
44
 
24
45
  it 'returns empty list when start is too large' do
25
46
  @redises.zrange(@key, 5, -1).should == []
26
47
  end
27
48
 
28
- it "returns the scores when :with_scores is specified" do
49
+ it 'returns entire list when start is out of bounds with negative end in bounds' do
50
+ @redises.zrange(@key, -5, -1).should == %w[Washington Adams Jefferson Madison]
51
+ end
52
+
53
+ it 'returns correct subset when start is out of bounds with positive end in bounds' do
54
+ @redises.zrange(@key, -5, 1).should == %w[Washington Adams]
55
+ end
56
+
57
+ it 'returns empty list when start is in bounds with negative end out of bounds' do
58
+ @redises.zrange(@key, 1, -5).should == []
59
+ end
60
+
61
+ it 'returns empty list when start is 0 with negative end out of bounds' do
62
+ @redises.zrange(@key, 0, -5).should == []
63
+ end
64
+
65
+ it 'returns correct subset when start is in bounds with negative end in bounds' do
66
+ @redises.zrange(@key, 1, -1).should == %w[Adams Jefferson Madison]
67
+ end
68
+
69
+ it 'returns the scores when :with_scores is specified' do
29
70
  @redises.zrange(@key, 0, 1, :with_scores => true).
30
- should == [["Washington", 1.0], ["Adams", 2.0]]
71
+ should == [['Washington', 1.0], ['Adams', 2.0]]
31
72
  end
32
73
 
33
- it "returns the scores when :withscores is specified" do
74
+ it 'returns the scores when :withscores is specified' do
34
75
  @redises.zrange(@key, 0, 1, :withscores => true).
35
- should == [["Washington", 1.0], ["Adams", 2.0]]
76
+ should == [['Washington', 1.0], ['Adams', 2.0]]
36
77
  end
37
78
 
38
- it_should_behave_like "a zset-only command"
79
+ it_should_behave_like 'a zset-only command'
39
80
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])" do
3
+ describe '#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrangebyscore'
6
6
  @redises.zadd(@key, 1, 'Washington')
@@ -9,60 +9,75 @@ describe "#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [off
9
9
  @redises.zadd(@key, 4, 'Madison')
10
10
  end
11
11
 
12
- it "returns the elements in order by score" do
13
- @redises.zrangebyscore(@key, 1, 2).should == ['Washington', 'Adams']
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.zrangebyscore(@key, 0, 4).should == []
20
+ end
21
+ end
22
+
23
+ it 'returns the elements in order by score' do
24
+ @redises.zrangebyscore(@key, 1, 2).should == %w[Washington Adams]
14
25
  end
15
26
 
16
- it "returns the scores when :with_scores is specified" do
27
+ it 'returns the scores when :with_scores is specified' do
17
28
  @redises.zrangebyscore(@key, 1, 2, :with_scores => true).
18
- should == [["Washington", 1.0], ["Adams", 2.0]]
29
+ should == [['Washington', 1.0], ['Adams', 2.0]]
19
30
  end
20
31
 
21
- it "returns the scores when :withscores is specified" do
32
+ it 'returns the scores when :withscores is specified' do
22
33
  @redises.zrangebyscore(@key, 1, 2, :withscores => true).
23
- should == [["Washington", 1.0], ["Adams", 2.0]]
34
+ should == [['Washington', 1.0], ['Adams', 2.0]]
24
35
  end
25
36
 
26
- it "honors the :limit => [offset count] argument" do
37
+ it 'honors the :limit => [offset count] argument' do
27
38
  @redises.zrangebyscore(@key, -100, 100, :limit => [1, 2]).
28
- should == ["Adams", "Jefferson"]
39
+ should == %w[Adams Jefferson]
29
40
  end
30
41
 
31
42
  it "raises an error if :limit isn't a 2-tuple" do
32
43
  lambda do
33
44
  @redises.zrangebyscore(@key, -100, 100, :limit => [1, 2, 3])
34
- end.should raise_error(RuntimeError)
45
+ end.should raise_error(Redis::CommandError)
35
46
 
36
47
  lambda do
37
- @redises.zrangebyscore(@key, -100, 100, :limit => "1, 2")
38
- end.should raise_error
48
+ @redises.zrangebyscore(@key, -100, 100, :limit => '1, 2')
49
+ end.should raise_error(RedisMultiplexer::MismatchedResponse)
50
+ end
51
+
52
+ it 'treats scores like floats, not strings' do
53
+ @redises.zadd(@key, '10', 'Tyler')
54
+ @redises.zrangebyscore(@key, 1, 2).should == %w[Washington Adams]
39
55
  end
40
56
 
41
- it "treats scores like floats, not strings" do
42
- @redises.zadd(@key, "10", "Tyler")
43
- @redises.zrangebyscore(@key, 1, 2).should == ['Washington', 'Adams']
57
+ it 'treats -inf as negative infinity' do
58
+ @redises.zrangebyscore(@key, '-inf', 3).should ==
59
+ %w[Washington Adams Jefferson]
44
60
  end
45
61
 
46
- it "treats -inf as negative infinity" do
47
- @redises.zrangebyscore(@key, "-inf", 3).should ==
48
- ["Washington", "Adams", "Jefferson"]
62
+ it 'treats +inf as positive infinity' do
63
+ @redises.zrangebyscore(@key, 3, '+inf').should == %w[Jefferson Madison]
49
64
  end
50
65
 
51
- it "treats +inf as positive infinity" do
52
- @redises.zrangebyscore(@key, 3, "+inf").should == ["Jefferson", "Madison"]
66
+ it 'treats +inf as positive infinity' do
67
+ @redises.zrangebyscore(@key, 3, '+inf').should == %w[Jefferson Madison]
53
68
  end
54
69
 
55
- it "treats +inf as positive infinity" do
56
- @redises.zrangebyscore(@key, 3, "+inf").should == ["Jefferson", "Madison"]
70
+ it 'honors exclusive ranges on the left' do
71
+ @redises.zrangebyscore(@key, '(3', 4).should == ['Madison']
57
72
  end
58
73
 
59
- it "honors exclusive ranges on the left" do
60
- @redises.zrangebyscore(@key, "(3", 4).should == ["Madison"]
74
+ it 'honors exclusive ranges on the right' do
75
+ @redises.zrangebyscore(@key, '3', '(4').should == ['Jefferson']
61
76
  end
62
77
 
63
- it "honors exclusive ranges on the right" do
64
- @redises.zrangebyscore(@key, "3", "(4").should == ["Jefferson"]
78
+ it 'honors exclusive ranges on the left and the right simultaneously' do
79
+ @redises.zrangebyscore(@key, '(1', '(4').should == %w[Adams Jefferson]
65
80
  end
66
81
 
67
- it_should_behave_like "a zset-only command"
82
+ it_should_behave_like 'a zset-only command'
68
83
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrank(key, member)" do
3
+ describe '#zrank(key, member)' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrank'
6
6
 
@@ -13,17 +13,17 @@ describe "#zrank(key, member)" do
13
13
  @redises.zrank(@key, 'foo').should be_nil
14
14
  end
15
15
 
16
- it "returns the index of the member in the set" do
16
+ it 'returns the index of the member in the set' do
17
17
  @redises.zrank(@key, 'one').should == 0
18
18
  @redises.zrank(@key, 'two').should == 1
19
19
  @redises.zrank(@key, 'three').should == 2
20
20
  end
21
21
 
22
- it "handles integer members correctly" do
22
+ it 'handles integer members correctly' do
23
23
  member = 11
24
24
  @redises.zadd(@key, 4, member)
25
25
  @redises.zrank(@key, member).should == 3
26
26
  end
27
27
 
28
- it_should_behave_like "a zset-only command"
28
+ it_should_behave_like 'a zset-only command'
29
29
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrem(key, member)" do
3
+ describe '#zrem(key, member)' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrem'
6
6
 
@@ -8,30 +8,36 @@ describe "#zrem(key, member)" do
8
8
  @redises.zadd(@key, 2, 'two')
9
9
  end
10
10
 
11
- it "returns true if member is present in the set" do
12
- @redises.zrem(@key, 'one').should be_true
11
+ it 'returns true if member is present in the set' do
12
+ @redises.zrem(@key, 'one').should == true
13
13
  end
14
14
 
15
- it "returns false if member is not present in the set" do
16
- @redises.zrem(@key, 'nobody home').should be_false
15
+ it 'returns false if member is not present in the set' do
16
+ @redises.zrem(@key, 'nobody home').should == false
17
17
  end
18
18
 
19
- it "removes member from the set" do
19
+ it 'removes member from the set' do
20
20
  @redises.zrem(@key, 'one')
21
21
  @redises.zrange(@key, 0, -1).should == ['two']
22
22
  end
23
23
 
24
- it "removes integer member from the set" do
24
+ it 'removes integer member from the set' do
25
25
  member = 11
26
26
  @redises.zadd(@key, 3, member)
27
- @redises.zrem(@key, member).should be_true
28
- @redises.zrange(@key, 0, -1).should == ['one', 'two']
27
+ @redises.zrem(@key, member).should == true
28
+ @redises.zrange(@key, 0, -1).should == %w[one two]
29
29
  end
30
30
 
31
- it "supports a variable number of arguments" do
32
- @redises.zrem(@key, ['one', 'two'])
31
+ it 'supports a variable number of arguments' do
32
+ @redises.zrem(@key, %w[one two])
33
33
  @redises.zrange(@key, 0, -1).should be_empty
34
34
  end
35
35
 
36
- it_should_behave_like "a zset-only command"
36
+ it 'raises an error if member is an empty array' do
37
+ lambda do
38
+ @redises.zrem(@key, [])
39
+ end.should raise_error(Redis::CommandError)
40
+ end
41
+
42
+ it_should_behave_like 'a zset-only command'
37
43
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zremrangebyrank(key, start, stop)" do
3
+ describe '#zremrangebyrank(key, start, stop)' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zremrangebyrank'
6
6
  @redises.zadd(@key, 1, 'Washington')
@@ -9,19 +9,19 @@ describe "#zremrangebyrank(key, start, stop)" do
9
9
  @redises.zadd(@key, 4, 'Madison')
10
10
  end
11
11
 
12
- it "returns the number of elements in range" do
12
+ it 'returns the number of elements in range' do
13
13
  @redises.zremrangebyrank(@key, 2, 3).should == 2
14
14
  end
15
15
 
16
- it "removes the elements" do
16
+ it 'removes the elements' do
17
17
  @redises.zremrangebyrank(@key, 2, 3)
18
18
  @redises.zrange(@key, 0, -1).should == %w[Washington Adams]
19
19
  end
20
20
 
21
- it "does nothing if start is greater than cardinality of set" do
21
+ it 'does nothing if start is greater than cardinality of set' do
22
22
  @redises.zremrangebyrank(@key, 5, -1)
23
23
  @redises.zrange(@key, 0, -1).should == %w[Washington Adams Jefferson Madison]
24
24
  end
25
25
 
26
- it_should_behave_like "a zset-only command"
26
+ it_should_behave_like 'a zset-only command'
27
27
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
+ require 'date'
2
3
 
3
- describe "#zremrangebyscore(key, min, max)" do
4
+ describe '#zremrangebyscore(key, min, max)' do
4
5
  before do
5
6
  @key = 'mock-redis-test:zremrangebyscore'
6
7
  @redises.zadd(@key, 1, 'Washington')
@@ -9,20 +10,26 @@ describe "#zremrangebyscore(key, min, max)" do
9
10
  @redises.zadd(@key, 4, 'Madison')
10
11
  end
11
12
 
12
- it "returns the number of elements in range" do
13
+ it 'returns the number of elements in range' do
13
14
  @redises.zremrangebyscore(@key, 2, 3).should == 2
14
15
  end
15
16
 
16
- it "removes the elements" do
17
+ it 'removes the elements' do
17
18
  @redises.zremrangebyscore(@key, 2, 3)
18
19
  @redises.zrange(@key, 0, -1).should == %w[Washington Madison]
19
20
  end
20
21
 
21
22
  # As seen in http://redis.io/commands/zremrangebyscore
22
- it "removes the elements for complex statements" do
23
+ it 'removes the elements for complex statements' do
23
24
  @redises.zremrangebyscore(@key, '-inf', '(4')
24
25
  @redises.zrange(@key, 0, -1).should == %w[Madison]
25
26
  end
26
27
 
27
- it_should_behave_like "a zset-only command"
28
+ it_should_behave_like 'a zset-only command'
29
+
30
+ it 'throws a command error' do
31
+ expect do
32
+ @redises.zrevrangebyscore(@key, DateTime.now, '-inf')
33
+ end.to raise_error(Redis::CommandError)
34
+ end
28
35
  end