Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip files with shared groups in RSpec/FilePath #1009

Merged
merged 1 commit into from Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

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

## 1.43.1 (2020-08-17)

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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out example_group? was yielding nil as there's no capture.

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