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

Fix RSpec/FilePath when checking an empty class #1000

Merged
merged 1 commit into from Aug 17, 2020
Merged

Conversation

bquorning
Copy link
Collaborator

Remember that RSpec/FilePath checks all files - not only **/*_spec.rb. And when some class defines e.g. an empty class, the TopLevelGroup module would raise an error.

Fixes #999.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • [-] Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

Remember that `RSpec/FilePath` checks *all* files - not only
**/*_spec.rb. And when some class defines e.g. an empty class, the
`TopLevelGroup` module would raise an error.

Fixes #999.
@bquorning bquorning requested a review from pirj August 17, 2020 09:11
@bquorning bquorning changed the title Fix RSpec/FilePath when checking an empty class Fix RSpec/FilePath when checking an empty class Aug 17, 2020
@bquorning
Copy link
Collaborator Author

Congratulations on the 1K pull requests (and issues) 🎉

@bquorning
Copy link
Collaborator Author

I hope it’s OK to ignore Code Climate’s report on added complexity…

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

We have spec/smoke_tests/empty_spec.rb. How did it happen to pass?

@@ -204,6 +204,14 @@
RUBY
end

# RSpec/FilePath runs on all files - not only **/*_spec.rb
Copy link
Member

Choose a reason for hiding this comment

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

Wondering, why so?
For some reason relevant_rubocop_rspec_file? evaluates to true for it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see it

        def relevant_rubocop_rspec_file?(_file)
          true
        end

@@ -38,7 +38,9 @@ def top_level_group?(node)
end

def top_level_nodes(node)
if node.begin_type?
if node.nil?
[]
Copy link
Member

Choose a reason for hiding this comment

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

I remember we were discussing this with Maxim and settled on

return unless root_node

Do you think both checks are necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As you mention, we already have return unless root_node inside #on_new_investigation. The problem happens when the root node is an empty module or class:

elsif node.module_type? || node.class_type?
  top_level_nodes(node.body)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mean, we could move the check into the elsif body:

elsif node.module_type? || node.class_type?
  node.body.nil? ? [] : top_level_nodes(node.body)

or

elsif node.module_type? || node.class_type?
  if node.body
    top_level_nodes(node.body)
  else
    []
  end

@pirj
Copy link
Member

pirj commented Aug 17, 2020

Congratulations on the 1K pull requests (and issues)

🎉 image

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Look good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RSpec/FilePath error occurs in 1.43.0
2 participants