Implement `expect_next_instance_of` to replace `expect_any_instance_of`
The following discussion from !5808 (merged) should be addressed:
-
@godfat started a discussion: (+1 comment) We should probably try to write a wrapper around this, so that we don't have to rely on
expect_any_instance_of
which isn't a good idea, nor does it work withprepend
. Maybe something like...def expect_next_instance_of(klass, *new_args) expect(klass).to receive(:new) .with(*new_args).and_wrap_original do |method, *original_args| method.call(*original_args).tap do |instance| yield(instance) end end end
And use it like:
expect_next_instance_of(MergeRequests::RefreshService, project, user) do |refresh_service| expect(refresh_service).to receive(:execute).with(oldrev, newrev, ref) end
Edited by Lin Jen-Shin