redis-namespace 1.5.3 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/redis_spec.rb CHANGED
@@ -3,49 +3,60 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  describe "redis" do
6
- @redis_version = Gem::Version.new(Redis.current.info["redis_version"])
6
+ @redis_version = Gem::Version.new(Redis.new.info["redis_version"])
7
+ let(:redis_client) { @redis.respond_to?(:_client) ? @redis._client : @redis.client}
7
8
 
8
- before(:all) do
9
+ before(:each) do
9
10
  # use database 15 for testing so we dont accidentally step on your real data
10
11
  @redis = Redis.new :db => 15
11
- end
12
-
13
- before(:each) do
14
- @namespaced = Redis::Namespace.new(:ns, :redis => @redis)
15
12
  @redis.flushdb
16
- @redis['foo'] = 'bar'
13
+ @namespaced = Redis::Namespace.new(:ns, :redis => @redis)
14
+ @redis.set('foo', 'bar')
17
15
  end
18
16
 
19
- after(:each) do
20
- @redis.flushdb
17
+ # redis-rb 3.3.4+
18
+ it "should inject :namespace into connection info" do
19
+ info = @redis.connection.merge(:namespace => :ns)
20
+ expect(@namespaced.connection).to eq(info)
21
21
  end
22
22
 
23
- after(:all) do
24
- @redis.quit
23
+ it "proxies `client` to the _client and deprecated" do
24
+ expect(@namespaced.client).to eq(redis_client)
25
25
  end
26
26
 
27
- it "proxies `client` to the client" do
28
- @namespaced.client.should eq(@redis.client)
27
+ it "proxies `_client` to the _client" do
28
+ expect(@namespaced._client).to eq(redis_client)
29
29
  end
30
30
 
31
31
  it "should be able to use a namespace" do
32
- @namespaced['foo'].should eq(nil)
33
- @namespaced['foo'] = 'chris'
34
- @namespaced['foo'].should eq('chris')
35
- @redis['foo'] = 'bob'
36
- @redis['foo'].should eq('bob')
32
+ expect(@namespaced.get('foo')).to eq(nil)
33
+ @namespaced.set('foo', 'chris')
34
+ expect(@namespaced.get('foo')).to eq('chris')
35
+ @redis.set('foo', 'bob')
36
+ expect(@redis.get('foo')).to eq('bob')
37
37
 
38
38
  @namespaced.incrby('counter', 2)
39
- @namespaced['counter'].to_i.should eq(2)
40
- @redis['counter'].should eq(nil)
41
- @namespaced.type('counter').should eq('string')
39
+ expect(@namespaced.get('counter').to_i).to eq(2)
40
+ expect(@redis.get('counter')).to eq(nil)
41
+ expect(@namespaced.type('counter')).to eq('string')
42
+ end
43
+
44
+ it "should work with Proc namespaces" do
45
+ namespace = Proc.new { :dynamic_ns }
46
+ namespaced = Redis::Namespace.new(namespace, redis: @redis)
47
+
48
+ expect(namespaced.get('foo')).to eq(nil)
49
+ namespaced.set('foo', 'chris')
50
+ expect(namespaced.get('foo')).to eq('chris')
51
+ @redis.set('foo', 'bob')
52
+ expect(@redis.get('foo')).to eq('bob')
42
53
  end
43
54
 
44
55
  context 'when sending capital commands (issue 68)' do
45
56
  it 'should be able to use a namespace' do
46
57
  @namespaced.send('SET', 'fubar', 'quux')
47
- @redis.get('fubar').should be_nil
48
- @namespaced.get('fubar').should eq 'quux'
58
+ expect(@redis.get('fubar')).to be_nil
59
+ expect(@namespaced.get('fubar')).to eq 'quux'
49
60
  end
50
61
  end
51
62
 
@@ -53,136 +64,179 @@ describe "redis" do
53
64
  @namespaced.rpush "foo", "string"
54
65
  @namespaced.rpush "foo", "ns:string"
55
66
  @namespaced.rpush "foo", "string_no_timeout"
56
- @namespaced.blpop("foo", 1).should eq(["foo", "string"])
57
- @namespaced.blpop("foo", 1).should eq(["foo", "ns:string"])
58
- @namespaced.blpop("foo").should eq(["foo", "string_no_timeout"])
59
- @namespaced.blpop("foo", 1).should eq(nil)
67
+ expect(@namespaced.blpop("foo", 1)).to eq(["foo", "string"])
68
+ expect(@namespaced.blpop("foo", 1)).to eq(["foo", "ns:string"])
69
+ expect(@namespaced.blpop("foo")).to eq(["foo", "string_no_timeout"])
70
+ expect(@namespaced.blpop("foo", 1)).to eq(nil)
60
71
  end
61
72
 
62
73
  it "should be able to use a namespace with del" do
63
- @namespaced['foo'] = 1000
64
- @namespaced['bar'] = 2000
65
- @namespaced['baz'] = 3000
74
+ @namespaced.set('foo', 1000)
75
+ @namespaced.set('bar', 2000)
76
+ @namespaced.set('baz', 3000)
66
77
  @namespaced.del 'foo'
67
- @namespaced['foo'].should eq(nil)
78
+ expect(@namespaced.get('foo')).to eq(nil)
68
79
  @namespaced.del 'bar', 'baz'
69
- @namespaced['bar'].should eq(nil)
70
- @namespaced['baz'].should eq(nil)
80
+ expect(@namespaced.get('bar')).to eq(nil)
81
+ expect(@namespaced.get('baz')).to eq(nil)
82
+ end
83
+
84
+ it "should be able to use a namespace with unlink" do
85
+ @namespaced.set('foo', 1000)
86
+ @namespaced.set('bar', 2000)
87
+ @namespaced.set('baz', 3000)
88
+ @namespaced.unlink 'foo'
89
+ expect(@namespaced.get('foo')).to eq(nil)
90
+ @namespaced.unlink 'bar', 'baz'
91
+ expect(@namespaced.get('bar')).to eq(nil)
92
+ expect(@namespaced.get('baz')).to eq(nil)
71
93
  end
72
94
 
73
95
  it 'should be able to use a namespace with append' do
