mock_redis 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c44bae9b73824aa1ed4b8a5e745d45f1b511dab
4
- data.tar.gz: b055a6c704f08fba3ba9910bf75b953ec2bb4a1f
3
+ metadata.gz: 8a63181a124183a90e68a84d2aaa16957e47398e
4
+ data.tar.gz: a633c58b9b8eabe402eeb593bfb72fe83e36f069
5
5
  SHA512:
6
- metadata.gz: 247bdc2430fad048264a198fc2d023b08df49e89ba2563693bc4b131cbf675079499236f8cd4e9c3bfc3a6c720bc400a0427722b6faf4d8abf2ac5ee097f34f0
7
- data.tar.gz: 20d485098a4c0b402c18addd39fa68d949068e3cade53e35b850f84ad1d262e44b64de72c8a83337ec5c4eace639c014fcaa875ad515f709da7beaad9a313d47
6
+ metadata.gz: 41f515662a87bb3a51d2c1f8f5f9f92a0d3d93f9a909a30eb89b03a6a7a454b64d136cb2c3286217e45e9b64252bcd3bc177bae52655f1ad0f8aa773cdaa2b7f
7
+ data.tar.gz: f262b7fc4dcf2cfe0a6a44017521a8962ba4769899d65271214a6d909a5aca17f3cbe628b7811d22678e69b014f632d2bc2705032158aebe91f6964b7c768ec4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.13.0
4
+
5
+ * Fix bug where SETBIT command would not correctly unset a bit
6
+ * Add support for the `connect` method
7
+ * Check that `min`/`max` parameters are floats in `zrangebyscore`,
8
+ `zremrangebyscore`, and `zrevrangebyscore`
9
+ * Update blocking list commands to take `timeout` in an options hash
10
+ for compatibility with `redis-rb` >= 3.0.0
11
+
3
12
  ### 0.12.1
4
13
 
5
14
  * RENAME command now keeps key expiration
data/lib/mock_redis.rb CHANGED
@@ -71,6 +71,10 @@ class MockRedis
71
71
  self
72
72
  end
73
73
 
74
+ def connect
75
+ self
76
+ end
77
+
74
78
  def reconnect
75
79
  self
76
80
  end
@@ -210,8 +210,8 @@ class MockRedis
210
210
  private
211
211
 
212
212
  def assert_valid_timeout(timeout)
213
- if !looks_like_float?(timeout.to_s)
214
- raise Redis::CommandError, "ERR timeout is not a float or out of range"
213
+ if !looks_like_integer?(timeout.to_s)
214
+ raise Redis::CommandError, "ERR timeout is not an integer or out of range"
215
215
  elsif timeout < 0
216
216
  raise Redis::CommandError, "ERR timeout is negative"
217
217
  end
@@ -227,8 +227,13 @@ class MockRedis
227
227
  end
228
228
 
229
229
  def extract_timeout(arglist)
230
- timeout = assert_valid_timeout(arglist.last)
231
- [arglist[0..-2], arglist.last]
230
+ options = arglist.last
231
+ if options.is_a?(Hash) && options[:timeout]
232
+ timeout = assert_valid_timeout(options[:timeout])
233
+ [arglist[0..-2], timeout]
234
+ else
235
+ [arglist, 0]
236
+ end
232
237
  end
233
238
 
234
239
  def expiration(key)
@@ -32,7 +32,8 @@ class MockRedis
32
32
  end
33
33
  end
34
34
 
35
- def brpoplpush(source, destination, timeout)
35
+ def brpoplpush(source, destination, options = {})
36
+ timeout = options.is_a?(Hash) && options[:timeout] || 0
36
37
  assert_valid_timeout(timeout)
37
38
 
38
39
  if llen(source) > 0
@@ -199,7 +199,7 @@ class MockRedis
199
199
  char_as_number = char.each_byte.reduce(0) do |a, byte|
200
200
  (a << 8) + byte
201
201
  end
202
- char_as_number |=
202
+ char_as_number ^=
203
203
  (2**((char.bytesize * 8)-1) >>
204
204
  (offset_within_char * 8 + offset_within_byte))
205
205
  str[char_index] = char_as_number.chr
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  class MockRedis
3
- VERSION = '0.12.1'
3
+ VERSION = '0.13.0'
4
4
  end
@@ -67,6 +67,9 @@ class MockRedis
67
67
  end
68
68
 
69
69
  def zrangebyscore(key, min, max, options={})
70
+ assert_scorey(min, 'ERR min or max is not a float') unless min == '-inf'
71
+ assert_scorey(max, 'ERR min or max is not a float') unless max == '+inf'
72
+
70
73
  with_zset_at(key) do |zset|
71
74
  all_results = zset.in_range(min, max)
72
75
  to_response(apply_limit(all_results, options[:limit]), options)
@@ -104,12 +107,18 @@ class MockRedis
104
107
  end
