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