74
- @namespaced['foo'] = 'bar'
75
- @namespaced.append('foo','n').should eq(4)
76
- @namespaced['foo'].should eq('barn')
77
- @redis['foo'].should eq('bar')
96
+ @namespaced.set('foo', 'bar')
97
+ expect(@namespaced.append('foo','n')).to eq(4)
98
+ expect(@namespaced.get('foo')).to eq('barn')
99
+ expect(@redis.get('foo')).to eq('bar')
78
100
  end
79
101
 
80
102
  it 'should be able to use a namespace with brpoplpush' do
81
103
  @namespaced.lpush('foo','bar')
82
- @namespaced.brpoplpush('foo','bar',0).should eq('bar')
83
- @namespaced.lrange('foo',0,-1).should eq([])
84
- @namespaced.lrange('bar',0,-1).should eq(['bar'])
104
+ expect(@namespaced.brpoplpush('foo','bar',0)).to eq('bar')
105
+ expect(@namespaced.lrange('foo',0,-1)).to eq([])
106
+ expect(@namespaced.lrange('bar',0,-1)).to eq(['bar'])
107
+ end
108
+
109
+ it "should be able to use a namespace with getex" do
110
+ expect(@namespaced.set('mykey', 'Hello')).to eq('OK')
111
+ expect(@namespaced.getex('mykey', ex: 50)).to eq('Hello')
112
+ expect(@namespaced.get('mykey')).to eq('Hello')
113
+ expect(@namespaced.ttl('mykey')).to eq(50)
85
114
  end
86
115
 
87
116
  it 'should be able to use a namespace with getbit' do
88
117
  @namespaced.set('foo','bar')
89
- @namespaced.getbit('foo',1).should eq(1)
118
+ expect(@namespaced.getbit('foo',1)).to eq(1)
90
119
  end
91
120
 
92
121
  it 'should be able to use a namespace with getrange' do
93
122
  @namespaced.set('foo','bar')
94
- @namespaced.getrange('foo',0,-1).should eq('bar')
123
+ expect(@namespaced.getrange('foo',0,-1)).to eq('bar')
95
124
  end
96
125
 
97
126
  it 'should be able to use a namespace with linsert' do
98
127
  @namespaced.rpush('foo','bar')
99
128
  @namespaced.rpush('foo','barn')
100
129
  @namespaced.rpush('foo','bart')
101
- @namespaced.linsert('foo','BEFORE','barn','barf').should eq(4)
102
- @namespaced.lrange('foo',0,-1).should eq(['bar','barf','barn','bart'])
130
+ expect(@namespaced.linsert('foo','BEFORE','barn','barf')).to eq(4)
131
+ expect(@namespaced.lrange('foo',0,-1)).to eq(['bar','barf','barn','bart'])
103
132
  end
104
133
 
105
134
  it 'should be able to use a namespace with lpushx' do
106
- @namespaced.lpushx('foo','bar').should eq(0)
135
+ expect(@namespaced.lpushx('foo','bar')).to eq(0)
107
136
  @namespaced.lpush('foo','boo')
108
- @namespaced.lpushx('foo','bar').should eq(2)
109
- @namespaced.lrange('foo',0,-1).should eq(['bar','boo'])
137
+ expect(@namespaced.lpushx('foo','bar')).to eq(2)
138
+ expect(@namespaced.lrange('foo',0,-1)).to eq(['bar','boo'])
110
139
  end
111
140
 
112
141
  it 'should be able to use a namespace with rpushx' do
113
- @namespaced.rpushx('foo','bar').should eq(0)
142
+ expect(@namespaced.rpushx('foo','bar')).to eq(0)
114
143
  @namespaced.lpush('foo','boo')
115
- @namespaced.rpushx('foo','bar').should eq(2)
116
- @namespaced.lrange('foo',0,-1).should eq(['boo','bar'])
144
+ expect(@namespaced.rpushx('foo','bar')).to eq(2)
145
+ expect(@namespaced.lrange('foo',0,-1)).to eq(['boo','bar'])
117
146
  end
118
147
 
119
148
  it 'should be able to use a namespace with setbit' do
120
149
  @namespaced.setbit('virgin_key', 1, 1)
121
- @namespaced.exists('virgin_key').should be_true
122
- @namespaced.get('virgin_key').should eq(@namespaced.getrange('virgin_key',0,-1))
150
+ expect(@namespaced.exists?('virgin_key')).to be true
151
+ expect(@namespaced.get('virgin_key')).to eq(@namespaced.getrange('virgin_key',0,-1))
152
+ end
153
+
154
+ it 'should be able to use a namespace with exists' do
155
+ @namespaced.set('foo', 1000)
156
+ @namespaced.set('bar', 2000)
157
+ expect(@namespaced.exists('foo', 'bar')).to eq(2)
158
+ end
159
+
160
+ it 'should be able to use a namespace with exists?' do
161
+ @namespaced.set('foo', 1000)
162
+ @namespaced.set('bar', 2000)
163
+ expect(@namespaced.exists?('does_not_exist', 'bar')).to eq(true)
164
+ end
165
+
166
+ it 'should be able to use a namespace with bitpos' do
167
+ @namespaced.setbit('bit_map', 42, 1)
168
+ expect(@namespaced.bitpos('bit_map', 0)).to eq(0)
169
+ expect(@namespaced.bitpos('bit_map', 1)).to eq(42)
123
170
  end
124
171
 
125
172
  it 'should be able to use a namespace with setrange' do
126
173
  @namespaced.setrange('foo', 0, 'bar')
127
- @namespaced['foo'].should eq('bar')
174
+ expect(@namespaced.get('foo')).to eq('bar')
128
175
 
129
176
  @namespaced.setrange('bar', 2, 'foo')
130
- @namespaced['bar'].should eq("\000\000foo")
177
+ expect(@namespaced.get('bar')).to eq("\000\000foo")
131
178
  end
132
179
 
133
180
  it "should be able to use a namespace with mget" do
134
- @namespaced['foo'] = 1000
135
- @namespaced['bar'] = 2000
136
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000' })
137
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
181
+ @namespaced.set('foo', 1000)
182
+ @namespaced.set('bar', 2000)
183
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
184
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
138
185
  end
139
186
 
140
187
  it "should be able to use a namespace with mset" do
141
188
  @namespaced.mset('foo', '1000', 'bar', '2000')
142
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000' })
143
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
189
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
190
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
191
+
144
192
  @namespaced.mapped_mset('foo' => '3000', 'bar' => '5000')
145
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '3000', 'bar' => '5000' })
146
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
193
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000' })
194
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
195
+
196
+ @namespaced.mset(['foo', '4000'], ['baz', '6000'])
197
+ expect(@namespaced.mapped_mget('foo', 'bar', 'baz')).to eq({ 'foo' => '4000', 'bar' => '5000', 'baz' => '6000' })
147
198
  end
148
199
 
149
200
  it "should be able to use a namespace with msetnx" do
150
201
  @namespaced.msetnx('foo', '1000', 'bar', '2000')
151
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000' })
152
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
202
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
203
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
204
+
205
+ @namespaced.msetnx(['baz', '4000'])
206
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => '4000'})
153
207
  end
154
208
 
155
209
  it "should be able to use a namespace with mapped_msetnx" do
156
210
  @namespaced.set('foo','1')
157
- @namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000').should be_false
158
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1', 'bar' => nil })
159
- @namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000').should be_true
160
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1', 'bar' => '2000' })
211
+ expect(@namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000')).to be false
212
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1', 'bar' => nil })
213
+ expect(@namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000')).to be true
214
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1', 'bar' => '2000' })
161
215
  end
162
216
 
163
217
  it "should be able to use a namespace with hashes" do
164
218
  @namespaced.hset('foo', 'key', 'value')
165
219
  @namespaced.hset('foo', 'key1', 'value1')
166
- @namespaced.hget('foo', 'key').should eq('value')
167
- @namespaced.hgetall('foo').should eq({'key' => 'value', 'key1' => 'value1'})
168
- @namespaced.hlen('foo').should eq(2)
169
- @namespaced.hkeys('foo').should eq(['key', 'key1'])
220
+ expect(@namespaced.hget('foo', 'key')).to eq('value')
221
+ expect(@namespaced.hgetall('foo')).to eq({'key' => 'value', 'key1' => 'value1'})
222
+ expect(@namespaced.hlen('foo')).to eq(2)
223
+ expect(@namespaced.hkeys('foo')).to eq(['key', 'key1'])
170
224
  @namespaced.hmset('bar', 'key', 'value', 'key1', 'value1')
171
225
  @namespaced.hmget('bar', 'key', 'key1')
172
226
  @namespaced.hmset('bar', 'a_number', 1)
173
- @namespaced.hmget('bar', 'a_number').should eq(['1'])
227
+ expect(@namespaced.hmget('bar', 'a_number')).to eq(['1'])
174
228
  @namespaced.hincrby('bar', 'a_number', 3)
175
- @namespaced.hmget('bar', 'a_number').should eq(['4'])
176
- @namespaced.hgetall('bar').should eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
177
-
178
- @namespaced.hsetnx('foonx','nx',10).should be_true
179
- @namespaced.hsetnx('foonx','nx',12).should be_false
180
- @namespaced.hget('foonx','nx').should eq("10")
181
- @namespaced.hkeys('foonx').should eq(%w{ nx })
182
- @namespaced.hvals('foonx').should eq(%w{ 10 })
229
+ expect(@namespaced.hmget('bar', 'a_number')).to eq(['4'])
230
+ expect(@namespaced.hgetall('bar')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
231
+
232
+ expect(@namespaced.hsetnx('foonx','nx',10)).to be true
233
+ expect(@namespaced.hsetnx('foonx','nx',12)).to be false
234
+ expect(@namespaced.hget('foonx','nx')).to eq("10")
235
+ expect(@namespaced.hkeys('foonx')).to eq(%w{ nx })
236
+ expect(@namespaced.hvals('foonx')).to eq(%w{ 10 })
183
237
  @namespaced.mapped_hmset('baz', {'key' => 'value', 'key1' => 'value1', 'a_number' => 4})
184
- @namespaced.mapped_hmget('baz', 'key', 'key1', 'a_number').should eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
185
- @namespaced.hgetall('baz').should eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
238
+ expect(@namespaced.mapped_hmget('baz', 'key', 'key1', 'a_number')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
239
+ expect(@namespaced.hgetall('baz')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
186
240
  end
187
241
 
188
242
  it "should properly intersect three sets" do
@@ -193,7 +247,7 @@ describe "redis" do
193
247
  @namespaced.sadd('bar', 3)
194
248
  @namespaced.sadd('bar', 4)
195
249
  @namespaced.sadd('baz', 3)
196
- @namespaced.sinter('foo', 'bar', 'baz').should eq(%w( 3 ))
250
+ expect(@namespaced.sinter('foo', 'bar', 'baz')).to eq(%w( 3 ))
197
251
  end
198
252
 
199
253
  it "should properly union two sets" do
@@ -202,7 +256,7 @@ describe "redis" do
202
256
  @namespaced.sadd('bar', 2)
203
257
  @namespaced.sadd('bar', 3)
204
258
  @namespaced.sadd('bar', 4)
205
- @namespaced.sunion('foo', 'bar').sort.should eq(%w( 1 2 3 4 ))
259
+ expect(@namespaced.sunion('foo', 'bar').sort).to eq(%w( 1 2 3 4 ))
206
260
  end
207
261
 
208
262
  it "should properly union two sorted sets with options" do
@@ -211,8 +265,8 @@ describe "redis" do
211
265
  @namespaced.zadd('sort2', 2, 2)
212
266
  @namespaced.zadd('sort2', 3, 3)
213
267
  @namespaced.zadd('sort2', 4, 4)
214
- @namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1])
215
- @namespaced.zrevrange('union', 0, -1).should eq(%w( 2 4 3 1 ))
268
+ @namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1])
269
+ expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
216
270
  end
217
271
 
218
272
  it "should properly union two sorted sets without options" do
@@ -222,7 +276,7 @@ describe "redis" do
222
276
  @namespaced.zadd('sort2', 3, 3)
223
277
  @namespaced.zadd('sort2', 4, 4)
224
278
  @namespaced.zunionstore('union', ['sort1', 'sort2'])
225
- @namespaced.zrevrange('union', 0, -1).should eq(%w( 4 2 3 1 ))
279
+ expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 4 2 3 1 ))
226
280
  end
227
281
 
