mock_redis 0.5.4 → 0.31.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 (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
@@ -3,32 +3,32 @@ require 'spec_helper'
3
3
  describe '#incr(key)' do
4
4
  before { @key = 'mock-redis-test:33888' }
5
5
 
6
- it "returns the value after the increment" do
6
+ it 'returns the value after the increment' do
7
7
  @redises.set(@key, 1)
8
8
  @redises.incr(@key).should == 2
9
9
  end
10
10
 
11
- it "treats a missing key like 0" do
11
+ it 'treats a missing key like 0' do
12
12
  @redises.incr(@key).should == 1
13
13
  end
14
14
 
15
- it "increments negative numbers" do
15
+ it 'increments negative numbers' do
16
16
  @redises.set(@key, -10)
17
17
  @redises.incr(@key).should == -9
18
18
  end
19
19
 
20
- it "works multiple times" do
20
+ it 'works multiple times' do
21
21
  @redises.incr(@key).should == 1
22
22
  @redises.incr(@key).should == 2
23
23
  @redises.incr(@key).should == 3
24
24
  end
25
25
 
26
- it "raises an error if the value does not look like an integer" do
27
- @redises.set(@key, "one")
26
+ it 'raises an error if the value does not look like an integer' do
27
+ @redises.set(@key, 'one')
28
28
  lambda do
29
29
  @redises.incr(@key)
30
- end.should raise_error(RuntimeError)
30
+ end.should raise_error(Redis::CommandError)
31
31
  end
32
32
 
33
- it_should_behave_like "a string-only command"
33
+ it_should_behave_like 'a string-only command'
34
34
  end
@@ -3,42 +3,42 @@ require 'spec_helper'
3
3
  describe '#incrby(key, increment)' do
4
4
  before { @key = 'mock-redis-test:65374' }
5
5
 
6
- it "returns the value after the increment" do
6
+ it 'returns the value after the increment' do
7
7
  @redises.set(@key, 2)
8
8
  @redises.incrby(@key, 2).should == 4
9
9
  end
10
10
 
11
- it "treats a missing key like 0" do
11
+ it 'treats a missing key like 0' do
12
12
  @redises.incrby(@key, 1).should == 1
13
13
  end
14
14
 
15
- it "increments negative numbers" do
15
+ it 'increments negative numbers' do
16
16
  @redises.set(@key, -10)
17
17
  @redises.incrby(@key, 2).should == -8
18
18
  end
19
19
 
20
- it "works multiple times" do
20
+ it 'works multiple times' do
21
21
  @redises.incrby(@key, 2).should == 2
22
22
  @redises.incrby(@key, 2).should == 4
23
23
  @redises.incrby(@key, 2).should == 6
24
24
  end
25
25
 
26
- it "accepts an integer-ish string" do
27
- @redises.incrby(@key, "2").should == 2
26
+ it 'accepts an integer-ish string' do
27
+ @redises.incrby(@key, '2').should == 2
28
28
  end
29
29
 
30
- it "raises an error if the value does not look like an integer" do
31
- @redises.set(@key, "one")
30
+ it 'raises an error if the value does not look like an integer' do
31
+ @redises.set(@key, 'one')
32
32
  lambda do
33
33
  @redises.incrby(@key, 1)
34
- end.should raise_error(RuntimeError)
34
+ end.should raise_error(Redis::CommandError)
35
35
  end
36
36
 
37
- it "raises an error if the delta does not look like an integer" do
37
+ it 'raises an error if the delta does not look like an integer' do
38
38
  lambda do
39
- @redises.incrby(@key, "foo")
40
- end.should raise_error(RuntimeError)
39
+ @redises.incrby(@key, 'foo')
40
+ end.should raise_error(Redis::CommandError)
41
41
  end
42
42
 
43
- it_should_behave_like "a string-only command"
43
+ it_should_behave_like 'a string-only command'
44
44
  end
@@ -3,42 +3,42 @@ require 'spec_helper'
3
3
  describe '#incrbyfloat(key, increment)' do
4
4
  before { @key = 'mock-redis-test:65374' }
5
5
 
6
- it "returns the value after the increment" do
6
+ it 'returns the value after the increment' do
7
7
  @redises.set(@key, 2.0)
8
8
  @redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(4.1)
9
9
  end
10
10
 
11
- it "treats a missing key like 0" do
11
+ it 'treats a missing key like 0' do
12
12
  @redises.incrbyfloat(@key, 1.2).should be_within(0.0001).of(1.2)
13
13
  end
14
14
 
15
- it "increments negative numbers" do
15
+ it 'increments negative numbers' do
16
16
  @redises.set(@key, -10.4)
17
17
  @redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(-8.1)
18
18
  end
19
19
 
20
- it "works multiple times" do
20
+ it 'works multiple times' do
21
21
  @redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(2.1)
22
22
  @redises.incrbyfloat(@key, 2.2).should be_within(0.0001).of(4.3)
23
23
  @redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(6.6)
24
24
  end
25
25
 
26
- it "accepts an float-ish string" do
27
- @redises.incrbyfloat(@key, "2.2").should be_within(0.0001).of(2.2)
26
+ it 'accepts an float-ish string' do
27
+ @redises.incrbyfloat(@key, '2.2').should be_within(0.0001).of(2.2)
28
28
  end
29
29
 
30
- it "raises an error if the value does not look like an float" do
31
- @redises.set(@key, "one.two")
30
+ it 'raises an error if the value does not look like an float' do
31
+ @redises.set(@key, 'one.two')
32
32
  lambda do
33
33
  @redises.incrbyfloat(@key, 1)
34
- end.should raise_error(RuntimeError)
34
+ end.should raise_error(Redis::CommandError)
35
35
  end
36
36
 
37
- it "raises an error if the delta does not look like an float" do
37
+ it 'raises an error if the delta does not look like an float' do
38
38
  lambda do
39
- @redises.incrbyfloat(@key, "foobar.baz")
40
- end.should raise_error(RuntimeError)
39
+ @redises.incrbyfloat(@key, 'foobar.baz')
40
+ end.should raise_error(Redis::CommandError)
41
41
  end
42
42
 
43
- it_should_behave_like "a string-only command"
43
+ it_should_behave_like 'a string-only command'
44
44
  end
@@ -1,13 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe '#info [mock only]' do
4
- before { @info = @redises.mock.info }
4
+ let(:redis) { @redises.mock }
5
5
 
6
- it "responds with a config hash" do
7
- @info.should be_a(Hash)
6
+ it 'responds with a config hash' do
7
+ redis.info.should be_a(Hash)
8
8
  end
9
9
 
10
- it "has some data in it" do
11
- @info.keys.length.should > 0
10
+ it 'gets default set of info' do
11
+ info = redis.info
12
+ info['arch_bits'].should be_a(String)
13
+ info['connected_clients'].should be_a(String)
14
+ info['aof_rewrite_scheduled'].should be_a(String)
15
+ info['used_cpu_sys'].should be_a(String)
16
+ end
17
+
18
+ it 'gets all info' do
19
+ info = redis.info(:all)
20
+ info['arch_bits'].should be_a(String)
21
+ info['connected_clients'].should be_a(String)
22
+ info['aof_rewrite_scheduled'].should be_a(String)
23
+ info['used_cpu_sys'].should be_a(String)
24
+ info['cmdstat_slowlog'].should be_a(String)
25
+ end
26
+
27
+ it 'gets server info' do
28
+ redis.info(:server)['arch_bits'].should be_a(String)
29
+ end
30
+
31
+ it 'gets clients info' do
32
+ redis.info(:clients)['connected_clients'].should be_a(String)
33
+ end
34
+
35
+ it 'gets memory info' do
36
+ redis.info(:memory)['used_memory'].should be_a(String)
37
+ end
38
+
39
+ it 'gets persistence info' do
40
+ redis.info(:persistence)['aof_rewrite_scheduled'].should be_a(String)
41
+ end
42
+
43
+ it 'gets stats info' do
44
+ redis.info(:stats)['keyspace_hits'].should be_a(String)
45
+ end
46
+
47
+ it 'gets replication info' do
48
+ redis.info(:replication)['role'].should be_a(String)
49
+ end
50
+
51
+ it 'gets cpu info' do
52
+ redis.info(:cpu)['used_cpu_sys'].should be_a(String)
53
+ end
54
+
55
+ it 'gets keyspace info' do
56
+ redis.info(:keyspace)['db0'].should be_a(String)
57
+ end
58
+
59
+ it 'gets commandstats info' do
60
+ redis.info(:commandstats)['sunionstore']['usec'].should be_a(String)
12
61
  end
13
62
  end
@@ -1,55 +1,81 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe '#keys()' do
4
-
5
- it "returns [] when no keys are found (no regex characters)" do
6
- @redises.keys("mock-redis-test:29016").should == []
4
+ it 'returns [] when no keys are found (no regex characters)' do
5
+ @redises.keys('mock-redis-test:29016').should == []
7
6
  end
8
7
 
9
- it "returns [] when no keys are found (some regex characters)" do
10
- @redises.keys("mock-redis-test:29016*").should == []
8
+ it 'returns [] when no keys are found (some regex characters)' do
9
+ @redises.keys('mock-redis-test:29016*').should == []
11
10
  end
12
11
 
13
- describe "with pattern matching" do
12
+ describe 'with pattern matching' do
14
13
  before do
15
- @redises.set("mock-redis-test:key1", 1)
16
- @redises.set("mock-redis-test:key2", 2)
17
- @redises.set("mock-redis-test:key3", 3)
18
- @redises.set("mock-redis-test:key10", 10)
19
- @redises.set("mock-redis-test:key20", 20)
20
- @redises.set("mock-redis-test:key30", 30)
21
-
22
- @redises.set("mock-redis-test:special-key?", 'true')
23
- @redises.set("mock-redis-test:special-key*", 'true')
14
+ @redises.set('mock-redis-test:key', 0)
15
+ @redises.set('mock-redis-test:key1', 1)
16
+ @redises.set('mock-redis-test:key2', 2)
17
+ @redises.set('mock-redis-test:key3', 3)
18
+ @redises.set('mock-redis-test:key10', 10)
19
+ @redises.set('mock-redis-test:key20', 20)
20
+ @redises.set('mock-redis-test:key30', 30)
21
+
22
+ @redises.set('mock-redis-test:regexp-key(1|22)', 40)
23
+ @redises.set('mock-redis-test:regexp-key3+', 40)
24
+ @redises.set('mock-redis-test:regexp-key33', 40)
25
+ @redises.set('mock-redis-test:regexp-key4a', 40)
26
+ @redises.set('mock-redis-test:regexp-key4-', 40)
27
+ @redises.set('mock-redis-test:regexp-key4b', 40)
28
+ @redises.set('mock-redis-test:regexp-key4c', 40)
29
+
30
+ @redises.set('mock-redis-test:special-key?', 'true')
31
+ @redises.set('mock-redis-test:special-key*', 'true')
32
+ @redises.set('mock-redis-test:special-key-!?*', 'true')
24
33
  end
25
34
 
26
- describe "the ? character" do
27
- it "is treated as a single character (at the end of the pattern)" do
28
- @redises.keys("mock-redis-test:key?").sort.should == [
35
+ describe 'the ? character' do
36
+ it 'is treated as a single character (at the end of the pattern)' do
37
+ @redises.keys('mock-redis-test:key?').sort.should == [
29
38
  'mock-redis-test:key1',
30
39
  'mock-redis-test:key2',
31
40
  'mock-redis-test:key3',
32
41
  ]
33
42
  end
34
43
 
35
- it "is treated as a single character (in the middle of the pattern)" do
36
- @redises.keys("mock-redis-test:key?0").sort.should == [
44
+ it 'is treated as a single character (in the middle of the pattern)' do
45
+ @redises.keys('mock-redis-test:key?0').sort.should == [
37
46
  'mock-redis-test:key10',
38
47
  'mock-redis-test:key20',
39
48
  'mock-redis-test:key30',
40
49
  ]
41
50
  end
42
51
 
43
- it "treats \? as a literal ?" do
52
+ it 'treats \\? as a literal ?' do
44
53
  @redises.keys('mock-redis-test:special-key\?').sort.should == [
45
- 'mock-redis-test:special-key?'
54
+ 'mock-redis-test:special-key?',
46
55
  ]
47
56
  end
57
+
58
+ context 'multiple ? characters' do
59
+ it "properly handles multiple consequtive '?' characters" do
60
+ @redises.keys('mock-redis-test:special-key-???').sort.should == [
61
+ 'mock-redis-test:special-key-!?*',
62
+ ]
63
+ end
64
+
65
+ context '\\? as a literal ' do
66
+ it 'handles multiple ? as both literal and special character' do
67
+ @redises.keys('mock-redis-test:special-key-?\??').sort.should == [
68
+ 'mock-redis-test:special-key-!?*',
69
+ ]
70
+ end
71
+ end
72
+ end
48
73
  end
49
74
 
50
- describe "the * character" do
51
- it "is treated as 1 or more characters" do
52
- @redises.keys("mock-redis-test:key*").sort.should == [
75
+ describe 'the * character' do
76
+ it 'is treated as 0 or more characters' do
77
+ @redises.keys('mock-redis-test:key*').sort.should == [
78
+ 'mock-redis-test:key',
53
79
  'mock-redis-test:key1',
54
80
  'mock-redis-test:key10',
55
81
  'mock-redis-test:key2',
@@ -59,15 +85,15 @@ describe '#keys()' do
59
85
  ]
60
86
  end
61
87
 
62
- it "treats \* as a literal *" do
88
+ it 'treats \\* as a literal *' do
63
89
  @redises.keys('mock-redis-test:special-key\*').sort.should == [
64
- 'mock-redis-test:special-key*'
90
+ 'mock-redis-test:special-key*',
65
91
  ]
66
92
  end
67
93
  end
68
94
 
69
- describe "character classes ([abcde])" do
70
- it "matches any one of those characters" do
95
+ describe 'character classes ([abcde])' do
96
+ it 'matches any one of those characters' do
71
97
  @redises.keys('mock-redis-test:key[12]').sort.should == [
72
98
  'mock-redis-test:key1',
73
99
  'mock-redis-test:key2',
@@ -75,8 +101,34 @@ describe '#keys()' do
75
101
  end
76
102
  end
77
103
 
78
- describe "combining metacharacters" do
79
- it "works with different metacharacters simultaneously" do
104
+ describe 'the | character' do
105
+ it "is treated as literal (not 'or')" do
106
+ @redises.keys('mock-redis-test:regexp-key(1|22)').sort.should == [
107
+ 'mock-redis-test:regexp-key(1|22)',
108
+ ]
109
+ end
110
+ end
111
+
112
+ describe 'the + character' do
113
+ it "is treated as literal (not 'one or more' quantifier)" do
114
+ @redises.keys('mock-redis-test:regexp-key3+').sort.should == [
115
+ 'mock-redis-test:regexp-key3+',
116
+ ]
117
+ end
118
+ end
119
+
120
+ describe 'character classes ([a-c])' do
121
+ it 'specifies a range which matches any lowercase letter from "a" to "c"' do
122
+ @redises.keys('mock-redis-test:regexp-key4[a-c]').sort.should == [
123
+ 'mock-redis-test:regexp-key4a',
124
+ 'mock-redis-test:regexp-key4b',
125
+ 'mock-redis-test:regexp-key4c',
126
+ ]
127
+ end
128
+ end
129
+
130
+ describe 'combining metacharacters' do
131
+ it 'works with different metacharacters simultaneously' do
80
132
  @redises.keys('mock-redis-test:k*[12]?').sort.should == [
81
133
  'mock-redis-test:key10',
82
134
  'mock-redis-test:key20',
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#lastsave [mock only]" do
3
+ describe '#lastsave [mock only]' do
4
4
  # can't test against both since it's timing-dependent
5
- it "returns a Unix time" do
5
+ it 'returns a Unix time' do
6
6
  @redises.mock.lastsave.to_s.should =~ /^\d+$/
7
7
  end
8
8
  end
@@ -3,37 +3,47 @@ require 'spec_helper'
3
3
  describe '#lindex(key, index)' do
4
4
  before { @key = 'mock-redis-test:69312' }
5
5
 
6
- it "gets an element from the list by its index" do
6
+ it 'gets an element from the list by its index' do
7
7
  @redises.lpush(@key, 20)
8
8
  @redises.lpush(@key, 10)
9
9
 
10
- @redises.lindex(@key, 0).should == "10"
11
- @redises.lindex(@key, 1).should == "20"
10
+ @redises.lindex(@key, 0).should == '10'
11
+ @redises.lindex(@key, 1).should == '20'
12
12
  end
13
13
 
14
- it "treats negative indices as coming from the right" do
14
+ it 'treats negative indices as coming from the right' do
15
15
  @redises.lpush(@key, 20)
16
16
  @redises.lpush(@key, 10)
17
17
 
18
- @redises.lindex(@key, -1).should == "20"
19
- @redises.lindex(@key, -2).should == "10"
18
+ @redises.lindex(@key, -1).should == '20'
19
+ @redises.lindex(@key, -2).should == '10'
20
20
  end
21
21
 
22
- it "returns nil if the index is too large (and positive)" do
22
+ it 'gets an element from the list by its index when index is a string' do
23
+ @redises.lpush(@key, 20)
24
+ @redises.lpush(@key, 10)
25
+
26
+ @redises.lindex(@key, '0').should == '10'
27
+ @redises.lindex(@key, '1').should == '20'
28
+ @redises.lindex(@key, '-1').should == '20'
29
+ @redises.lindex(@key, '-2').should == '10'
30
+ end
31
+
32
+ it 'returns nil if the index is too large (and positive)' do
23
33
  @redises.lpush(@key, 20)
24
34
 
25
35
  @redises.lindex(@key, 100).should be_nil
26
36
  end
27
37
 
28
- it "returns nil if the index is too large (and negative)" do
38
+ it 'returns nil if the index is too large (and negative)' do
29
39
  @redises.lpush(@key, 20)
30
40
 
31
41
  @redises.lindex(@key, -100).should be_nil
32
42
  end
33
43
 
34
- it "returns nil for nonexistent values" do
44
+ it 'returns nil for nonexistent values' do
35
45
  @redises.lindex(@key, 0).should be_nil
36
46
  end
37
47
 
38
- it_should_behave_like "a list-only command"
48
+ it_should_behave_like 'a list-only command'
39
49
  end
@@ -1,26 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#linsert(key, :before|:after, pivot, value)" do
3
+ describe '#linsert(key, :before|:after, pivot, value)' do
4
4
  before { @key = 'mock-redis-test:48733' }
5
5
 
6
- it "returns the new size of the list when the pivot is found" do
6
+ it 'returns the new size of the list when the pivot is found' do
7
7
  @redises.lpush(@key, 'X')
8
8
 
9
9
  @redises.linsert(@key, :before, 'X', 'Y').should == 2
10
10
  @redises.lpushx(@key, 'X').should == 3
11
11
  end
12
12
 
13
- it "does nothing when run against a nonexistent key" do
13
+ it 'does nothing when run against a nonexistent key' do
14
14
  @redises.linsert(@key, :before, 1, 2).should == 0
15
15
  @redises.get(@key).should be_nil
16
16
  end
17
17
 
18
- it "returns -1 if the pivot is not found" do
18
+ it 'returns -1 if the pivot is not found' do
19
19
  @redises.lpush(@key, 1)
20
20
  @redises.linsert(@key, :after, 'X', 'Y').should == -1
21
21
  end
22
22
 
23
- it "inserts elements before the pivot when given :before as position" do
23
+ it 'inserts elements before the pivot when given :before as position' do
24
24
  @redises.lpush(@key, 'bert')
25
25
  @redises.linsert(@key, :before, 'bert', 'ernie')
26
26
 
@@ -36,33 +36,33 @@ describe "#linsert(key, :before|:after, pivot, value)" do
36
36
  @redises.lindex(@key, 1).should == 'bert'
37
37
  end
38
38
 
39
- it "inserts elements after the pivot when given :after as position" do
39
+ it 'inserts elements after the pivot when given :after as position' do
40
40
  @redises.lpush(@key, 'bert')
41
41
  @redises.linsert(@key, :after, 'bert', 'ernie')
42
-
42
+
43
43
  @redises.lindex(@key, 0).should == 'bert'
44
44
  @redises.lindex(@key, 1).should == 'ernie'
45
45
  end
46
-
46
+
47
47
  it "inserts elements after the pivot when given 'after' as position" do
48
48
  @redises.lpush(@key, 'bert')
49
49
  @redises.linsert(@key, 'after', 'bert', 'ernie')
50
-
50
+
51
51
  @redises.lindex(@key, 0).should == 'bert'
52
52
  @redises.lindex(@key, 1).should == 'ernie'
53
53
  end
54
54
 
55
- it "raises an error when given a position that is neither before nor after" do
55
+ it 'raises an error when given a position that is neither before nor after' do
56
56
  lambda do
57
57
  @redises.linsert(@key, :near, 1, 2)
58
- end.should raise_error(RuntimeError)
58
+ end.should raise_error(Redis::CommandError)
59
59
  end
60
60
 
61
- it "stores values as strings" do
61
+ it 'stores values as strings' do
62
62
  @redises.lpush(@key, 1)
63
63
  @redises.linsert(@key, :before, 1, 2)
64
- @redises.lindex(@key, 0).should == "2"
64
+ @redises.lindex(@key, 0).should == '2'
65
65
  end
66
66
 
67
- it_should_behave_like "a list-only command"
67
+ it_should_behave_like 'a list-only command'
68
68
  end
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#llen(key)" do
3
+ describe '#llen(key)' do
4
4
  before { @key = 'mock-redis-test:78407' }
5
5
 
6
- it "returns 0 for a nonexistent key" do
6
+ it 'returns 0 for a nonexistent key' do
7
7
  @redises.llen(@key).should == 0
8
8
  end
9
9
 
10
- it "returns the length of the list" do
10
+ it 'returns the length of the list' do
11
11
  5.times { @redises.lpush(@key, 'X') }
12
12
  @redises.llen(@key).should == 5
13
13
  end
14
14
 
15
- it_should_behave_like "a list-only command"
15
+ it_should_behave_like 'a list-only command'
16
16
  end
@@ -3,32 +3,32 @@ require 'spec_helper'
3
3
  describe '#lpop(key)' do
4
4
  before { @key = 'mock-redis-test:65374' }
5
5
 
6
- it "returns and removes the first element of a list" do
6
+ it 'returns and removes the first element of a list' do
7
7
  @redises.lpush(@key, 1)
8
8
  @redises.lpush(@key, 2)
9
9
 
10
- @redises.lpop(@key).should == "2"
10
+ @redises.lpop(@key).should == '2'
11
11
 
12
12
  @redises.llen(@key).should == 1
13
13
  end
14
14
 
15
- it "returns nil if the list is empty" do
15
+ it 'returns nil if the list is empty' do
16
16
  @redises.lpush(@key, 'foo')
17
17
  @redises.lpop(@key)
18
18
 
19
19
  @redises.lpop(@key).should be_nil
20
20
  end
21
21
 
22
- it "returns nil for nonexistent values" do
22
+ it 'returns nil for nonexistent values' do
23
23
  @redises.lpop(@key).should be_nil
24
24
  end
25
25
 
26
- it "removes empty lists" do
26
+ it 'removes empty lists' do
27
27
  @redises.lpush(@key, 'foo')
28
28
  @redises.lpop(@key)
29
29
 
30
30
  @redises.get(@key).should be_nil
31
31
  end
32
32
 
33
- it_should_behave_like "a list-only command"
33
+ it_should_behave_like 'a list-only command'
34
34
  end
@@ -1,37 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#lpush(key, value)" do
3
+ describe '#lpush(key, value)' do
4
4
  before { @key = 'mock-redis-test:57367' }
5
5
 
6
- it "returns the new size of the list" do
6
+ it 'returns the new size of the list' do
7
7
  @redises.lpush(@key, 'X').should == 1
8
8
  @redises.lpush(@key, 'X').should == 2
9
9
  end
10
10
 
11
- it "creates a new list when run against a nonexistent key" do
11
+ it 'creates a new list when run against a nonexistent key' do
12
12
  @redises.lpush(@key, 'value')
13
13
  @redises.llen(@key).should == 1
14
14
  end
15
15
 
16
- it "prepends items to the list" do
17
- @redises.lpush(@key, "bert")
18
- @redises.lpush(@key, "ernie")
16
+ it 'prepends items to the list' do
17
+ @redises.lpush(@key, 'bert')
18
+ @redises.lpush(@key, 'ernie')
19
19
 
20
- @redises.lindex(@key, 0).should == "ernie"
21
- @redises.lindex(@key, 1).should == "bert"
20
+ @redises.lindex(@key, 0).should == 'ernie'
21
+ @redises.lindex(@key, 1).should == 'bert'
22
22
  end
23
23
 
24
- it "stores values as strings" do
24
+ it 'stores values as strings' do
25
25
  @redises.lpush(@key, 1)
26
- @redises.lindex(@key, 0).should == "1"
26
+ @redises.lindex(@key, 0).should == '1'
27
27
  end
28
28
 
29
- it "supports a variable number of arguments" do
29
+ it 'supports a variable number of arguments' do
30
30
  @redises.lpush(@key, [1, 2, 3]).should == 3
31
- @redises.lindex(@key, 0).should == "3"
32
- @redises.lindex(@key, 1).should == "2"
33
- @redises.lindex(@key, 2).should == "1"
31
+ @redises.lindex(@key, 0).should == '3'
32
+ @redises.lindex(@key, 1).should == '2'
33
+ @redises.lindex(@key, 2).should == '1'
34
34
  end
35
35
 
36
- it_should_behave_like "a list-only command"
36
+ it 'raises an error if an empty array is given' do
37
+ lambda do
38
+ @redises.lpush(@key, [])
39
+ end.should raise_error(Redis::CommandError)
40
+ end
41
+
42
+ it_should_behave_like 'a list-only command'
37
43
  end