Skip to content

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:

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