228
282
  it "should properly intersect two sorted sets without options" do
@@ -237,7 +291,7 @@ describe "redis" do
237
291
  @namespaced.zinterstore('inter', ['food', 'color'])
238
292
 
239
293
  inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
240
- inter_values.should =~ [['orange', 3.0], ['eggplant', 7.0]]
294
+ expect(inter_values).to match_array([['orange', 3.0], ['eggplant', 7.0]])
241
295
  end
242
296
 
243
297
  it "should properly intersect two sorted sets with options" do
@@ -252,7 +306,37 @@ describe "redis" do
252
306
  @namespaced.zinterstore('inter', ['food', 'color'], :aggregate => "min")
253
307
 
254
308
  inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
255
- inter_values.should =~ [['orange', 1.0], ['eggplant', 3.0]]
309
+ expect(inter_values).to match_array([['orange', 1.0], ['eggplant', 3.0]])
310
+ end
311
+
312
+ it "should return lexicographical range for sorted set" do
313
+ @namespaced.zadd('food', 0, 'orange')
314
+ @namespaced.zadd('food', 0, 'banana')
315
+ @namespaced.zadd('food', 0, 'eggplant')
316
+
317
+ values = @namespaced.zrangebylex('food', '[b', '(o')
318
+ expect(values).to match_array(['banana', 'eggplant'])
319
+ end
320
+
321
+ it "should return the number of elements removed from the set" do
322
+ @namespaced.zadd('food', 0, 'orange')
323
+ @namespaced.zadd('food', 0, 'banana')
324
+ @namespaced.zadd('food', 0, 'eggplant')
325
+
326
+ removed = @namespaced.zremrangebylex('food', '[b', '(o')
327
+ expect(removed).to eq(2)
328
+
329
+ values = @namespaced.zrange('food', 0, -1)
330
+ expect(values).to eq(['orange'])
331
+ end
332
+
333
+ it "should return reverce lexicographical range for sorted set" do
334
+ @namespaced.zadd('food', 0, 'orange')
335
+ @namespaced.zadd('food', 0, 'banana')
336
+ @namespaced.zadd('food', 0, 'eggplant')
337
+
338
+ values = @namespaced.zrevrangebylex('food', '(o', '[b')
339
+ expect(values).to match_array(['banana', 'eggplant'])
256
340
  end
257
341
 
258
342
  it "should add namespace to sort" do
@@ -263,24 +347,24 @@ describe "redis" do
263
347
  @namespaced.set('value_1', 'a')
264
348
  @namespaced.set('value_2', 'b')
265
349
 
266
- @namespaced.sort('foo').should eq(%w( 1 2 ))
267
- @namespaced.sort('foo', :limit => [0, 1]).should eq(%w( 1 ))
268
- @namespaced.sort('foo', :order => 'desc').should eq(%w( 2 1 ))
269
- @namespaced.sort('foo', :by => 'weight_*').should eq(%w( 2 1 ))
270
- @namespaced.sort('foo', :get => 'value_*').should eq(%w( a b ))
271
- @namespaced.sort('foo', :get => '#').should eq(%w( 1 2 ))
272
- @namespaced.sort('foo', :get => ['#', 'value_*']).should eq([["1", "a"], ["2", "b"]])
350
+ expect(@namespaced.sort('foo')).to eq(%w( 1 2 ))
351
+ expect(@namespaced.sort('foo', :limit => [0, 1])).to eq(%w( 1 ))
352
+ expect(@namespaced.sort('foo', :order => 'desc')).to eq(%w( 2 1 ))
353
+ expect(@namespaced.sort('foo', :by => 'weight_*')).to eq(%w( 2 1 ))
354
+ expect(@namespaced.sort('foo', :get => 'value_*')).to eq(%w( a b ))
355
+ expect(@namespaced.sort('foo', :get => '#')).to eq(%w( 1 2 ))
356
+ expect(@namespaced.sort('foo', :get => ['#', 'value_*'])).to eq([["1", "a"], ["2", "b"]])
273
357
 
274
358
  @namespaced.sort('foo', :store => 'result')
275
- @namespaced.lrange('result', 0, -1).should eq(%w( 1 2 ))
359
+ expect(@namespaced.lrange('result', 0, -1)).to eq(%w( 1 2 ))
276
360
  end
277
361
 
278
362
  it "should yield the correct list of keys" do
279
- @namespaced["foo"] = 1
280
- @namespaced["bar"] = 2
281
- @namespaced["baz"] = 3
282
- @namespaced.keys("*").sort.should eq(%w( bar baz foo ))
283
- @namespaced.keys.sort.should eq(%w( bar baz foo ))
363
+ @namespaced.set("foo", 1)
364
+ @namespaced.set("bar", 2)
365
+ @namespaced.set("baz", 3)
366
+ expect(@namespaced.keys("*").sort).to eq(%w( bar baz foo ))
367
+ expect(@namespaced.keys.sort).to eq(%w( bar baz foo ))
284
368
  end
285
369
 
286
370
  it "should add namepsace to multi blocks" do
@@ -289,7 +373,7 @@ describe "redis" do
289
373
  r.del "foo"
290
374
  r.mapped_hmset "foo", {"key1" => "value1"}
291
375
  end
292
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
376
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
293
377
  end
294
378
 
295
379
  it "should pass through multi commands without block" do
@@ -300,14 +384,14 @@ describe "redis" do
300
384
  @namespaced.mapped_hmset "foo", {"key1" => "value1"}
301
385
  @namespaced.exec
302
386
 
303
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
387
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
304
388
  end
305
389
 
306
390
  it 'should return futures without attempting to remove namespaces' do
307
391
  @namespaced.multi do
308
392
  @future = @namespaced.keys('*')
309
393
  end
310
- @future.class.should be(Redis::Future)
394
+ expect(@future.class).to be(Redis::Future)
311
395
  end
312
396
 
313
397
  it "should add namespace to pipelined blocks" do
@@ -316,74 +400,134 @@ describe "redis" do
316
400
  r.del "foo"
317
401
  r.mapped_hmset "foo", {"key1" => "value1"}
318
402
  end
319
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
403
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
320
404
  end
321
405
 
322
406
  it "should returned response array from pipelined block" do
323
407
  @namespaced.mset "foo", "bar", "key", "value"
324
408
  result = @namespaced.pipelined do |r|
325
- r["foo"]
326
- r["key"]
409
+ r.get("foo")
410
+ r.get("key")
327
411
  end
328
- result.should eq(["bar", "value"])
412
+ expect(result).to eq(["bar", "value"])
413
+ end
414
+
415
+ it "is thread safe for multi blocks" do
416
+ mon = Monitor.new
417
+ entered = false
418
+ entered_cond = mon.new_cond
419
+
420
+ thread = Thread.new do
421
+ mon.synchronize do
422
+ entered_cond.wait_until { entered }
423
+ @namespaced.multi
424
+ end
425
+ end
426
+
427
+ @namespaced.multi do |transaction|
428
+ entered = true
429
+ mon.synchronize { entered_cond.signal }
430
+ thread.join(0.1)
431
+ transaction.get("foo")
432
+ end
433
+ thread.join
329
434
  end
330
435
 
331
436
  it "should add namespace to strlen" do
332
437
  @namespaced.set("mykey", "123456")
333
- @namespaced.strlen("mykey").should eq(6)
438
+ expect(@namespaced.strlen("mykey")).to eq(6)
334
439
  end
335
440
 
336
441
  it "should not add namespace to echo" do
337
- @namespaced.echo(123).should eq("123")
442
+ expect(@namespaced.echo(123)).to eq("123")
338
443
  end
339
444
 
340
445
  it 'should not add namespace to disconnect!' do
341
- expect(@redis).to receive(:disconnect!).with().and_call_original
446
+ expect(@redis).to receive(:disconnect!).with(no_args).and_call_original
342
447
 
343
448
  expect(@namespaced.disconnect!).to be nil
344
449
  end
345
450
 
346
451
  it "can change its namespace" do
347
- @namespaced['foo'].should eq(nil)
348
- @namespaced['foo'] = 'chris'
349
- @namespaced['foo'].should eq('chris')
452
+ expect(@namespaced.get('foo')).to eq(nil)
453
+ @namespaced.set('foo', 'chris')
454
+ expect(@namespaced.get('foo')).to eq('chris')
350
455
 
351
- @namespaced.namespace.should eq(:ns)
456
+ expect(@namespaced.namespace).to eq(:ns)
352
457
  @namespaced.namespace = :spec
353
- @namespaced.namespace.should eq(:spec)
458
+ expect(@namespaced.namespace).to eq(:spec)
354
459
 
355
- @namespaced['foo'].should eq(nil)
356
- @namespaced['foo'] = 'chris'
357
- @namespaced['foo'].should eq('chris')
460
+ expect(@namespaced.get('foo')).to eq(nil)
461
+ @namespaced.set('foo', 'chris')
462
+ expect(@namespaced.get('foo')).to eq('chris')
358
463
  end
359
464
 
360
465
  it "can accept a temporary namespace" do
361
- @namespaced.namespace.should eq(:ns)
362
- @namespaced['foo'].should eq(nil)
466
+ expect(@namespaced.namespace).to eq(:ns)
467
+ expect(@namespaced.get('foo')).to eq(nil)
363
468
 
364
469
  @namespaced.namespace(:spec) do |temp_ns|
365
- temp_ns.namespace.should eq(:spec)
366
- temp_ns['foo'].should eq(nil)
367
- temp_ns['foo'] = 'jake'
368
- temp_ns['foo'].should eq('jake')
470
+ expect(temp_ns.namespace).to eq(:spec)
471
+ expect(temp_ns.get('foo')).to eq(nil)
472
+ temp_ns.set('foo', 'jake')
473
+ expect(temp_ns.get('foo')).to eq('jake')
369
474
  end
370
475
 
371
- @namespaced.namespace.should eq(:ns)
372
- @namespaced['foo'].should eq(nil)
476
+ expect(@namespaced.namespace).to eq(:ns)
477
+ expect(@namespaced.get('foo')).to eq(nil)
373
478
  end
374
479
 
375
480
  it "should respond to :namespace=" do
376
- @namespaced.respond_to?(:namespace=).should eq(true)
481
+ expect(@namespaced.respond_to?(:namespace=)).to eq(true)
377
482
  end
378
483
 
379
484
  it "should respond to :warning=" do
380
- @namespaced.respond_to?(:warning=).should == true
485
+ expect(@namespaced.respond_to?(:warning=)).to eq(true)
381
486
  end
382
487
 
383
488
  it "should raise an exception when an unknown command is passed" do
384
489
  expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
385
490
  end
386
491
 
492
+ describe '#inspect' do
493
+ let(:single_level_names) { %i[first] }
494
+ let(:double_level_names) { %i[first second] }
495
+ let(:triple_level_names) { %i[first second third] }
496
+ let(:namespace_builder) do
497
+ ->(redis, *namespaces) { namespaces.reduce(redis) { |r, n| Redis::Namespace.new(n, redis: r) } }
498
+ end
499
+ let(:regexp_builder) do
500
+ ->(*namespaces) { %r{/#{namespaces.join(':')}>\z} }
501
+ end
502
+
503
+ context 'when one namespace' do
504
+ let(:single_namespaced) { namespace_builder.call(@redis, *single_level_names) }
505
+ let(:regexp) { regexp_builder.call(*single_level_names) }
506
+
507
+ it 'should have correct ending of inspect string' do
508
+ expect(regexp =~ single_namespaced.inspect).not_to be(nil)
509
+ end
510
+ end
511
+
512
+ context 'when two namespaces' do
513
+ let(:double_namespaced) { namespace_builder.call(@redis, *double_level_names) }
514
+ let(:regexp) { regexp_builder.call(*double_level_names) }
515
+
516
+ it 'should have correct ending of inspect string' do
517
+ expect(regexp =~ double_namespaced.inspect).not_to be(nil)
518
+ end
519
+ end
520
+
521
+ context 'when three namespaces' do
522
+ let(:triple_namespaced) { namespace_builder.call(@redis, *triple_level_names) }
523
+ let(:regexp) { regexp_builder.call(*triple_level_names) }
524
+
525
+ it 'should have correct ending of inspect string' do
526
+ expect(regexp =~ triple_namespaced.inspect).not_to be(nil)
527
+ end
528
+ end
529
+ end
530
+
387
531
  # Redis 2.6 RC reports its version as 2.5.
388
532
  if @redis_version >= Gem::Version.new("2.5.0")
389
533
  describe "redis 2.6 commands" do
@@ -417,7 +561,7 @@ describe "redis" do
417
561
  v = @namespaced.dump("foo")
418
562
  @redis.del("ns:foo")
419
563
 
420
- expect(@namespaced.restore("foo", 1000, v)).to be_true
564
+ expect(@namespaced.restore("foo", 1000, v)).to be_truthy
421
565
  expect(@redis.get("ns:foo")).to eq 'a'
422
566
  expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
423
567
 
@@ -425,72 +569,72 @@ describe "redis" do
425
569
  w = @namespaced.dump("bar")
426
570
  @redis.del("ns:bar")
427
571
 
428
- expect(@namespaced.restore("bar", 1000, w)).to be_true
572
+ expect(@namespaced.restore("bar", 1000, w)).to be_truthy
429
573
  expect(@redis.lrange('ns:bar', 0, -1)).to eq %w(b c d)
430
574
  expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
431
575
  end
432
576
 
433
577
  it "should namespace hincrbyfloat" do
434
578
  @namespaced.hset('mykey', 'field', 10.50)
435
- @namespaced.hincrbyfloat('mykey', 'field', 0.1).should eq(10.6)
579
+ expect(@namespaced.hincrbyfloat('mykey', 'field', 0.1)).to eq(10.6)
436
580
  end
437
581
 
438
582
  it "should namespace incrbyfloat" do
439
583
  @namespaced.set('mykey', 10.50)
440
- @namespaced.incrbyfloat('mykey', 0.1).should eq(10.6)
584
+ expect(@namespaced.incrbyfloat('mykey', 0.1)).to eq(10.6)
441
585
  end
442
586
 
443
587
  it "should namespace object" do
444
588
  @namespaced.set('foo', 1000)
445
- @namespaced.object('encoding', 'foo').should eq('int')
589
+ expect(@namespaced.object('encoding', 'foo')).to eq('int')
446
590
  end
447
591
 
448
592
  it "should namespace persist" do
449
593
  @namespaced.set('mykey', 'Hello')
450
594
  @namespaced.expire('mykey', 60)
451
- @namespaced.persist('mykey').should eq(true)
452
- @namespaced.ttl('mykey').should eq(-1)
595
+ expect(@namespaced.persist('mykey')).to eq(true)
596
+ expect(@namespaced.ttl('mykey')).to eq(-1)
453
597
  end
454
598
 
455
599
  it "should namespace pexpire" do
456
600
  @namespaced.set('mykey', 'Hello')
457
- @namespaced.pexpire('mykey', 60000).should eq(true)
601
+ expect(@namespaced.pexpire('mykey', 60000)).to eq(true)
458
602
  end
459
603
 
460
604
  it "should namespace pexpireat" do
461
605
  @namespaced.set('mykey', 'Hello')
462
- @namespaced.pexpire('mykey', 1555555555005).should eq(true)
606
+ expect(@namespaced.pexpire('mykey', 1555555555005)).to eq(true)
463
607
  end
464
608
 
465
609
  it "should namespace psetex" do
466
- @namespaced.psetex('mykey', 10000, 'Hello').should eq('OK')
467
- @namespaced.get('mykey').should eq('Hello')
610
+ expect(@namespaced.psetex('mykey', 10000, 'Hello')).to eq('OK')
611
+ expect(@namespaced.get('mykey')).to eq('Hello')
468
612
  end
469
613
 
470
614
  it "should namespace pttl" do
471
615
  @namespaced.set('mykey', 'Hello')
472
616
  @namespaced.expire('mykey', 1)
473
- @namespaced.pttl('mykey').should >= 0
617
+ expect(@namespaced.pttl('mykey')).to be >= 0
474
618
  end
475
619
 
476
620
  it "should namespace eval keys passed in as array args" do
477
- @namespaced.
478
- eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2]).
479
- should eq(%w[ns:k1 ns:k2])
621
+ expect(@namespaced.
622
+ eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2])).
623
+ to eq(%w[ns:k1 ns:k2])
480
624
  end
481
625
 
482
626
  it "should namespace eval keys passed in as hash args" do
483
- @namespaced.
484
- eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
485
- should eq(%w[ns:k1 ns:k2])
627
+ expect(@namespaced.
628
+ eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
629
+ to eq(%w[ns:k1 ns:k2])
486
630
  end
487
631
 
488
632
  it "should namespace eval keys passed in as hash args unmodified" do
489
633
  args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
490
634
  args.freeze
491
- @namespaced.
492
- eval("return {KEYS[1], KEYS[2]}", args).
493
- should eq(%w[ns:k1 ns:k2])
635
+ expect(@namespaced.
636
+ eval("return {KEYS[1], KEYS[2]}", args)).
637
+ to eq(%w[ns:k1 ns:k2])
494
638
  end
495
639
 
496
640
  context '#evalsha' do
@@ -499,23 +643,23 @@ describe "redis" do
499
643
  end
500
644
 
501
645
  it "should namespace evalsha keys passed in as array args" do
502
- @namespaced.
503
- evalsha(sha, %w[k1 k2], %w[arg1 arg2]).
504
- should eq(%w[ns:k1 ns:k2])
646
+ expect(@namespaced.
647
+ evalsha(sha, %w[k1 k2], %w[arg1 arg2])).
648
+ to eq(%w[ns:k1 ns:k2])
505
649
  end
506
650
 
507
651
  it "should namespace evalsha keys passed in as hash args" do
508
- @namespaced.
509
- evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
510
- should eq(%w[ns:k1 ns:k2])
652
+ expect(@namespaced.
653
+ evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
654
+ to eq(%w[ns:k1 ns:k2])
511
655
  end
512
656
 
513
657
  it "should namespace evalsha keys passed in as hash args unmodified" do
514
658
  args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
515
659
  args.freeze
516
- @namespaced.
517
- evalsha(sha, args).
518
- should eq(%w[ns:k1 ns:k2])
660
+ expect(@namespaced.
661
+ evalsha(sha, args)).
662
+ to eq(%w[ns:k1 ns:k2])
519
663
  end
520
664
  end
521
665
 
@@ -524,13 +668,13 @@ describe "redis" do
524
668
  let(:sha) { @redis.script(:load, "return {KEYS[1], KEYS[2]}") }
525
669
 
526
670
  it "should namespace eval keys passed in as hash args" do
527
- nested_namespace.
528
- eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
529
- should eq(%w[ns:nest:k1 ns:nest:k2])
671
+ expect(nested_namespace.
672
+ eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
673
+ to eq(%w[ns:nest:k1 ns:nest:k2])
530
674
  end
531
675
  it "should namespace evalsha keys passed in as hash args" do
532
- nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
533
- should eq(%w[ns:nest:k1 ns:nest:k2])
676
+ expect(nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
677
+ to eq(%w[ns:nest:k1 ns:nest:k2])
534
678
  end
535
679
  end
536
680
  end
@@ -559,16 +703,16 @@ describe "redis" do
559
703
  context 'when :match supplied' do
560
704
  it 'should retrieve the proper keys' do
561
705
  _, result = @namespaced.scan(0, :match => 'zeta:*', :count => 1000)
562
- result.should =~ matching_namespaced_keys
706
+ expect(result).to match_array(matching_namespaced_keys)
563
707
  end
564
708
  end
565
709
  context 'without :match supplied' do
566
710
  it 'should retrieve the proper keys' do
567
711
  _, result = @namespaced.scan(0, :count => 1000)
568
- result.should =~ namespaced_keys
712
+ expect(result).to match_array(namespaced_keys)
569
713
  end
570
714
  end
571
- end if Redis.current.respond_to?(:scan)
715
+ end if Redis.new.respond_to?(:scan)
572
716
 
573
717
  context '#scan_each' do
574
718
  context 'when :match supplied' do
@@ -576,13 +720,13 @@ describe "redis" do
576
720
  it 'should yield unnamespaced' do
577
721
  results = []
578
722
  @namespaced.scan_each(:match => 'zeta:*', :count => 1000) {|k| results << k }
579
- results.should =~ matching_namespaced_keys
723
+ expect(results).to match_array(matching_namespaced_keys)
580
724
  end
581
725
  end
582
726
  context 'without a block' do
583
727
  it 'should return an Enumerator that un-namespaces' do
584
728
  enum = @namespaced.scan_each(:match => 'zeta:*', :count => 1000)
585
- enum.to_a.should =~ matching_namespaced_keys
729
+ expect(enum.to_a).to match_array(matching_namespaced_keys)
586
730
  end
587
731
  end
588
732
  end
@@ -591,17 +735,17 @@ describe "redis" do
591
735
  it 'should yield unnamespaced' do
592
736
  results = []
593
737
  @namespaced.scan_each(:count => 1000){ |k| results << k }
594
- results.should =~ namespaced_keys
738
+ expect(results).to match_array(namespaced_keys)
595
739
  end
596
740
  end
597
741
  context 'without a block' do
598
742
  it 'should return an Enumerator that un-namespaces' do
599
743
  enum = @namespaced.scan_each(:count => 1000)
600
- enum.to_a.should =~ namespaced_keys
744
+ expect(enum.to_a).to match_array(namespaced_keys)
601
745
  end
602
746
  end
603
747
  end
604
- end if Redis.current.respond_to?(:scan_each)
748
+ end if Redis.new.respond_to?(:scan_each)
605
749
  end
606
750
 
607
751
  context 'hash scan methods' do
@@ -620,16 +764,16 @@ describe "redis" do
620
764
  context 'when supplied :match' do
621
765
  it 'should retrieve the proper keys' do
622
766
  _, results = @namespaced.hscan('hsh', 0, :match => 'zeta:*')
623
- results.should =~ hash_matching_subset.to_a
767
+ expect(results).to match_array(hash_matching_subset.to_a)
624
768
  end
625
769
  end
626
770
  context 'without :match supplied' do
627
771
  it 'should retrieve all hash keys' do
628
772
  _, results = @namespaced.hscan('hsh', 0)
629
- results.should =~ @redis.hgetall('ns:hsh').to_a
773
+ expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
630
774
  end
631
775
  end
632
- end if Redis.current.respond_to?(:hscan)
776
+ end if Redis.new.respond_to?(:hscan)
633
777
 
634
778
  context '#hscan_each' do
635
779
  context 'when :match supplied' do
@@ -637,13 +781,13 @@ describe "redis" do
637
781
  it 'should yield the correct hash keys unchanged' do
638
782
  results = []
639
783
  @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
640
- results.should =~ hash_matching_subset.to_a
784
+ expect(results).to match_array(hash_matching_subset.to_a)
641
785
  end
642
786
  end
643
787
  context 'without a block' do
644
788
  it 'should return an Enumerator that yields the correct hash keys unchanged' do
645
789
  enum = @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000)
646
- enum.to_a.should =~ hash_matching_subset.to_a
790
+ expect(enum.to_a).to match_array(hash_matching_subset.to_a)
647
791
  end
648
792
  end
649
793
  end
@@ -652,17 +796,17 @@ describe "redis" do
652
796
  it 'should yield all hash keys unchanged' do
653
797
  results = []
654
798
  @namespaced.hscan_each('hsh', :count => 1000){ |k| results << k }
655
- results.should =~ hash.to_a
799
+ expect(results).to match_array(hash.to_a)
656
800
  end
657
801
  end
658
802
  context 'without a block' do
659
803
  it 'should return an Enumerator that yields all keys unchanged' do
660
804
  enum = @namespaced.hscan_each('hsh', :count => 1000)
661
- enum.to_a.should =~ hash.to_a
805
+ expect(enum.to_a).to match_array(hash.to_a)
662
806
  end
663
807
  end
664
808
  end
665
- end if Redis.current.respond_to?(:hscan_each)
809
+ end if Redis.new.respond_to?(:hscan_each)
666
810
  end
667
811
 
668
812
  context 'set scan methods' do
@@ -681,16 +825,16 @@ describe "redis" do
681
825
  context 'when supplied :match' do
682
826
  it 'should retrieve the matching set members from the proper set' do
683
827
  _, results = @namespaced.sscan('set', 0, :match => 'zeta:*', :count => 1000)
684
- results.should =~ matching_subset
828
+ expect(results).to match_array(matching_subset)
685
829
  end
686
830
  end
687
831
  context 'without :match supplied' do
688
832
  it 'should retrieve all set members from the proper set' do
689
833
  _, results = @namespaced.sscan('set', 0, :count => 1000)
690
- results.should =~ set
834
+ expect(results).to match_array(set)
691
835
  end
692
836
  end
693
- end if Redis.current.respond_to?(:sscan)
837
+ end if Redis.new.respond_to?(:sscan)
694
838
 
695
839
  context '#sscan_each' do
696
840
  context 'when :match supplied' do
@@ -698,13 +842,13 @@ describe "redis" do
698
842
  it 'should yield the correct hset elements unchanged' do
699
843
  results = []
700
844
  @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
701
- results.should =~ matching_subset
845
+ expect(results).to match_array(matching_subset)
702
846
  end
703
847
  end
704
848
  context 'without a block' do
705
849
  it 'should return an Enumerator that yields the correct set elements unchanged' do
706
850
  enum = @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000)
707
- enum.to_a.should =~ matching_subset
851
+ expect(enum.to_a).to match_array(matching_subset)
708
852
  end
709
853
  end
710
854
  end
@@ -713,17 +857,17 @@ describe "redis" do
713
857
  it 'should yield all set elements unchanged' do
714
858
  results = []
715
859
  @namespaced.sscan_each('set', :count => 1000){ |k| results << k }
716
- results.should =~ set
860
+ expect(results).to match_array(set)
717
861
  end
718
862
  end
719
863
  context 'without a block' do
720
864
  it 'should return an Enumerator that yields all set elements unchanged' do
721
865
  enum = @namespaced.sscan_each('set', :count => 1000)
722
- enum.to_a.should =~ set
866
+ expect(enum.to_a).to match_array(set)
723
867
  end
724
868
  end
725
869
  end
726
- end if Redis.current.respond_to?(:sscan_each)
870
+ end if Redis.new.respond_to?(:sscan_each)
727
871
  end
728
872
 
729
873
  context 'zset scan methods' do
@@ -743,17 +887,17 @@ describe "redis" do
743
887
  it 'should retrieve the matching set elements and their scores' do
744
888
  results = []
745
889
  @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms }
746
- results.should =~ hash_matching_subset.to_a
890
+ expect(results).to match_array(hash_matching_subset.to_a)
747
891
  end
748
892
  end
749
893
  context 'without :match supplied' do
750
894
  it 'should retrieve all set elements and their scores' do
751
895
  results = []
752
896
  @namespaced.zscan_each('zset', :count => 1000) { |ms| results << ms }
753
- results.should =~ hash.to_a
897
+ expect(results).to match_array(hash.to_a)
754
898
  end
755
899
  end
756
- end if Redis.current.respond_to?(:zscan)
900
+ end if Redis.new.respond_to?(:zscan)
757
901
 
758
902
  context '#zscan_each' do
759
903
  context 'when :match supplied' do
@@ -761,13 +905,13 @@ describe "redis" do
761
905
  it 'should yield the correct set elements and scores unchanged' do
762
906
  results = []
763
907
  @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms}
