-
-
Notifications
You must be signed in to change notification settings - Fork 277
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 new RSpec/NegatedExpectation
cop
#1838
Conversation
c4ed05a
to
fd112e0
Compare
This cop checks for expectations with `!`. The autocorrection is marked as unsafe, because it may change the expectation from a positive to a negative one, or vice versa. ```ruby !expect(foo).to be_valid expect(foo).not_to be_valid ```
fd112e0
to
b8ea2f9
Compare
I don’t think this cop reflects a real problem. For the example When I run this small spec file, both examples pass. require "rspec"
RSpec.describe "problem" do
specify { !expect(1).to be_odd }
specify { expect(1).to be_odd }
end |
@bquorning One of the real trouble cases I encountered was when there was only a test |
Hmm, I’m not sure if this is something we should have a cop for. There are probably many other ways to badly write a spec which this cop wouldn’t catch. I’d be interested to hear what @pirj thinks. |
FYI: A recent example I encountered was the capybara cheat sheet: |
memo) For example, a Lint/Void offense will result if it do
!expect(nil).to be_nil
# ^ Lint/Void: Operator ! used in void context.
do_something
end However, the following is not an offense: it do
!expect(nil).to be_nil
end |
I could argue with Void, as overridden unary RSpec supports binary With the first paragraph in mind, won’t it be better adding a pika-yoke on rapec-expectations side as an implementation of |
I agree with your opinion. I think it would be better if the poka-yoke is in |
I agree that adding a check to rspec-expectations would be better. |
This cop checks for expectations with
!
.The autocorrection is marked as unsafe, because it may change the expectation from a positive to a negative one, or vice versa.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if 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).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.Enabled: true
in.rubocop.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.