Skip to content

Commit 88a8f54

Browse files
committed
Fix an exception in DescribedClass when accessing a constant on a variable in a namespaced spec
1 parent a01cc07 commit 88a8f54

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Master (Unreleased)
44

55
* Add missing documentation for `single_statement_only` style of `RSpec/ImplicitSubject` cop. ([@tejasbubane][])
6+
* Fix an exception in `DescribedClass` when accessing a constant on a variable in a spec that is nested in a namespace. ([@rrosenblum][])
67

78
## 2.3.0 (2021-04-28)
89

@@ -615,3 +616,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
615616
[@hosamaly]: https://github.com/hosamaly
616617
[@stephannv]: https://github.com/stephannv
617618
[@Tietew]: https://github.com/Tietew
619+
[@rrosenblum]: https://github.com/rrosenblum

lib/rubocop/cop/rspec/described_class.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def const_name(node)
203203
[name]
204204
elsif namespace.const_type?
205205
[*const_name(namespace), name]
206-
elsif namespace.lvar_type? || namespace.cbase_type?
206+
elsif %i[lvar cbase send].include?(namespace.type)
207207
[nil, name]
208208
end
209209
end

spec/rubocop/cop/rspec/described_class_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
RUBY
7878
end
7979

80+
it 'allows accessing constants from variables when in a nested namespace' do
81+
expect_no_offenses(<<~RUBY)
82+
module Foo
83+
describe MyClass do
84+
let(:foo) { SomeClass }
85+
let(:baz) { foo::CONST }
86+
end
87+
end
88+
RUBY
89+
end
90+
8091
it 'flags with metadata' do
8192
expect_offense(<<-RUBY)
8293
describe MyClass, some: :metadata do

0 commit comments

Comments
 (0)