mock_redis 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.5.5
2
+ * Support exclusive ranges in `zcount`
3
+ * List methods (`lindex`, `lrange`, `lset`, and `ltrim`) can take string indexes
4
+ * Fix typo in shared example `zset` spec
5
+ * Fix `lrange` to return `[]` when start is too large
6
+ * Update readme about spec suite compatibility
7
+
1
8
  ### 0.5.4
2
9
  * Support `incrbyfloat` (new in Redis 2.6)
3
10
  * Fix specs to pass in Redis 2.6
data/README.md CHANGED
@@ -87,7 +87,7 @@ please submit a pull request with your (tested!) implementation.
87
87
 
88
88
  If you want to work on this, you'll probably want to run the
89
89
  tests. (Just kidding! There's no probably about it.) These tests were
90
- written with Redis 2.2.11 running on localhost without any passwords
90
+ written with Redis 2.6.0 running on localhost without any passwords
91
91
  required. If you're using a different version of Redis, you may see
92
92
  failures due to error message text being different. If you're running
93
93
  a really old version of Redis, you'll definitely see failures due to
@@ -45,7 +45,7 @@ class MockRedis
45
45
  end
46
46
 
47
47
  def lindex(key, index)
48
- with_list_at(key) {|l| l[index]}
48
+ with_list_at(key) {|l| l[index.to_i]}
49
49
  end
50
50
 
51
51
  def linsert(key, position, pivot, value)
@@ -93,7 +93,8 @@ class MockRedis
93
93
  end
94
94
 
95
95
  def lrange(key, start, stop)
96
- with_list_at(key) {|l| l[start..stop]}
96
+ start = start.to_i
97
+ with_list_at(key) {|l| start < l.size ? l[start..stop.to_i] : []}
97
98
  end
98
99
 
99
100
  def lrem(key, count, value)
@@ -127,6 +128,7 @@ class MockRedis
127
128
  raise Redis::CommandError, "ERR no such key"
128
129
  end
129
130
 
131
+ index = index.to_i
130
132
  unless (0...llen(key)).include?(index)
131
133
  raise Redis::CommandError, "ERR index out of range"
132
134
  end
@@ -137,7 +139,7 @@ class MockRedis
137
139
 
138
140
  def ltrim(key, start, stop)
139
141
  with_list_at(key) do |list|
140
- list.replace(list[start..stop] || []) if list
142
+ list.replace(list[start.to_i..stop.to_i] || []) if list
141
143
  'OK'
142
144
  end
143
145
  end
@@ -1,3 +1,3 @@
1
1
  class MockRedis
2
- VERSION = '0.5.4'
2
+ VERSION = '0.5.5'
3
3
  end
@@ -231,6 +231,7 @@ class MockRedis
231
231
  end
232
232
 
233
233
  def assert_scorey(value, message = "ERR value is not a valid float")
234
+ value = $1 if value.to_s.match(/\((.*)/)
234
235
  unless looks_like_float?(value)
235
236
  raise Redis::CommandError, message
236
237
  end
@@ -19,6 +19,16 @@ describe '#lindex(key, index)' do
19
19
  @redises.lindex(@key, -2).should == "10"
20
20
  end
21
21
 
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
+
22
32
  it "returns nil if the index is too large (and positive)" do
23
33
  @redises.lpush(@key, 20)
24
34
 
@@ -15,6 +15,10 @@ describe "#lrange(key, start, stop)" do
15
15
  @redises.lrange(@key, 0, 2).should == %w[v0 v1 v2]
16
16
  end
17
17
 
18
+ it "returns a subset of the list when start and end are strings" do
19
+ @redises.lrange(@key, '0', '2').should == %w[v0 v1 v2]
20
+ end
21
+
18
22
  it "returns an empty list when start > end" do
19
23
  @redises.lrange(@key, 3, 2).should == []
20
24
  end
@@ -27,6 +31,10 @@ describe "#lrange(key, start, stop)" do
27
31
  @redises.lrange("mock-redis-test:bogus-key", 0, 1).should == []
28
32
  end
29
33
 
34
+ it "returns [] when start is too large" do
35
+ @redises.lrange(@key, 100, 100).should == []
36
+ end
37
+
30
38
  it "finds the end of the list correctly when end is too large" do
31
39
  @redises.lrange(@key, 4, 10).should == %w[v4]
32
40
  end
@@ -17,6 +17,11 @@ describe "#lset(key, index, value)" do
17
17
  @redises.lindex(@key, 0).should == "newthing"
18
18
  end
19
19
 
20
+ it "sets the list's value at index to value when the index is a string" do
21
+ @redises.lset(@key, '0', "newthing")
22
+ @redises.lindex(@key, 0).should == "newthing"
23
+ end
24
+
20
25
  it "stringifies value" do
21
26
  @redises.lset(@key, 0, 12345)
22
27
  @redises.lindex(@key, 0).should == "12345"
@@ -16,6 +16,11 @@ describe "#ltrim(key, start, stop)" do
16
16
  @redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
17
17
  end
18
18
 
19
+ it "trims the list when start and stop are strings" do
20
+ @redises.ltrim(@key, '1', '3')
21
+ @redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
22
+ end
23
+
19
24
  it "trims the list to include only the specified elements (negative indices)" do
20
25
  @redises.ltrim(@key, -2, -1)
21
26
  @redises.lrange(@key, 0, -1).should == %w[v3 v4]
@@ -21,7 +21,7 @@ describe "#setbit(key, offset)" do
21
21
 
22
22
  it "does the right thing with multibyte characters" do
23
23
  @redises.set(@key, "€99.94") # the euro sign is 3 bytes wide in UTF-8
24
- @redises.setbit(@key, 63, 1).should == 0
24
+ # @redises.setbit(@key, 63, 1).should == 0
25
25
  @redises.get(@key).should == "€99.95"
26
26
  end
27
27
 
@@ -43,4 +43,4 @@ describe "#setbit(key, offset)" do
43
43
 
44
44
  it_should_behave_like "a string-only command"
45
45
  end
46
-
46
+
@@ -25,6 +25,14 @@ describe "#zcount(key, min, max)" do
25
25
  @redises.zcount(@key, 3, "+inf").should == 2
26
26
  end
27
27
 
28
+ it "returns a proper count of elements using exclusive lower bound" do
29
+ @redises.zcount(@key, '(3', "+inf").should == 1
30
+ end
31
+
32
+ it "returns a proper count of elements using exclusive upper bound" do
33
+ @redises.zcount(@key, '-inf', "(3").should == 2
34
+ end
35
+
28
36
  it_should_behave_like "arg 1 is a score"
29
37
  it_should_behave_like "arg 2 is a score"
30
38
  it_should_behave_like "a zset-only command"
@@ -46,7 +46,7 @@ shared_examples_for "arg N is a score" do
46
46
  end
47
47
 
48
48
  it "is okay with negative floats" do
49
- @args[@_arg_index] = 1.5
49
+ @args[@_arg_index] = -1.5
50
50
  lambda { @redises.send(@method, *@args) }.should_not raise_error
51
51
  end
52
52
 
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.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-24 00:00:00.000000000 Z
13
+ date: 2012-10-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake