Commit 35735620 authored by Arturo Herrero's avatar Arturo Herrero

Create allow_next_instance_of spec helper

parent c0133a59
......@@ -106,7 +106,7 @@ end
Using `any_instance` to stub a method (elasticsearch_indexing) that has been defined on a prepended module (EE::ApplicationSetting) is not supported.
```
### Alternative: `expect_next_instance_of`
### Alternative: `expect_next_instance_of` or `allow_next_instance_of`
Instead of writing:
......
......@@ -90,6 +90,7 @@ RSpec.configure do |config|
config.include StubFeatureFlags
config.include StubGitlabCalls
config.include StubGitlabData
config.include AllowNextInstanceOf
config.include ExpectNextInstanceOf
config.include TestEnv
config.include Devise::Test::ControllerHelpers, type: :controller
......
# frozen_string_literal: true
module AllowNextInstanceOf
def allow_next_instance_of(klass, *new_args)
receive_new = receive(:new)
receive_new.with(*new_args) if new_args.any?
allow(klass).to receive_new
.and_wrap_original do |method, *original_args|
method.call(*original_args).tap do |instance|
yield(instance)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment