-
-
Notifications
You must be signed in to change notification settings - Fork 278
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/ChangeWithoutExpect
cop
#2074
base: master
Are you sure you want to change the base?
Conversation
ae49a4e
to
07cb1d9
Compare
Follow up: #2071
07cb1d9
to
88d8bf9
Compare
'without chains' do | ||
expect_no_offenses(<<~RUBY) | ||
it 'changes the count' do | ||
change(Counter, :count) |
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.
Why doesn’t it register an offence?
(send | ||
{ | ||
(block (send nil? :expect ...) ...) | ||
(send nil? :expect ...) |
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.
Why do we match the non-block form here?
|
||
MSG = 'Use `change` matcher within an `expect` block.' | ||
RESTRICT_ON_SEND = [:change].freeze | ||
SINGLE_RESTRICTED_METHODS = %i[by by_at_least by_at_most from].freeze |
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.
# expect { subject }.to change(Counter, :count).by(1) | ||
# end | ||
# | ||
class ChangeWithoutExpect < RuboCop::Cop::Base |
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.
Even though this would detect a number of offences, wouldn’t it make more sense to make a more broad cop that would detect all built-in block matchers? “output”, “raise_error”, …
# expect { subject }.to change(Counter, :count).by(1) | ||
# end | ||
# | ||
class ChangeWithoutExpect < RuboCop::Cop::Base |
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.
Also, why only block matchers?
end | ||
RUBY | ||
end | ||
end |
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.
How does it behave with a case with two statements? Like “subject; change(:foo, :bar)”?
end | ||
RUBY | ||
end | ||
end |
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.
What it the matcher is assigned to a variable, and then used multiple times?
“m = change { sum }
expect { foo }.to m
expect { bar }.to m
“
This is a legit RSpec construct, and should work fine?
Follow up: #2071
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
.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"
inconfig/default.yml
.