Replace *_any_instance_of with *_next_instance_of in RSpec
Summary
Implement a RuboCop Cop to auto-correct automatically all the references that are able to be converted in RSpec as:
-
expect_any_instance_of
->expect_next_instance_of
-
allow_any_instance_of
->allow_next_instance_of
Why
The story starts with this comment about replacing allow_any_instance_of
with expect_next_instance_of
.
At that moment, I was surprised for the comment because:
- This is something specific to GitLab because we have the gotcha about avoiding using
expect_any_instance_of
orallow_any_instance_of
in RSpec. - We didn't have the
allow_next_instance_of
spec helper, so there is a discrepancy between the existing method (allow_any_instance_of
) and its replacement (expect_next_instance_of
).
I already created the allow_next_instance_of
spec helper in !18139 (merged).
Improvements
I can see the following improvements:
- Developers don't need to point about style/gotchas that can be spotted automatically by tools (Rubocop).
- Follow our own guidelines (gotchas page) and dogfooding.
- Automatic replacement with Rubocop --auto-correct.
Edited by Arturo Herrero