Fix an error RSpec/ChangeByZero cop when without expect block#2071
Fix an error RSpec/ChangeByZero cop when without expect block#2071pirj merged 1 commit intorubocop:masterfrom
RSpec/ChangeByZero cop when without expect block#2071Conversation
a05b88a to
d1eb4af
Compare
|
|
||
| expect_no_offenses(<<~RUBY) | ||
| it do | ||
| subject; change(Foo, :bar).by(0) |
There was a problem hiding this comment.
I would very much rather this cop to raise an exception than to swallow such a spec.
There was a problem hiding this comment.
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
|
@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 |
pirj
left a comment
There was a problem hiding this comment.
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.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).