Skip to content

Commit

Permalink
Merge pull request #1009 from rubocop-hq/fix-file_path-cop-to-ignore-…
Browse files Browse the repository at this point in the history
…shared-groups

Skip files with shared groups in RSpec/FilePath
  • Loading branch information
Darhazer authored and bquorning committed Aug 24, 2020
1 parent 46b39c7 commit a57c6f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

* Fix `RSpec/FilePath` when checking a file with a shared example. ([@pirj][])

## 1.43.1 (2020-08-17)

* Fix `RSpec/FilePath` when checking a file defining e.g. an empty class. ([@bquorning][])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/file_path.rb
Expand Up @@ -69,7 +69,7 @@ class FilePath < Base

def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'

def on_top_level_group(node)
def on_top_level_example_group(node)
return unless top_level_groups.one?

const_described(node) do |send_node, described_class, arguments|
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/rspec/top_level_group.rb
Expand Up @@ -16,7 +16,7 @@ def on_new_investigation
return unless root_node

top_level_groups.each do |node|
example_group?(node, &method(:on_top_level_example_group))
on_top_level_example_group(node) if example_group?(node)
on_top_level_group(node)
end
end
Expand All @@ -29,9 +29,9 @@ def top_level_groups
private

# Dummy methods to be overridden in the consumer
def on_top_level_example_group; end
def on_top_level_example_group(_node); end

def on_top_level_group; end
def on_top_level_group(_node); end

def top_level_group?(node)
top_level_groups.include?(node)
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rspec/file_path_spec.rb
Expand Up @@ -64,6 +64,12 @@
RUBY
end

it 'ignores shared examples' do
expect_no_offenses(<<-RUBY, 'user.rb')
shared_examples_for 'foo' do; end
RUBY
end

it 'skips specs that do not describe a class / method' do
expect_no_offenses(<<-RUBY, 'some/class/spec.rb')
describe 'Test something' do; end
Expand Down

0 comments on commit a57c6f1

Please sign in to comment.