-
-
Notifications
You must be signed in to change notification settings - Fork 278
Fix an error RSpec/ChangeByZero
cop when without expect block
#2071
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
a05b88a
to
d1eb4af
Compare
|
||
expect_no_offenses(<<~RUBY) | ||
it do | ||
subject; change(Foo, :bar).by(0) |
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.
I would very much rather this cop to raise an exception than to swallow such a spec.
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.
Indeed, that example might be unnecessary. However, it makes sense that code like change(foo, :bar).by(0)
doesn't produce an error, so perhaps we could simply remove it from the test examples.
Could you rebase to the latest master branch? |
d1eb4af
to
e2953f5
Compare
Thank you. Could you squashed related commits together? |
e2953f5
to
ce811c7
Compare
ce811c7
to
9aa4b8a
Compare
9aa4b8a
to
8c4429e
Compare
RSpec/ChangeByZero
cop when without expect block
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❤️
@pirj If your concerns have now been resolved, merge this PR. |
Again. I would rather have this current error and let users know about such a mistake in their specs than to swallow it. Is there another cop that would catch this? Presently, this cop’s deficiency alerts users in a way, and prevents them from writing specs with false negatives. I’m not convinced that fixing this error is an improvement when there’s no other cop to catch this. I clearly understand that this only “detects” such cases with the “change” matcher, and others are left out. |
@pirj # spec/sample_spec.rb:13:3: C: RSpec/NoExpectationExample: No expectation found in this example.
it { change(numbers, :size).by(0) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I would appreciate your thoughts on this. |
I created |
@lee266 This is reasonable. I apologise to ask this, can’t check this as I’m away from my computer. Does it also detect the case with two statements? it { subject; change(numbers, :size).by(0) } |
@pirj
|
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.
Sorry for the confusion, and thank you for the fix! 🙌
issue number: #2069
Replace this text with a summary of the changes in your PR. The more detailed you are, the better.
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).