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

Cops Idea: NegativeSpecifiedException #1742

Open
marocchino opened this issue Nov 17, 2023 · 1 comment
Open

Cops Idea: NegativeSpecifiedException #1742

marocchino opened this issue Nov 17, 2023 · 1 comment

Comments

@marocchino
Copy link
Contributor

# 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
Copy link
Member

pirj commented Nov 17, 2023

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 ?

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

No branches or pull requests

2 participants