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

Add configuration option AllowNested to RSpec/MultipleExpectations #1810

Closed
wants to merge 1 commit into from

Conversation

ydah
Copy link
Member

@ydah ydah commented Feb 16, 2024

Fix: #379


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

If you have modified an existing cop's configuration options:

  • Set VersionChanged: "<<next>>" in config/default.yml.

@ydah ydah requested a review from a team as a code owner February 16, 2024 06:56
expect_no_offenses(<<~RUBY)
describe Foo do
it 'uses expect with block twice' do
expect { my_code }.to raise_error(MyErrorType) do |error|
Copy link
Member

Choose a reason for hiding this comment

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

How would we count multiple nested expectations? As one or as multiple?
This really depends, right?

Copy link
Member

Choose a reason for hiding this comment

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

What would happen if there will be two expectations inside the block?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I understand. This is not an offense if there are multiple expectations in a block of the same block if it is completely nested, so instead, we need to count the number of expectations in the same block.

Copy link
Member

Choose a reason for hiding this comment

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

Right. And this is getting interesting when the Max is above one.

So

ex is one
ex { ex } is one

ex { ex }
ex { ex }
is two

ex {
ex
ex
}
is two

etc

does this make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Now that I look at it, I feel like adding this option makes it more confusing. Maybe AllowNested isn't such a good approach. I think I'll close this PR, but what do you think of @pirj ?

Copy link
Member

Choose a reason for hiding this comment

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

I agree. And the ticket as well - i see some comments expressing doubts from my past self

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.

Looks good and welcome back to your usual level of commitment! ❤️

@ydah ydah force-pushed the fix379 branch 3 times, most recently from 6ea1d53 to 05dcaad Compare February 28, 2024 04:21
@ydah ydah closed this Feb 29, 2024
@ydah ydah deleted the fix379 branch February 29, 2024 15:00
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.

MultipleExpectation and exception matching
2 participants