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 a false positive for RSpec/DescribedClass when SkipBlocks is true and numblocks are used #2054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Earlopain
Copy link
Contributor

I will probably make a few more of these. I don't particularly care about numblocks, this just future-proofs it for itblock.


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).

@Earlopain Earlopain requested a review from a team as a code owner March 3, 2025 10:35
@Earlopain Earlopain force-pushed the described-class-numblocks branch from 50c3e9a to 6ff1c39 Compare March 3, 2025 10:36
expect_offense(<<~RUBY)
describe MyClass do
controller(ApplicationController) do
_1
Copy link
Member

Choose a reason for hiding this comment

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

What is the real-world use case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just here to make the block node into a numblock node. Since this is a user-defined method it can yield as much or as little as it wants and the user can use a few ways to express that. It just aligns it to work for all types of blocks there are (currently foo {}, foo { |bar| } and foo { _1 }, but also foo { it } in the future from Ruby 3.4).

I made the spec a bit more aligned to how could look like in actual code.

describe MyClass do
controller(ApplicationController) do
_1
bar = MyClass
Copy link
Member

Choose a reason for hiding this comment

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

Is this a setter? Doesn’t it need to be prefixed with self.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved this over from the test preceeding it. I added the prefix to both to make more sense

@Earlopain Earlopain force-pushed the described-class-numblocks branch from 6ff1c39 to 0451790 Compare March 3, 2025 11:03
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.

2 participants