mock_redis 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.overcommit.yml +1 -1
  4. data/.rubocop.yml +91 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +14 -2
  7. data/CHANGELOG.md +4 -0
  8. data/Gemfile +4 -2
  9. data/README.md +1 -0
  10. data/Rakefile +2 -2
  11. data/lib/mock_redis.rb +25 -26
  12. data/lib/mock_redis/assertions.rb +0 -1
  13. data/lib/mock_redis/database.rb +35 -28
  14. data/lib/mock_redis/expire_wrapper.rb +1 -1
  15. data/lib/mock_redis/future.rb +1 -1
  16. data/lib/mock_redis/hash_methods.rb +18 -17
  17. data/lib/mock_redis/indifferent_hash.rb +4 -0
  18. data/lib/mock_redis/info_method.rb +109 -108
  19. data/lib/mock_redis/list_methods.rb +17 -16
  20. data/lib/mock_redis/multi_db_wrapper.rb +5 -4
  21. data/lib/mock_redis/pipelined_wrapper.rb +3 -3
  22. data/lib/mock_redis/set_methods.rb +10 -9
  23. data/lib/mock_redis/sort_method.rb +11 -12
  24. data/lib/mock_redis/string_methods.rb +26 -29
  25. data/lib/mock_redis/transaction_wrapper.rb +7 -8
  26. data/lib/mock_redis/utility_methods.rb +9 -12
  27. data/lib/mock_redis/version.rb +1 -1
  28. data/lib/mock_redis/zset.rb +22 -23
  29. data/lib/mock_redis/zset_methods.rb +25 -25
  30. data/spec/cloning_spec.rb +17 -18
  31. data/spec/commands/append_spec.rb +4 -4
  32. data/spec/commands/auth_spec.rb +1 -1
  33. data/spec/commands/bgrewriteaof_spec.rb +2 -2
  34. data/spec/commands/bgsave_spec.rb +2 -2
  35. data/spec/commands/bitcount_spec.rb +3 -3
  36. data/spec/commands/blpop_spec.rb +10 -10
  37. data/spec/commands/brpop_spec.rb +10 -10
  38. data/spec/commands/brpoplpush_spec.rb +9 -9
  39. data/spec/commands/connected_spec.rb +2 -2
  40. data/spec/commands/dbsize_spec.rb +3 -3
  41. data/spec/commands/decr_spec.rb +7 -7
  42. data/spec/commands/decrby_spec.rb +7 -7
  43. data/spec/commands/del_spec.rb +4 -4
  44. data/spec/commands/disconnect_spec.rb +2 -2
  45. data/spec/commands/echo_spec.rb +4 -4
  46. data/spec/commands/exists_spec.rb +3 -3
  47. data/spec/commands/expire_spec.rb +13 -13
  48. data/spec/commands/expireat_spec.rb +6 -7
  49. data/spec/commands/flushall_spec.rb +5 -5
  50. data/spec/commands/flushdb_spec.rb +5 -5
  51. data/spec/commands/future_spec.rb +2 -2
  52. data/spec/commands/get_spec.rb +7 -7
  53. data/spec/commands/getbit_spec.rb +6 -6
  54. data/spec/commands/getrange_spec.rb +9 -9
  55. data/spec/commands/getset_spec.rb +7 -7
  56. data/spec/commands/hash_operator_spec.rb +5 -5
  57. data/spec/commands/hdel_spec.rb +12 -12
  58. data/spec/commands/hexists_spec.rb +7 -7
  59. data/spec/commands/hget_spec.rb +7 -7
  60. data/spec/commands/hgetall_spec.rb +6 -6
  61. data/spec/commands/hincrby_spec.rb +14 -14
  62. data/spec/commands/hincrbyfloat_spec.rb +14 -14
  63. data/spec/commands/hkeys_spec.rb +5 -5
  64. data/spec/commands/hlen_spec.rb +5 -5
  65. data/spec/commands/hmget_spec.rb +8 -8
  66. data/spec/commands/hmset_spec.rb +10 -10
  67. data/spec/commands/hset_spec.rb +11 -11
  68. data/spec/commands/hsetnx_spec.rb +14 -14
  69. data/spec/commands/hvals_spec.rb +5 -5
  70. data/spec/commands/incr_spec.rb +7 -7
  71. data/spec/commands/incrby_spec.rb +11 -11
  72. data/spec/commands/incrbyfloat_spec.rb +11 -11
  73. data/spec/commands/info_spec.rb +30 -30
  74. data/spec/commands/keys_spec.rb +42 -43
  75. data/spec/commands/lastsave_spec.rb +2 -2
  76. data/spec/commands/lindex_spec.rb +15 -15
  77. data/spec/commands/linsert_spec.rb +13 -13
  78. data/spec/commands/llen_spec.rb +4 -4
  79. data/spec/commands/lpop_spec.rb +6 -6
  80. data/spec/commands/lpush_spec.rb +16 -16
  81. data/spec/commands/lpushx_spec.rb +13 -13
  82. data/spec/commands/lrange_spec.rb +12 -12
  83. data/spec/commands/lrem_spec.rb +15 -15
  84. data/spec/commands/lset_spec.rb +12 -12
  85. data/spec/commands/ltrim_spec.rb +9 -9
  86. data/spec/commands/mapped_hmget_spec.rb +8 -8
  87. data/spec/commands/mapped_hmset_spec.rb +12 -12
  88. data/spec/commands/mapped_mget_spec.rb +4 -4
  89. data/spec/commands/mapped_mset_spec.rb +1 -1
  90. data/spec/commands/mget_spec.rb +11 -11
  91. data/spec/commands/move_spec.rb +29 -29
  92. data/spec/commands/mset_spec.rb +4 -4
  93. data/spec/commands/msetnx_spec.rb +10 -10
  94. data/spec/commands/persist_spec.rb +9 -10
  95. data/spec/commands/pexpire_spec.rb +12 -13
  96. data/spec/commands/pexpireat_spec.rb +6 -6
  97. data/spec/commands/ping_spec.rb +1 -1
  98. data/spec/commands/pipelined_spec.rb +5 -5
  99. data/spec/commands/pttl_spec.rb +5 -5
  100. data/spec/commands/randomkey_spec.rb +3 -3
  101. data/spec/commands/rename_spec.rb +9 -9
  102. data/spec/commands/renamenx_spec.rb +10 -10
  103. data/spec/commands/rpop_spec.rb +6 -6
  104. data/spec/commands/rpoplpush_spec.rb +7 -7
  105. data/spec/commands/rpush_spec.rb +16 -16
  106. data/spec/commands/rpushx_spec.rb +13 -13
  107. data/spec/commands/sadd_spec.rb +8 -9
  108. data/spec/commands/scan_spec.rb +6 -7
  109. data/spec/commands/scard_spec.rb +3 -3
  110. data/spec/commands/sdiff_spec.rb +10 -10
  111. data/spec/commands/sdiffstore_spec.rb +10 -10
  112. data/spec/commands/select_spec.rb +7 -7
  113. data/spec/commands/setbit_spec.rb +13 -13
  114. data/spec/commands/setex_spec.rb +4 -4
  115. data/spec/commands/setnx_spec.rb +4 -4
  116. data/spec/commands/setrange_spec.rb +12 -12
  117. data/spec/commands/sinter_spec.rb +8 -10
  118. data/spec/commands/sinterstore_spec.rb +9 -9
  119. data/spec/commands/sismember_spec.rb +5 -5
  120. data/spec/commands/smembers_spec.rb +5 -5
  121. data/spec/commands/smove_spec.rb +7 -7
  122. data/spec/commands/sort_list_spec.rb +3 -3
  123. data/spec/commands/sort_set_spec.rb +3 -3
  124. data/spec/commands/sort_zset_spec.rb +3 -3
  125. data/spec/commands/spop_spec.rb +4 -4
  126. data/spec/commands/srandmember_spec.rb +8 -8
  127. data/spec/commands/srem_spec.rb +9 -9
  128. data/spec/commands/strlen_spec.rb +4 -4
  129. data/spec/commands/sunion_spec.rb +7 -9
  130. data/spec/commands/sunionstore_spec.rb +9 -9
  131. data/spec/commands/ttl_spec.rb +5 -5
  132. data/spec/commands/type_spec.rb +1 -1
  133. data/spec/commands/zadd_spec.rb +10 -10
  134. data/spec/commands/zcard_spec.rb +4 -4
  135. data/spec/commands/zcount_spec.rb +14 -14
  136. data/spec/commands/zincrby_spec.rb +6 -6
  137. data/spec/commands/zinterstore_spec.rb +17 -17
  138. data/spec/commands/zrange_spec.rb +12 -12
  139. data/spec/commands/zrangebyscore_spec.rb +26 -26
  140. data/spec/commands/zrank_spec.rb +4 -4
  141. data/spec/commands/zrem_spec.rb +9 -9
  142. data/spec/commands/zremrangebyrank_spec.rb +5 -5
  143. data/spec/commands/zremrangebyscore_spec.rb +9 -7
  144. data/spec/commands/zrevrange_spec.rb +10 -10
  145. data/spec/commands/zrevrangebyscore_spec.rb +14 -14
  146. data/spec/commands/zrevrank_spec.rb +4 -4
  147. data/spec/commands/zscore_spec.rb +5 -5
  148. data/spec/commands/zunionstore_spec.rb +18 -18
  149. data/spec/mock_redis_spec.rb +11 -1
  150. data/spec/spec_helper.rb +13 -4
  151. data/spec/support/redis_multiplexer.rb +39 -31
  152. data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
  153. data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
  154. data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
  155. data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
  156. data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
  157. data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
  158. data/spec/transactions_spec.rb +18 -18
  159. metadata +5 -3
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'date'
3
3
 
4
- describe "#zremrangebyscore(key, min, max)" do
4
+ describe '#zremrangebyscore(key, min, max)' do
5
5
  before do
6
6
  @key = 'mock-redis-test:zremrangebyscore'
7
7
  @redises.zadd(@key, 1, 'Washington')
@@ -10,24 +10,26 @@ describe "#zremrangebyscore(key, min, max)" do
10
10
  @redises.zadd(@key, 4, 'Madison')
11
11
  end
12
12
 
13
- it "returns the number of elements in range" do
13
+ it 'returns the number of elements in range' do
14
14
  @redises.zremrangebyscore(@key, 2, 3).should == 2
15
15
  end
16
16
 
17
- it "removes the elements" do
17
+ it 'removes the elements' do
18
18
  @redises.zremrangebyscore(@key, 2, 3)
19
19
  @redises.zrange(@key, 0, -1).should == %w[Washington Madison]
20
20
  end
21
21
 
22
22
  # As seen in http://redis.io/commands/zremrangebyscore
23
- it "removes the elements for complex statements" do
23
+ it 'removes the elements for complex statements' do
24
24
  @redises.zremrangebyscore(@key, '-inf', '(4')
25
25
  @redises.zrange(@key, 0, -1).should == %w[Madison]
26
26
  end
27
27
 
28
- it_should_behave_like "a zset-only command"
28
+ it_should_behave_like 'a zset-only command'
29
29
 
30
- it "throws a command error" do
31
- expect { @redises.zrevrangebyscore(@key, DateTime.now, '-inf') }.to raise_error(Redis::CommandError)
30
+ it 'throws a command error' do
31
+ expect do
32
+ @redises.zrevrangebyscore(@key, DateTime.now, '-inf')
33
+ end.to raise_error(Redis::CommandError)
32
34
  end
33
35
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrevrange(key, start, stop [, :with_scores => true])" do
3
+ describe '#zrevrange(key, start, stop [, :with_scores => true])' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrevrange'
6
6
  @redises.zadd(@key, 1, 'Washington')
@@ -20,27 +20,27 @@ describe "#zrevrange(key, start, stop [, :with_scores => true])" do
20
20
  end
21
21
  end
22
22
 
23
- it "returns the elements in order by score" do
24
- @redises.zrevrange(@key, 0, 1).should == ['Madison', 'Jefferson']
23
+ it 'returns the elements in order by score' do
24
+ @redises.zrevrange(@key, 0, 1).should == %w[Madison Jefferson]
25
25
  end
26
26
 
27
- it "returns the elements in order by score (negative indices)" do
28
- @redises.zrevrange(@key, -2, -1).should == ['Adams', 'Washington']
27
+ it 'returns the elements in order by score (negative indices)' do
28
+ @redises.zrevrange(@key, -2, -1).should == %w[Adams Washington]
29
29
  end
30
30
 
31
31
  it 'returns empty list when start is too large' do
32
32
  @redises.zrevrange(@key, 5, -1).should == []
33
33
  end
34
34
 
35
- it "returns the scores when :with_scores is specified" do
35
+ it 'returns the scores when :with_scores is specified' do
36
36
  @redises.zrevrange(@key, 2, 3, :with_scores => true).
37
- should == [["Adams", 2.0], ["Washington", 1.0]]
37
+ should == [['Adams', 2.0], ['Washington', 1.0]]
38
38
  end
39
39
 
40
- it "returns the scores when :withscores is specified" do
40
+ it 'returns the scores when :withscores is specified' do
41
41
  @redises.zrevrange(@key, 2, 3, :withscores => true).
42
- should == [["Adams", 2.0], ["Washington", 1.0]]
42
+ should == [['Adams', 2.0], ['Washington', 1.0]]
43
43
  end
44
44
 
45
- it_should_behave_like "a zset-only command"
45
+ it_should_behave_like 'a zset-only command'
46
46
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])" do
3
+ describe '#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrevrangebyscore'
6
6
  @redises.zadd(@key, 1, 'Washington')
@@ -20,28 +20,28 @@ describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [
20
20
  end
21
21
  end
22
22
 
23
- it "returns the elements in order by score" do
24
- @redises.zrevrangebyscore(@key, 4, 3).should == ['Madison', 'Jefferson']
23
+ it 'returns the elements in order by score' do
24
+ @redises.zrevrangebyscore(@key, 4, 3).should == %w[Madison Jefferson]
25
25
  end
26
26
 
27
- it "returns the scores when :with_scores is specified" do
27
+ it 'returns the scores when :with_scores is specified' do
28
28
  @redises.zrevrangebyscore(@key, 4, 3, :with_scores => true).
29
- should == [["Madison", 4.0], ["Jefferson", 3.0]]
29
+ should == [['Madison', 4.0], ['Jefferson', 3.0]]
30
30
  end
31
31
 
32
- it "returns the scores when :withscores is specified" do
32
+ it 'returns the scores when :withscores is specified' do
33
33
  @redises.zrevrangebyscore(@key, 4, 3, :withscores => true).
34
- should == [["Madison", 4.0], ["Jefferson", 3.0]]
34
+ should == [['Madison', 4.0], ['Jefferson', 3.0]]
35
35
  end
36
36
 
37
- it "treats +inf as positive infinity" do
38
- @redises.zrevrangebyscore(@key, "+inf", 3).
37
+ it 'treats +inf as positive infinity' do
38
+ @redises.zrevrangebyscore(@key, '+inf', 3).
39
39
  should == %w[Madison Jefferson]
40
40
  end
41
41
 
42
- it "honors the :limit => [offset count] argument" do
42
+ it 'honors the :limit => [offset count] argument' do
43
43
  @redises.zrevrangebyscore(@key, 100, -100, :limit => [1, 2]).
44
- should == ["Jefferson", "Adams"]
44
+ should == %w[Jefferson Adams]
45
45
  end
46
46
 
47
47
  it "raises an error if :limit isn't a 2-tuple" do
@@ -50,9 +50,9 @@ describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [
50
50
  end.should raise_error(RuntimeError)
51
51
 
52
52
  lambda do
53
- @redises.zrevrangebyscore(@key, 100, -100, :limit => "1, 2")
54
- end.should raise_error
53
+ @redises.zrevrangebyscore(@key, 100, -100, :limit => '1, 2')
54
+ end.should raise_error(RedisMultiplexer::MismatchedResponse)
55
55
  end
56
56
 
57
- it_should_behave_like "a zset-only command"
57
+ it_should_behave_like 'a zset-only command'
58
58
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zrevrank(key, member)" do
3
+ describe '#zrevrank(key, member)' do
4
4
  before do
5
5
  @key = 'mock-redis-test:zrevrank'
6
6
 
@@ -13,17 +13,17 @@ describe "#zrevrank(key, member)" do
13
13
  @redises.zrevrank(@key, 'foo').should be_nil
14
14
  end
15
15
 
16
- it "returns the index of the member in the set (ordered by -score)" do
16
+ it 'returns the index of the member in the set (ordered by -score)' do
17
17
  @redises.zrevrank(@key, 'one').should == 2
18
18
  @redises.zrevrank(@key, 'two').should == 1
19
19
  @redises.zrevrank(@key, 'three').should == 0
20
20
  end
21
21
 
22
- it "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.zrevrank(@key, member).should == 0
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,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zscore(key, member)" do
3
+ describe '#zscore(key, member)' do
4
4
  before { @key = 'mock-redis-test:zscore' }
5
5
 
6
- it "returns the score as a string" do
6
+ it 'returns the score as a string' do
7
7
  @redises.zadd(@key, 0.25, 'foo').should == true
8
8
  @redises.zscore(@key, 'foo').should == 0.25
9
9
  end
10
10
 
11
- it "handles integer members correctly" do
11
+ it 'handles integer members correctly' do
12
12
  member = 11
13
13
  @redises.zadd(@key, 0.25, member).should == true
14
14
  @redises.zscore(@key, member).should == 0.25
15
15
  end
16
16
 
17
- it "returns nil if member is not present in the set" do
17
+ it 'returns nil if member is not present in the set' do
18
18
  @redises.zscore(@key, 'foo').should be_nil
19
19
  end
20
20
 
21
- it_should_behave_like "a zset-only command"
21
+ it_should_behave_like 'a zset-only command'
22
22
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])" do
3
+ describe '#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])' do
4
4
  before do
5
5
  @set1 = 'mock-redis-test:zunionstore1'
6
6
  @set2 = 'mock-redis-test:zunionstore2'
@@ -17,45 +17,45 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
17
17
  @redises.zadd(@set3, 3, 'three')
18
18
  end
19
19
 
20
- it "returns the number of elements in the new set" do
20
+ it 'returns the number of elements in the new set' do
21
21
  @redises.zunionstore(@dest, [@set1, @set2, @set3]).should == 3
22
22
  end
23
23
 
24
24
  it "sums the members' scores by default" do
25
25
  @redises.zunionstore(@dest, [@set1, @set2, @set3])
26
26
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
27
- [["one", 3.0], ["three", 3.0], ["two", 4.0]]
27
+ [['one', 3.0], ['three', 3.0], ['two', 4.0]]
28
28
  end
29
29
 
30
- it "removes existing elements in destination" do
30
+ it 'removes existing elements in destination' do
31
31
  @redises.zadd(@dest, 10, 'ten')
32
32
 
33
33
  @redises.zunionstore(@dest, [@set1])
34
34
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
35
- [["one", 1.0]]
35
+ [['one', 1.0]]
36
36
  end
37
37
 
38
- it "raises an error if keys is empty" do
38
+ it 'raises an error if keys is empty' do
39
39
  lambda do
40
40
  @redises.zunionstore(@dest, [])
41
41
  end.should raise_error(RuntimeError)
42
42
  end
43
43
 
44
- context "the :weights argument" do
45
- it "multiplies the scores by the weights while aggregating" do
44
+ context 'the :weights argument' do
45
+ it 'multiplies the scores by the weights while aggregating' do
46
46
  @redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [2, 3, 5])
47
47
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
48
- [["one", 10.0], ["three", 15.0], ["two", 16.0]]
48
+ [['one', 10.0], ['three', 15.0], ['two', 16.0]]
49
49
  end
50
50
 
51
- it "raises an error if the number of weights != the number of keys" do
51
+ it 'raises an error if the number of weights != the number of keys' do
52
52
  lambda do
53
- @redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [1,2])
53
+ @redises.zunionstore(@dest, [@set1, @set2, @set3], :weights => [1, 2])
54
54
  end.should raise_error(RuntimeError)
55
55
  end
56
56
  end
57
57
 
58
- context "the :aggregate argument" do
58
+ context 'the :aggregate argument' do
59
59
  before do
60
60
  @smalls = 'mock-redis-test:zunionstore:smalls'
61
61
  @bigs = 'mock-redis-test:zunionstore:bigs'
@@ -66,19 +66,19 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
66
66
  @redises.zadd(@bigs, 200, 'ernie')
67
67
  end
68
68
 
69
- it "aggregates scores with min when :aggregate => :min is specified" do
69
+ it 'aggregates scores with min when :aggregate => :min is specified' do
70
70
  @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :min)
71
71
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
72
- [["bert", 1.0], ["ernie", 2.0]]
72
+ [['bert', 1.0], ['ernie', 2.0]]
73
73
  end
74
74
 
75
- it "aggregates scores with max when :aggregate => :max is specified" do
75
+ it 'aggregates scores with max when :aggregate => :max is specified' do
76
76
  @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :max)
77
77
  @redises.zrange(@dest, 0, -1, :with_scores => true).should ==
78
- [["bert", 100.0], ["ernie", 200.0]]
78
+ [['bert', 100.0], ['ernie', 200.0]]
79
79
  end
80
80
 
81
- it "ignores scores for missing members" do
81
+ it 'ignores scores for missing members' do
82
82
  @redises.zadd(@smalls, 3, 'grover')
83
83
  @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :min)
84
84
  @redises.zscore(@dest, 'grover').should == 3.0
@@ -95,7 +95,7 @@ describe "#zunionstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
95
95
  @redises.zscore(@dest, 'bert').should == 1.0
96
96
  end
97
97
 
98
- it "raises an error for unknown aggregation function" do
98
+ it 'raises an error for unknown aggregation function' do
99
99
  lambda do
100
100
  @redises.zunionstore(@dest, [@bigs, @smalls], :aggregate => :mix)
101
101
  end.should raise_error(RuntimeError)
@@ -58,11 +58,21 @@ describe MockRedis do
58
58
  its(:now) { should == now }
59
59
  end
60
60
 
61
+ describe '.time' do
62
+ let(:now) { 'Now' }
63
+ let(:time_stub) { double 'Time', :now => now }
64
+ let(:options) { { :time_class => time_stub } }
65
+
66
+ subject { MockRedis.new(options) }
67
+
68
+ its(:time) { should == now }
69
+ end
70
+
61
71
  describe '.expireat' do
62
72
  let(:time_at) { 'expireat' }
63
73
  let(:time_stub) { double 'Time' }
64
74
  let(:options) { { :time_class => time_stub } }
65
- let(:timestamp) { 123456 }
75
+ let(:timestamp) { 123_456 }
66
76
 
67
77
  subject { MockRedis.new(options) }
68
78
 
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,20 @@
1
- require 'rspec'
1
+ if ENV['TRAVIS']
2
+ # When running in Travis, report coverage stats to Coveralls.
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ else
6
+ # Otherwise render coverage information in coverage/index.html and display
7
+ # coverage percentage in the console.
8
+ require 'simplecov'
9
+ end
10
+
2
11
  require 'rspec/its'
3
12
  require 'redis'
4
- $LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, "..", "..", "lib")))
13
+ $LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, '..', '..', 'lib')))
5
14
  require 'mock_redis'
6
15
 
7
16
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
8
- Dir["spec/support/**/*.rb"].each {|x| require x}
17
+ Dir['spec/support/**/*.rb'].each { |x| require x }
9
18
 
10
19
  module TypeCheckingHelper
11
20
  def method_from_description(example)
@@ -45,7 +54,7 @@ RSpec.configure do |config|
45
54
  # databases mentioned in our tests
46
55
  [1, 0].each do |db|
47
56
  @redises.send_without_checking(:select, db)
48
- @redises.send_without_checking(:keys, "mock-redis-test:*").each do |key|
57
+ @redises.send_without_checking(:keys, 'mock-redis-test:*').each do |key|
49
58
  @redises.send_without_checking(:del, key)
50
59
  end
51
60
  end
@@ -1,5 +1,7 @@
1
1
  class BlankSlate
2
- instance_methods.each {|m| undef_method(m) unless m =~ /^__/ || ['inspect', 'object_id'].include?(m.to_s)}
2
+ instance_methods.each do |m|
3
+ undef_method(m) unless m =~ /^__/ || %w[inspect object_id].include?(m.to_s)
4
+ end
3
5
  end
4
6
 
5
7
  class RedisMultiplexer < BlankSlate
@@ -11,50 +13,54 @@ class RedisMultiplexer < BlankSlate
11
13
  end
12
14
 
13
15
  def method_missing(method, *args, &blk)
14
- # if we're in a Redis command that accepts a block, and we execute more redis commands, ONLY execute them
15
- # on the Redis implementation that the block came from.
16
- # e.g. if a pipelined command is started on a MockRedis object, DON'T send commands inside the pipelined block
17
- # to the real Redis object, as that one WON'T be inside a pipelined command, and we'll see weird behaviour
16
+ # If we're in a Redis command that accepts a block, and we execute more
17
+ # redis commands, ONLY execute them on the Redis implementation that the
18
+ # block came from.
19
+ # e.g. if a pipelined command is started on a MockRedis object, DON'T send
20
+ # commands inside the pipelined block to the real Redis object, as that one
21
+ # WON'T be inside a pipelined command, and we'll see weird behaviour
18
22
  if blk
