rubocop/rubocop-rspec

Cops Idea: NegativeSpecifiedException

marocchino opened this issue · 1 comments

# bad
expect { something }.not_to raise_error ArgumentError

# good
expect { something }.not_to raise_error

Motivation:
Basically, I want the test to fail when an error occurs.
The example is included in the Lint below, so we can make it a part of that Lint.
https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecunspecifiedexception

but.. I think it would be okay to separate them and allow them to be applied individually.

pirj commented

RSpec would warn for negation https://github.com/rspec/rspec-expectations/blob/2e8e800a0d8b64e7168dd625efe8f7526b7f1262/lib/rspec/matchers/built_in/raise_error.rb#L156
And it does a better job in runtime that we can with static analysis, eg for the mistakenly passed nil argument.

It’s also good to turn on raise_on_warnings https://github.com/rspec/rspec-core/blob/1eeadce5aa7137ead054783c31ff35cbfe9d07cc/lib/rspec/core/configuration.rb#L1766

We don’t try to duplicate what RSpec does already.
Do you think there’s still anything actionable here, @marocchino ?