105
108
 
106
109
  def zremrangebyscore(key, min, max)
110
+ assert_scorey(min, 'ERR min or max is not a float') unless min == '-inf'
111
+ assert_scorey(max, 'ERR min or max is not a float') unless max == '+inf'
112
+
107
113
  zrangebyscore(key, min, max).
108
114
  each {|member| zrem(key, member)}.
109
115
  size
110
116
  end
111
117
 
112
118
  def zrevrangebyscore(key, max, min, options={})
119
+ assert_scorey(min, 'ERR min or max is not a float') unless min == '-inf'
120
+ assert_scorey(max, 'ERR min or max is not a float') unless max == '+inf'
121
+
113
122
  with_zset_at(key) do |zset|
114
123
  to_response(
115
124
  apply_limit(
data/spec/client_spec.rb CHANGED
@@ -7,4 +7,11 @@ describe 'client' do
7
7
  redis.reconnect.should == redis
8
8
  end
9
9
  end
10
+
11
+ context '#connect' do
12
+ it 'connects' do
13
+ redis = MockRedis.new
14
+ redis.connect.should == redis
15
+ end
16
+ end
10
17
  end
@@ -12,30 +12,30 @@ describe '#blpop(key [, key, ...,], timeout)' do
12
12
  end
13
13
 
14
14
  it "returns [first-nonempty-list, popped-value]" do
15
- @redises.blpop(@list1, @list2, 1).should == [@list1, 'one']
15
+ @redises.blpop(@list1, @list2).should == [@list1, 'one']
16
16
  end
17
17
 
18
18
  it "pops that value off the list" do
19
- @redises.blpop(@list1, @list2, 1)
20
- @redises.blpop(@list1, @list2, 1)
19
+ @redises.blpop(@list1, @list2)
20
+ @redises.blpop(@list1, @list2)
21
21
 
22
- @redises.blpop(@list1, @list2, 1).should == [@list2, 'ten']
22
+ @redises.blpop(@list1, @list2).should == [@list2, 'ten']
23
23
  end
24
24
 
25
25
  it "ignores empty keys" do
26
- @redises.blpop('mock-redis-test:not-here', @list1, 1).should ==
26
+ @redises.blpop('mock-redis-test:not-here', @list1).should ==
27
27
  [@list1, 'one']
28
28
  end
29
29
 
30
- it "allows subsecond timeouts" do
30
+ it "raises an error on subsecond timeouts" do
31
31
  lambda do
32
- @redises.blpop(@list1, @list2, 0.5)
33
- end.should_not raise_error
32
+ @redises.blpop(@list1, @list2, :timeout => 0.5)
33
+ end.should raise_error(Redis::CommandError)
34
34
  end
35
35
 
36
36
  it "raises an error on negative timeout" do
37
37
  lambda do
38
- @redises.blpop(@list1, @list2, -1)
38
+ @redises.blpop(@list1, @list2, :timeout => -1)
39
39
  end.should raise_error(Redis::CommandError)
40
40
  end
41
41
 
@@ -43,12 +43,12 @@ describe '#blpop(key [, key, ...,], timeout)' do
43
43
 
44
44
  context "[mock only]" do
45
45
  it "ignores positive timeouts and returns nil" do
46
- @redises.mock.blpop('mock-redis-test:not-here', 1).should be_nil
46
+ @redises.mock.blpop('mock-redis-test:not-here', :timeout => 1).should be_nil
47
47
  end
48
48
 
49
49
  it "raises WouldBlock on zero timeout (no blocking in the mock)" do
50
50
  lambda do
51
- @redises.mock.blpop('mock-redis-test:not-here', 0)
51
+ @redises.mock.blpop('mock-redis-test:not-here', :timeout => 0)
52
52
  end.should raise_error(MockRedis::WouldBlock)
53
53
  end
54
54
  end
@@ -12,29 +12,29 @@ describe '#brpop(key [, key, ...,], timeout)' do
12
12
  end
13
13
 
14
14
  it "returns [first-nonempty-list, popped-value]" do
15
- @redises.brpop(@list1, @list2, 1).should == [@list1, 'two']
15
+ @redises.brpop(@list1, @list2).should == [@list1, 'two']
16
16
  end
17
17
 
18
18
  it "pops that value off the list" do
19
- @redises.brpop(@list1, @list2, 1)
20
- @redises.brpop(@list1, @list2, 1)
21
- @redises.brpop(@list1, @list2, 1).should == [@list2, 'ten']
19
+ @redises.brpop(@list1, @list2)
20
+ @redises.brpop(@list1, @list2)
21
+ @redises.brpop(@list1, @list2).should == [@list2, 'ten']
22
22
  end
23
23
 
24
24
  it "ignores empty keys" do
25
- @redises.brpop('mock-redis-test:not-here', @list1, 1).should ==
25
+ @redises.brpop('mock-redis-test:not-here', @list1).should ==
26
26
  [@list1, 'two']
27
27
  end
28
28
 
29
- it "allows subsecond timeouts" do
29
+ it "raises an error on subsecond timeouts" do
30
30
  lambda do
31
- @redises.brpop(@list1, @list2, 0.5)
32
- end.should_not raise_error
31
+ @redises.brpop(@list1, @list2, :timeout => 0.5)
32
+ end.should raise_error(Redis::CommandError)
33
33
  end
34
34
 
35
35
  it "raises an error on negative timeout" do
36
36
  lambda do
37
- @redises.brpop(@list1, @list2, -1)
37
+ @redises.brpop(@list1, @list2, :timeout => -1)
38
38
  end.should raise_error(Redis::CommandError)
39
39
  end
40
40
 
@@ -42,12 +42,12 @@ describe '#brpop(key [, key, ...,], timeout)' do
42
42
 
43
43
  context "[mock only]" do
44
44
  it "ignores positive timeouts and returns nil" do
45
- @redises.mock.brpop('mock-redis-test:not-here', 1).should be_nil
45
+ @redises.mock.brpop('mock-redis-test:not-here', :timeout => 1).should be_nil
46
46
  end
47
47
 
48
48
  it "raises WouldBlock on zero timeout (no blocking in the mock)" do
49
49
  lambda do
50
- @redises.mock.brpop('mock-redis-test:not-here', 0)
50
+ @redises.mock.brpop('mock-redis-test:not-here', :timeout => 0)
51
51
  end.should raise_error(MockRedis::WouldBlock)
52
52
  end
53
53
  end
@@ -15,18 +15,18 @@ describe '#brpoplpush(source, destination, timeout)' do
15
15
  end
16
16
 
17
17
  it "takes the last element of source and prepends it to destination" do
18
- @redises.brpoplpush(@list1, @list2, 0)
18
+ @redises.brpoplpush(@list1, @list2)
19
19
  @redises.lrange(@list1, 0, -1).should == %w[A]
20
20
  @redises.lrange(@list2, 0, -1).should == %w[B alpha beta]
21
21
  end
22
22
 
23
23
  it "returns the moved element" do
24
- @redises.brpoplpush(@list1, @list2, 0).should == "B"
24
+ @redises.brpoplpush(@list1, @list2).should == "B"
25
25
  end
26
26
 
27
27
  it "raises an error on negative timeout" do
28
28
  lambda do
29
- @redises.brpoplpush(@list1, @list2, -1)
29
+ @redises.brpoplpush(@list1, @list2, :timeout => -1)
30
30
  end.should raise_error(Redis::CommandError)
31
31
  end
32
32
 
@@ -34,13 +34,13 @@ describe '#brpoplpush(source, destination, timeout)' do
34
34
 
35
35
  context "[mock only]" do
36
36
  it "ignores positive timeouts and returns nil" do
37
- @redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 1).
37
+ @redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 1).
38
38
  should be_nil
