gitlab-org--gitlab-foss/spec/support/helpers/expect_next_instance_of.rb
Lin Jen-Shin 562f357ba5 Implement expect_next_instance_of and use it
We need this because `expect_any_instance_of` doesn't work on
prepended models. Now we could use the same code between CE/EE
2018-06-21 16:32:07 +08:00

13 lines
356 B
Ruby

module ExpectNextInstanceOf
def expect_next_instance_of(klass, *new_args)
receive_new = receive(:new)
receive_new.with(*new_args) if new_args.any?
expect(klass).to receive_new
.and_wrap_original do |method, *original_args|
method.call(*original_args).tap do |instance|
yield(instance)
end
end
end
end