Skip to content

Commit

Permalink
Fix a case for DescribedClass cop
Browse files Browse the repository at this point in the history
If a local variable was part of the described class's namespace, the cop
was failing.

fixes rubocop#790
  • Loading branch information
pirj committed Jul 24, 2019
1 parent bcb7ce2 commit 034d870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/described_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def const_name(node)
# rubocop:enable InternalAffairs/NodeDestructuring
if !namespace
[name]
elsif namespace.cbase_type?
elsif namespace.lvar_type? || namespace.cbase_type?
[nil, name]
else
[*const_name(namespace), name]
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/rspec/described_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ module D
end
RUBY
end

it 'ignores if a local variable is part of the namespace' do
expect_no_offenses(<<-RUBY)
describe Broken do
[Foo, Bar].each do |klass|
describe klass::Baz.name do
it { }
end
end
end
RUBY
end
end

context 'when EnforcedStyle is :explicit' do
Expand Down

0 comments on commit 034d870

Please sign in to comment.