39
39
  end
40
40
 
41
41
  it "raises WouldBlock on zero timeout (no blocking in the mock)" do
42
42
  lambda do
43
- @redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 0)
43
+ @redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 0)
44
44
  end.should raise_error(MockRedis::WouldBlock)
45
45
  end
46
46
  end
@@ -13,12 +13,15 @@ describe "#setbit(key, offset)" do
13
13
  end
14
14
 
15
15
  it "sets the bit within the string" do
16
- $debug = true
17
16
  @redises.setbit(@key, 7, 1)
18
- $debug = false
19
17
  @redises.get(@key).should == 'i' # ASCII 0x69
20
18
  end
21
19
 
20
+ it "unsets the bit within the string" do
21
+ @redises.setbit(@key, 1, 0)
22
+ @redises.get(@key).should == '(' # ASCII 0x28
23
+ end
24
+
22
25
  it "does the right thing with multibyte characters" do
23
26
  @redises.set(@key, "€99.94") # the euro sign is 3 bytes wide in UTF-8
24
27
  @redises.setbit(@key, 63, 1).should == 0
@@ -43,4 +46,3 @@ describe "#setbit(key, offset)" do
43
46
 
44
47
  it_should_behave_like "a string-only command"
45
48
  end
46
-
@@ -25,4 +25,8 @@ describe "#zremrangebyscore(key, min, max)" do
25
25
  end
26
26
 
27
27
  it_should_behave_like "a zset-only command"
28
+
29
+ it "throws a command error" do
30
+ expect { @redises.zrevrangebyscore(@key, DateTime.now, '-inf') }.to raise_error(Redis::CommandError)
31
+ end
28
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-14 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -387,4 +387,3 @@ test_files:
387
387
  - spec/support/shared_examples/only_operates_on_zsets.rb
388
388
  - spec/support/shared_examples/sorts_enumerables.rb
389
389
  - spec/transactions_spec.rb
390
- has_rdoc: