Skip to content

Commit

Permalink
Merge pull request #791 from pirj/fix-described_class-cbase-edge-case
Browse files Browse the repository at this point in the history
Fix a case for DescribedClass cop
  • Loading branch information
bquorning authored Jul 26, 2019
2 parents b1d531c + 8bbf5f0 commit 6420b04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

* Fix `RSpec/DescribedClass`'s error when a local variable is part of the namespace. ([@pirj][])

## 1.34.0 (2019-07-23)

* Remove `AggregateFailuresByDefault` config option of `RSpec/MultipleExpectations`. ([@pirj][])
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rspec/described_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ def const_name(node)
# rubocop:enable InternalAffairs/NodeDestructuring
if !namespace
[name]
elsif namespace.cbase_type?
[nil, name]
else
elsif namespace.const_type?
[*const_name(namespace), name]
elsif namespace.lvar_type? || namespace.cbase_type?
[nil, name]
end
end

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 6420b04

Please sign in to comment.