Skip to content

Commit

Permalink
Merge pull request #1156 from rrosenblum/described_class
Browse files Browse the repository at this point in the history
Fix an exception in DescribedClass when accessing a constant on a variable in a namespaced spec
  • Loading branch information
pirj authored May 24, 2021
2 parents a01cc07 + 88a8f54 commit cb5c0dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

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

## 2.3.0 (2021-04-28)

Expand Down Expand Up @@ -615,3 +616,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@hosamaly]: https://github.com/hosamaly
[@stephannv]: https://github.com/stephannv
[@Tietew]: https://github.com/Tietew
[@rrosenblum]: https://github.com/rrosenblum
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 @@ -203,7 +203,7 @@ def const_name(node)
[name]
elsif namespace.const_type?
[*const_name(namespace), name]
elsif namespace.lvar_type? || namespace.cbase_type?
elsif %i[lvar cbase send].include?(namespace.type)
[nil, name]
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/rspec/described_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
RUBY
end

it 'allows accessing constants from variables when in a nested namespace' do
expect_no_offenses(<<~RUBY)
module Foo
describe MyClass do
let(:foo) { SomeClass }
let(:baz) { foo::CONST }
end
end
RUBY
end

it 'flags with metadata' do
expect_offense(<<-RUBY)
describe MyClass, some: :metadata do
Expand Down

0 comments on commit cb5c0dc

Please sign in to comment.