Skip to content

Commit

Permalink
Merge pull request #164 from woarewe/improvements/add-nested-namespac…
Browse files Browse the repository at this point in the history
…es-to-inspect

Add final namespace prefix to inspect
  • Loading branch information
rafaelfranca committed Dec 13, 2019
2 parents 54066a5 + e282846 commit 27abd8b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/redis/namespace.rb
Expand Up @@ -373,7 +373,7 @@ def method_missing(command, *args, &block)

def inspect
"<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\
"for #{@redis.id}/#{@namespace}>"
"for #{@redis.id}/#{full_namespace}>"
end

def respond_to_missing?(command, include_all=false)
Expand Down
39 changes: 39 additions & 0 deletions spec/redis_spec.rb
Expand Up @@ -442,6 +442,45 @@
expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
end

describe '#inspect' do
let(:single_level_names) { %i[first] }
let(:double_level_names) { %i[first second] }
let(:triple_level_names) { %i[first second third] }
let(:namespace_builder) do
->(redis, *namespaces) { namespaces.reduce(redis) { |r, n| Redis::Namespace.new(n, redis: r) } }
end
let(:regexp_builder) do
->(*namespaces) { %r{/#{namespaces.join(':')}>\z} }
end

context 'when one namespace' do
let(:single_namespaced) { namespace_builder.call(@redis, *single_level_names) }
let(:regexp) { regexp_builder.call(*single_level_names) }

it 'should have correct ending of inspect string' do
expect(regexp =~ single_namespaced.inspect).not_to be(nil)
end
end

context 'when two namespaces' do
let(:double_namespaced) { namespace_builder.call(@redis, *double_level_names) }
let(:regexp) { regexp_builder.call(*double_level_names) }

it 'should have correct ending of inspect string' do
expect(regexp =~ double_namespaced.inspect).not_to be(nil)
end
end

context 'when three namespaces' do
let(:triple_namespaced) { namespace_builder.call(@redis, *triple_level_names) }
let(:regexp) { regexp_builder.call(*triple_level_names) }

it 'should have correct ending of inspect string' do
expect(regexp =~ triple_namespaced.inspect).not_to be(nil)
end
end
end

# Redis 2.6 RC reports its version as 2.5.
if @redis_version >= Gem::Version.new("2.5.0")
describe "redis 2.6 commands" do
Expand Down

0 comments on commit 27abd8b

Please sign in to comment.