redis-namespace 1.5.2 → 1.8.1

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