-
-
Notifications
You must be signed in to change notification settings - Fork 285
Fix false-negative for UnspecifiedException when matcher is chained
#1940
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
Conversation
419da80 to
2858671
Compare
2858671 to
60199ba
Compare
| return false unless node&.block_type? | ||
| expect_to = find_expect_to(node) | ||
| return false unless expect_to | ||
| return false if expect_to.block_node&.arguments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this checking expect { |args| … }.to raise_error?
Why do we ignore if there are any, how do we care?
Do we have a an example that will fail if we remove this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to test the raised error in detail, to may be called with a block with an argument as follows:
expect { foo }.to raise_error do |error|
expect(error.bar).to eq("baz")
endIf this code is removed, the following test will fail:
rubocop-rspec/spec/rubocop/cop/rspec/unspecified_exception_spec.rb
Lines 70 to 78 in ce4cd77
| it 'allows classes with blocks with do/end' do | |
| expect_no_offenses(<<~RUBY) | |
| expect { | |
| raise StandardError.new('error') | |
| }.to raise_error do |error| | |
| error.data | |
| end | |
| RUBY | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood.
Such syntax is confusing as hell. The block is not passed to to, but raise_error itself, isn’t it?
I recall there’s some poke-yoke warning in RSpec warning users when the block goes actually to the wrong one.
Ps and mistake happens if you change do/end to {} 🙈
However, yes, I now recall that we decided that such syntax should be tolerated as it is expected that aome check agains what the exception is will be made inside that block.
pirj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
ydah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I noticed that this cop could not detect the following cases, so fixed it.
Before submitting the PR make sure the following are checked:
master(if not - rebase it).CHANGELOG.mdif the new code introduces user-observable changes.bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).