19
23
  @in_mock_block = false
20
24
  @in_redis_block = true
21
25
  end
22
- real_retval, real_error = catch_errors { @in_mock_block ? :no_op : @real_redis.send(method, *args, &blk) }
26
+ real_retval, real_error =
27
+ catch_errors { @in_mock_block ? :no_op : @real_redis.send(method, *args, &blk) }
23
28
 
24
29
  if blk
25
30
  @in_mock_block = true
26
31
  @in_redis_block = false
27
32
  end
28
- mock_retval, mock_error = catch_errors { @in_redis_block ? :no_op : @mock_redis.send(method, *args, &blk) }
33
+ mock_retval, mock_error =
34
+ catch_errors { @in_redis_block ? :no_op : @mock_redis.send(method, *args, &blk) }
29
35
 
30
36
  if blk
31
37
  @in_mock_block = false
32
38
  @in_redis_block = false
33
39
  end
34
40
 
35
- if (mock_retval == :no_op || real_retval == :no_op)
36
- # ignore, we were inside a block (like pipelined)
37
- elsif (!equalish?(mock_retval, real_retval) && !mock_error && !real_error)
41
+ if mock_retval == :no_op || real_retval == :no_op
42
+ # ignore, we were inside a block (like pipelined)
43
+ elsif !equalish?(mock_retval, real_retval) && !mock_error && !real_error
38
44
  # no exceptions, just different behavior
39
45
  raise MismatchedResponse,
40
- "Mock failure: responses not equal.\n" +
41
- "Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" +
46
+ "Mock failure: responses not equal.\n" \
47
+ "Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" \
42
48
  "MockRedis.#{method}(#{args.inspect}) returned #{mock_retval.inspect}\n"
43
- elsif (!mock_error && real_error)
49
+ elsif !mock_error && real_error
44
50
  raise MismatchedResponse,
45
- "Mock failure: didn't raise an error when it should have.\n" +
46
- "Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" +
47
- "MockRedis.#{method}(#{args.inspect}) raised nothing " +
51
+ "Mock failure: didn't raise an error when it should have.\n" \
52
+ "Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" \
53
+ "MockRedis.#{method}(#{args.inspect}) raised nothing " \
48
54
  "and returned #{mock_retval.inspect}"
49
- elsif (!real_error && mock_error)
55
+ elsif !real_error && mock_error
50
56
  raise MismatchedResponse,
51
- "Mock failure: raised an error when it shouldn't have.\n" +
52
- "Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" +
57
+ "Mock failure: raised an error when it shouldn't have.\n" \
58
+ "Redis.#{method}(#{args.inspect}) returned #{real_retval.inspect}\n" \
53
59
  "MockRedis.#{method}(#{args.inspect}) raised #{mock_error.inspect}"
54
- elsif (mock_error && real_error && !equalish?(mock_error, real_error))
60
+ elsif mock_error && real_error && !equalish?(mock_error, real_error)
55
61
  raise MismatchedResponse,
56
- "Mock failure: raised the wrong error.\n" +
57
- "Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" +
62
+ "Mock failure: raised the wrong error.\n" \
63
+ "Redis.#{method}(#{args.inspect}) raised #{real_error.inspect}\n" \
58
64
  "MockRedis.#{method}(#{args.inspect}) raised #{mock_error.inspect}"
59
65
  end
60
66
 
@@ -77,8 +83,13 @@ class RedisMultiplexer < BlankSlate
77
83
  end
78
84
  end
79
85
 
80
- def mock() @mock_redis end
81
- def real() @real_redis end
86
+ def mock
87
+ @mock_redis
88
+ end
89
+
90
+ def real
91
+ @real_redis
92
+ end
82
93
 
83
94
  # Used in cleanup before() blocks.
84
95
  def send_without_checking(method, *args)
@@ -87,12 +98,9 @@ class RedisMultiplexer < BlankSlate
87
98
  end
88
99
 
89
100
  def catch_errors
90
- begin
91
- retval = yield
92
- [retval, nil]
93
- rescue StandardError => e
94
- [nil, e]
95
- end
101
+ retval = yield
102
+ [retval, nil]
103
+ rescue StandardError => e
104
+ [nil, e]
96
105
  end
97
106
  end
98
-