mock_redis 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- data/spec/cloning_spec.rb +17 -18
- data/spec/commands/append_spec.rb +4 -4
- data/spec/commands/auth_spec.rb +1 -1
- data/spec/commands/bgrewriteaof_spec.rb +2 -2
- data/spec/commands/bgsave_spec.rb +2 -2
- data/spec/commands/bitcount_spec.rb +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
data/spec/commands/info_spec.rb
CHANGED
@@ -3,60 +3,60 @@ require 'spec_helper'
|
|
3
3
|
describe '#info [mock only]' do
|
4
4
|
let(:redis) { @redises.mock }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'responds with a config hash' do
|
7
7
|
redis.info.should be_a(Hash)
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'gets default set of info' do
|
11
11
|
info = redis.info
|
12
|
-
info[
|
13
|
-
info[
|
14
|
-
info[
|
15
|
-
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
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'gets all info' do
|
19
19
|
info = redis.info(:all)
|
20
|
-
info[
|
21
|
-
info[
|
22
|
-
info[
|
23
|
-
info[
|
24
|
-
info[
|
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
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
redis.info(:server)[
|
27
|
+
it 'gets server info' do
|
28
|
+
redis.info(:server)['arch_bits'].should be_a(String)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
redis.info(:clients)[
|
31
|
+
it 'gets clients info' do
|
32
|
+
redis.info(:clients)['connected_clients'].should be_a(String)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
redis.info(:memory)[
|
35
|
+
it 'gets memory info' do
|
36
|
+
redis.info(:memory)['used_memory'].should be_a(String)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
redis.info(:persistence)[
|
39
|
+
it 'gets persistence info' do
|
40
|
+
redis.info(:persistence)['aof_rewrite_scheduled'].should be_a(String)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
redis.info(:stats)[
|
43
|
+
it 'gets stats info' do
|
44
|
+
redis.info(:stats)['keyspace_hits'].should be_a(String)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
redis.info(:replication)[
|
47
|
+
it 'gets replication info' do
|
48
|
+
redis.info(:replication)['role'].should be_a(String)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
redis.info(:cpu)[
|
51
|
+
it 'gets cpu info' do
|
52
|
+
redis.info(:cpu)['used_cpu_sys'].should be_a(String)
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
56
|
-
redis.info(:keyspace)[
|
55
|
+
it 'gets keyspace info' do
|
56
|
+
redis.info(:keyspace)['db0'].should be_a(String)
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
redis.info(:commandstats)[
|
59
|
+
it 'gets commandstats info' do
|
60
|
+
redis.info(:commandstats)['sunionstore']['usec'].should be_a(String)
|
61
61
|
end
|
62
62
|
end
|
data/spec/commands/keys_spec.rb
CHANGED
@@ -1,48 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe '#keys()' do
|
4
|
-
|
5
|
-
|
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
|
10
|
-
@redises.keys(
|
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
|
12
|
+
describe 'with pattern matching' do
|
14
13
|
before do
|
15
|
-
@redises.set(
|
16
|
-
@redises.set(
|
17
|
-
@redises.set(
|
18
|
-
@redises.set(
|
19
|
-
@redises.set(
|
20
|
-
@redises.set(
|
21
|
-
@redises.set(
|
22
|
-
|
23
|
-
@redises.set(
|
24
|
-
@redises.set(
|
25
|
-
@redises.set(
|
26
|
-
@redises.set(
|
27
|
-
@redises.set(
|
28
|
-
@redises.set(
|
29
|
-
@redises.set(
|
30
|
-
|
31
|
-
@redises.set(
|
32
|
-
@redises.set(
|
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')
|
33
32
|
end
|
34
33
|
|
35
|
-
describe
|
36
|
-
it
|
37
|
-
@redises.keys(
|
34
|
+
describe 'the ? character' do
|
35
|
+
it 'is treated as a single character (at the end of the pattern)' do
|
36
|
+
@redises.keys('mock-redis-test:key?').sort.should == [
|
38
37
|
'mock-redis-test:key1',
|
39
38
|
'mock-redis-test:key2',
|
40
39
|
'mock-redis-test:key3',
|
41
40
|
]
|
42
41
|
end
|
43
42
|
|
44
|
-
it
|
45
|
-
@redises.keys(
|
43
|
+
it 'is treated as a single character (in the middle of the pattern)' do
|
44
|
+
@redises.keys('mock-redis-test:key?0').sort.should == [
|
46
45
|
'mock-redis-test:key10',
|
47
46
|
'mock-redis-test:key20',
|
48
47
|
'mock-redis-test:key30',
|
@@ -51,14 +50,14 @@ describe '#keys()' do
|
|
51
50
|
|
52
51
|
it "treats \? as a literal ?" do
|
53
52
|
@redises.keys('mock-redis-test:special-key\?').sort.should == [
|
54
|
-
'mock-redis-test:special-key?'
|
53
|
+
'mock-redis-test:special-key?',
|
55
54
|
]
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
59
|
-
describe
|
60
|
-
it
|
61
|
-
@redises.keys(
|
58
|
+
describe 'the * character' do
|
59
|
+
it 'is treated as 0 or more characters' do
|
60
|
+
@redises.keys('mock-redis-test:key*').sort.should == [
|
62
61
|
'mock-redis-test:key',
|
63
62
|
'mock-redis-test:key1',
|
64
63
|
'mock-redis-test:key10',
|
@@ -71,13 +70,13 @@ describe '#keys()' do
|
|
71
70
|
|
72
71
|
it "treats \* as a literal *" do
|
73
72
|
@redises.keys('mock-redis-test:special-key\*').sort.should == [
|
74
|
-
'mock-redis-test:special-key*'
|
73
|
+
'mock-redis-test:special-key*',
|
75
74
|
]
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
79
|
-
describe
|
80
|
-
it
|
78
|
+
describe 'character classes ([abcde])' do
|
79
|
+
it 'matches any one of those characters' do
|
81
80
|
@redises.keys('mock-redis-test:key[12]').sort.should == [
|
82
81
|
'mock-redis-test:key1',
|
83
82
|
'mock-redis-test:key2',
|
@@ -85,23 +84,23 @@ describe '#keys()' do
|
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
|
-
describe
|
87
|
+
describe 'the | character' do
|
89
88
|
it "is treated as literal (not 'or')" do
|
90
89
|
@redises.keys('mock-redis-test:regexp-key(1|22)').sort.should == [
|
91
|
-
'mock-redis-test:regexp-key(1|22)'
|
90
|
+
'mock-redis-test:regexp-key(1|22)',
|
92
91
|
]
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
96
|
-
describe
|
95
|
+
describe 'the + character' do
|
97
96
|
it "is treated as literal (not 'one or more' quantifier)" do
|
98
97
|
@redises.keys('mock-redis-test:regexp-key3+').sort.should == [
|
99
|
-
'mock-redis-test:regexp-key3+'
|
98
|
+
'mock-redis-test:regexp-key3+',
|
100
99
|
]
|
101
100
|
end
|
102
101
|
end
|
103
102
|
|
104
|
-
describe
|
103
|
+
describe 'character classes ([a-c])' do
|
105
104
|
it "specifies a range which matches any lowercase letter from \"a\" to \"c\"" do
|
106
105
|
@redises.keys('mock-redis-test:regexp-key4[a-c]').sort.should == [
|
107
106
|
'mock-redis-test:regexp-key4a',
|
@@ -111,8 +110,8 @@ describe '#keys()' do
|
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
114
|
-
describe
|
115
|
-
it
|
113
|
+
describe 'combining metacharacters' do
|
114
|
+
it 'works with different metacharacters simultaneously' do
|
116
115
|
@redises.keys('mock-redis-test:k*[12]?').sort.should == [
|
117
116
|
'mock-redis-test:key10',
|
118
117
|
'mock-redis-test:key20',
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#lastsave [mock only]' do
|
4
4
|
# can't test against both since it's timing-dependent
|
5
|
-
it
|
5
|
+
it 'returns a Unix time' do
|
6
6
|
@redises.mock.lastsave.to_s.should =~ /^\d+$/
|
7
7
|
end
|
8
8
|
end
|
@@ -3,47 +3,47 @@ require 'spec_helper'
|
|
3
3
|
describe '#lindex(key, index)' do
|
4
4
|
before { @key = 'mock-redis-test:69312' }
|
5
5
|
|
6
|
-
it
|
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 ==
|
11
|
-
@redises.lindex(@key, 1).should ==
|
10
|
+
@redises.lindex(@key, 0).should == '10'
|
11
|
+
@redises.lindex(@key, 1).should == '20'
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
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 ==
|
19
|
-
@redises.lindex(@key, -2).should ==
|
18
|
+
@redises.lindex(@key, -1).should == '20'
|
19
|
+
@redises.lindex(@key, -2).should == '10'
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'gets an element from the list by its index when index is a string' do
|
23
23
|
@redises.lpush(@key, 20)
|
24
24
|
@redises.lpush(@key, 10)
|
25
25
|
|
26
|
-
@redises.lindex(@key, '0').should ==
|
27
|
-
@redises.lindex(@key, '1').should ==
|
28
|
-
@redises.lindex(@key, '-1').should ==
|
29
|
-
@redises.lindex(@key, '-2').should ==
|
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
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'returns nil if the index is too large (and positive)' do
|
33
33
|
@redises.lpush(@key, 20)
|
34
34
|
|
35
35
|
@redises.lindex(@key, 100).should be_nil
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it 'returns nil if the index is too large (and negative)' do
|
39
39
|
@redises.lpush(@key, 20)
|
40
40
|
|
41
41
|
@redises.lindex(@key, -100).should be_nil
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'returns nil for nonexistent values' do
|
45
45
|
@redises.lindex(@key, 0).should be_nil
|
46
46
|
end
|
47
47
|
|
48
|
-
it_should_behave_like
|
48
|
+
it_should_behave_like 'a list-only command'
|
49
49
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#linsert(key, :before|:after, pivot, value)' do
|
4
4
|
before { @key = 'mock-redis-test:48733' }
|
5
5
|
|
6
|
-
it
|
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
|
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
|
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
|
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
|
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
|
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
58
|
end.should raise_error(RuntimeError)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
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 ==
|
64
|
+
@redises.lindex(@key, 0).should == '2'
|
65
65
|
end
|
66
66
|
|
67
|
-
it_should_behave_like
|
67
|
+
it_should_behave_like 'a list-only command'
|
68
68
|
end
|
data/spec/commands/llen_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#llen(key)' do
|
4
4
|
before { @key = 'mock-redis-test:78407' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns 0 for a nonexistent key' do
|
7
7
|
@redises.llen(@key).should == 0
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
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
|
15
|
+
it_should_behave_like 'a list-only command'
|
16
16
|
end
|
data/spec/commands/lpop_spec.rb
CHANGED
@@ -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
|
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 ==
|
10
|
+
@redises.lpop(@key).should == '2'
|
11
11
|
|
12
12
|
@redises.llen(@key).should == 1
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
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
|
22
|
+
it 'returns nil for nonexistent values' do
|
23
23
|
@redises.lpop(@key).should be_nil
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
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
|
33
|
+
it_should_behave_like 'a list-only command'
|
34
34
|
end
|