764
- results.should =~ hash_matching_subset.to_a
908
+ expect(results).to match_array(hash_matching_subset.to_a)
765
909
  end
766
910
  end
767
911
  context 'without a block' do
768
912
  it 'should return an Enumerator that yields the correct set elements and scoresunchanged' do
769
913
  enum = @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000)
770
- enum.to_a.should =~ hash_matching_subset.to_a
914
+ expect(enum.to_a).to match_array(hash_matching_subset.to_a)
771
915
  end
772
916
  end
773
917
  end
@@ -776,17 +920,17 @@ describe "redis" do
776
920
  it 'should yield all set elements and scores unchanged' do
777
921
  results = []
778
922
  @namespaced.zscan_each('zset', :count => 1000){ |ms| results << ms }
779
- results.should =~ hash.to_a
923
+ expect(results).to match_array(hash.to_a)
780
924
  end
781
925
  end
782
926
  context 'without a block' do
783
927
  it 'should return an Enumerator that yields all set elements and scores unchanged' do
784
928
  enum = @namespaced.zscan_each('zset', :count => 1000)
785
- enum.to_a.should =~ hash.to_a
929
+ expect(enum.to_a).to match_array(hash.to_a)
786
930
  end
787
931
  end
788
932
  end
789
- end if Redis.current.respond_to?(:zscan_each)
933
+ end if Redis.new.respond_to?(:zscan_each)
790
934
  end
791
935
  end
792
936
  end
@@ -794,12 +938,12 @@ describe "redis" do
794
938
  if @redis_version >= Gem::Version.new("2.8.9")
795
939
  it 'should namespace pfadd' do
796
940
  5.times { |n| @namespaced.pfadd("pf", n) }
797
- @redis.pfcount("ns:pf").should == 5
941
+ expect(@redis.pfcount("ns:pf")).to eq(5)
798
942
  end
799
943
 
800
944
  it 'should namespace pfcount' do
801
945
  5.times { |n| @redis.pfadd("ns:pf", n) }
802
- @namespaced.pfcount("pf").should == 5
946
+ expect(@namespaced.pfcount("pf")).to eq(5)
803
947
  end
804
948
 
805
949
  it 'should namespace pfmerge' do
@@ -809,7 +953,18 @@ describe "redis" do
809
953
  end
810
954
 
811
955
  @namespaced.pfmerge("pfc", "pfa", "pfb")
812
- @redis.pfcount("ns:pfc").should == 10
956
+ expect(@redis.pfcount("ns:pfc")).to eq(10)
957
+ end
958
+ end
959
+
960
+ describe :full_namespace do
961
+ it "should return the full namespace including sub namespaces" do
962
+ sub_namespaced = Redis::Namespace.new(:sub1, :redis => @namespaced)
963
+ sub_sub_namespaced = Redis::Namespace.new(:sub2, :redis => sub_namespaced)
964
+
965
+ expect(@namespaced.full_namespace).to eql("ns")
966
+ expect(sub_namespaced.full_namespace).to eql("ns:sub1")
967
+ expect(sub_sub_namespaced.full_namespace).to eql("ns:sub1:sub2")
813
968
  end
814
969
  end
815
970
  end