Commit 91693d40 authored by Arturo Herrero's avatar Arturo Herrero

Update RSpec helper methods to *_next_instance_of

Auto-correct some references in RSpec as:
- expect_any_instance_of -> expect_next_instance_of
- allow_any_instance_of -> allow_next_instance_of

Related to https://gitlab.com/gitlab-org/gitlab/issues/34997
parent 0491777b
...@@ -14,8 +14,9 @@ describe Admin::GroupsController do ...@@ -14,8 +14,9 @@ describe Admin::GroupsController do
subject { post :reset_runners_minutes, params: { id: group } } subject { post :reset_runners_minutes, params: { id: group } }
before do before do
allow_any_instance_of(ClearNamespaceSharedRunnersMinutesService) allow_next_instance_of(ClearNamespaceSharedRunnersMinutesService) do |instance|
.to receive(:execute).and_return(clear_runners_minutes_service_result) allow(instance).to receive(:execute).and_return(clear_runners_minutes_service_result)
end
end end
context 'when the reset is successful' do context 'when the reset is successful' do
......
...@@ -19,7 +19,9 @@ describe Admin::PushRulesController do ...@@ -19,7 +19,9 @@ describe Admin::PushRulesController do
end end
it 'updates sample push rule' do it 'updates sample push rule' do
expect_any_instance_of(PushRule).to receive(:update).with(ActionController::Parameters.new(params).permit!) expect_next_instance_of(PushRule) do |instance|
expect(instance).to receive(:update).with(ActionController::Parameters.new(params).permit!)
end
patch :update, params: { push_rule: params } patch :update, params: { push_rule: params }
......
...@@ -64,8 +64,9 @@ describe Admin::UsersController do ...@@ -64,8 +64,9 @@ describe Admin::UsersController do
subject { post :reset_runners_minutes, params: { id: user } } subject { post :reset_runners_minutes, params: { id: user } }
before do before do
allow_any_instance_of(ClearNamespaceSharedRunnersMinutesService) allow_next_instance_of(ClearNamespaceSharedRunnersMinutesService) do |instance|
.to receive(:execute).and_return(clear_runners_minutes_service_result) allow(instance).to receive(:execute).and_return(clear_runners_minutes_service_result)
end
end end
context 'when the reset is successful' do context 'when the reset is successful' do
......
...@@ -74,7 +74,9 @@ describe Analytics::ProductivityAnalyticsController do ...@@ -74,7 +74,9 @@ describe Analytics::ProductivityAnalyticsController do
before do before do
merge_requests = double merge_requests = double
allow_any_instance_of(ProductivityAnalyticsFinder).to receive(:execute).and_return(merge_requests) allow_next_instance_of(ProductivityAnalyticsFinder) do |instance|
allow(instance).to receive(:execute).and_return(merge_requests)
end
allow(ProductivityAnalytics) allow(ProductivityAnalytics)
.to receive(:new) .to receive(:new)
.with(merge_requests: merge_requests, sort: params[:sort]) .with(merge_requests: merge_requests, sort: params[:sort])
......
...@@ -10,8 +10,9 @@ describe Groups::DependencyProxyForContainersController do ...@@ -10,8 +10,9 @@ describe Groups::DependencyProxyForContainersController do
allow(Gitlab.config.dependency_proxy) allow(Gitlab.config.dependency_proxy)
.to receive(:enabled).and_return(true) .to receive(:enabled).and_return(true)
allow_any_instance_of(DependencyProxy::RequestTokenService) allow_next_instance_of(DependencyProxy::RequestTokenService) do |instance|
.to receive(:execute).and_return(token_response) allow(instance).to receive(:execute).and_return(token_response)
end
end end
describe 'GET #manifest' do describe 'GET #manifest' do
...@@ -19,8 +20,9 @@ describe Groups::DependencyProxyForContainersController do ...@@ -19,8 +20,9 @@ describe Groups::DependencyProxyForContainersController do
let(:pull_response) { { status: :success, manifest: manifest } } let(:pull_response) { { status: :success, manifest: manifest } }
before do before do
allow_any_instance_of(DependencyProxy::PullManifestService) allow_next_instance_of(DependencyProxy::PullManifestService) do |instance|
.to receive(:execute).and_return(pull_response) allow(instance).to receive(:execute).and_return(pull_response)
end
end end
context 'feature enabled' do context 'feature enabled' do
...@@ -87,8 +89,9 @@ describe Groups::DependencyProxyForContainersController do ...@@ -87,8 +89,9 @@ describe Groups::DependencyProxyForContainersController do
let(:blob_response) { { status: :success, blob: blob } } let(:blob_response) { { status: :success, blob: blob } }
before do before do
allow_any_instance_of(DependencyProxy::FindOrCreateBlobService) allow_next_instance_of(DependencyProxy::FindOrCreateBlobService) do |instance|
.to receive(:execute).and_return(blob_response) allow(instance).to receive(:execute).and_return(blob_response)
end
end end
context 'feature enabled' do context 'feature enabled' do
......
...@@ -12,7 +12,9 @@ describe Profiles::BillingsController do ...@@ -12,7 +12,9 @@ describe Profiles::BillingsController do
end end
it 'renders index with 200 status code' do it 'renders index with 200 status code' do
allow_any_instance_of(FetchSubscriptionPlansService).to receive(:execute) allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute)
end
sign_in(user) sign_in(user)
get :index get :index
...@@ -23,7 +25,9 @@ describe Profiles::BillingsController do ...@@ -23,7 +25,9 @@ describe Profiles::BillingsController do
it 'fetch subscription plans data from customers.gitlab.com' do it 'fetch subscription plans data from customers.gitlab.com' do
data = double data = double
expect_any_instance_of(FetchSubscriptionPlansService).to receive(:execute).and_return(data) expect_next_instance_of(FetchSubscriptionPlansService) do |instance|
expect(instance).to receive(:execute).and_return(data)
end
sign_in(user) sign_in(user)
get :index get :index
......
...@@ -14,7 +14,9 @@ describe Projects::ImportsController do ...@@ -14,7 +14,9 @@ describe Projects::ImportsController do
context 'POST #create' do context 'POST #create' do
context 'mirror user is not the current user' do context 'mirror user is not the current user' do
it 'only assigns the current user' do it 'only assigns the current user' do
allow_any_instance_of(EE::Project).to receive(:add_import_job) allow_next_instance_of(EE::Project) do |instance|
allow(instance).to receive(:add_import_job)
end
new_user = create(:user) new_user = create(:user)
project.add_maintainer(new_user) project.add_maintainer(new_user)
......
...@@ -25,7 +25,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do ...@@ -25,7 +25,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
allow_any_instance_of(Ci::Build).to receive(:merge_request).and_return(merge_request) allow_next_instance_of(Ci::Build) do |instance|
allow(instance).to receive(:merge_request).and_return(merge_request)
end
stub_application_setting(shared_runners_minutes: 2) stub_application_setting(shared_runners_minutes: 2)
...@@ -73,7 +75,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do ...@@ -73,7 +75,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
allow_any_instance_of(Ci::Build).to receive(:merge_request).and_return(merge_request) allow_next_instance_of(Ci::Build) do |instance|
allow(instance).to receive(:merge_request).and_return(merge_request)
end
stub_application_setting(shared_runners_minutes: 0) stub_application_setting(shared_runners_minutes: 0)
...@@ -98,7 +102,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do ...@@ -98,7 +102,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
allow_any_instance_of(Ci::Build).to receive(:merge_request).and_return(merge_request) allow_next_instance_of(Ci::Build) do |instance|
allow(instance).to receive(:merge_request).and_return(merge_request)
end
stub_application_setting(shared_runners_minutes: 2) stub_application_setting(shared_runners_minutes: 2)
......
...@@ -73,7 +73,9 @@ describe Projects::LogsController do ...@@ -73,7 +73,9 @@ describe Projects::LogsController do
before do before do
stub_licensed_features(pod_logs: true) stub_licensed_features(pod_logs: true)
allow_any_instance_of(::PodLogs::KubernetesService).to receive(:execute).and_return(service_result) allow_next_instance_of(::PodLogs::KubernetesService) do |instance|
allow(instance).to receive(:execute).and_return(service_result)
end
end end
shared_examples 'resource not found' do |message| shared_examples 'resource not found' do |message|
......
...@@ -107,8 +107,9 @@ describe Projects::WebIdeTerminalsController do ...@@ -107,8 +107,9 @@ describe Projects::WebIdeTerminalsController do
let(:result) { { status: :success } } let(:result) { { status: :success } }
before do before do
allow_any_instance_of(::Ci::WebIdeConfigService) allow_next_instance_of(::Ci::WebIdeConfigService) do |instance|
.to receive(:execute).and_return(result) allow(instance).to receive(:execute).and_return(result)
end
post :check_config, params: { post :check_config, params: {
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
...@@ -145,8 +146,9 @@ describe Projects::WebIdeTerminalsController do ...@@ -145,8 +146,9 @@ describe Projects::WebIdeTerminalsController do
let(:pipeline) { build.pipeline } let(:pipeline) { build.pipeline }
before do before do
allow_any_instance_of(::Ci::CreateWebIdeTerminalService) allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance|
.to receive(:execute).and_return(status: :success, pipeline: pipeline) allow(instance).to receive(:execute).and_return(status: :success, pipeline: pipeline)
end
subject subject
end end
...@@ -169,8 +171,9 @@ describe Projects::WebIdeTerminalsController do ...@@ -169,8 +171,9 @@ describe Projects::WebIdeTerminalsController do
let(:user) { admin } let(:user) { admin }
it 'returns 400' do it 'returns 400' do
allow_any_instance_of(::Ci::CreateWebIdeTerminalService) allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance|
.to receive(:execute).and_return(status: :error, message: 'foobar') allow(instance).to receive(:execute).and_return(status: :error, message: 'foobar')
end
subject subject
......
...@@ -11,7 +11,9 @@ describe Boards::UsersFinder do ...@@ -11,7 +11,9 @@ describe Boards::UsersFinder do
let(:board) { create(:board, project: project) } let(:board) { create(:board, project: project) }
it 'requests correct relations' do it 'requests correct relations' do
expect_any_instance_of(MembersFinder).to receive(:execute).with(include_relations: [:direct, :descendants, :inherited]).and_call_original expect_next_instance_of(MembersFinder) do |instance|
expect(instance).to receive(:execute).with(include_relations: [:direct, :descendants, :inherited]).and_call_original
end
subject.execute subject.execute
end end
...@@ -34,7 +36,9 @@ describe Boards::UsersFinder do ...@@ -34,7 +36,9 @@ describe Boards::UsersFinder do
end end
it 'requests correct relations' do it 'requests correct relations' do
expect_any_instance_of(GroupMembersFinder).to receive(:execute).with(include_relations: [:direct, :descendants, :inherited]).and_call_original expect_next_instance_of(GroupMembersFinder) do |instance|
expect(instance).to receive(:execute).with(include_relations: [:direct, :descendants, :inherited]).and_call_original
end
subject.execute subject.execute
end end
......
...@@ -36,7 +36,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -36,7 +36,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
context 'counts all the things' do context 'counts all the things' do
describe '#count_syncable' do describe '#count_syncable' do
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -82,7 +84,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -82,7 +84,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_4.id) create(:geo_lfs_object_registry, lfs_object_id: lfs_object_4.id)
create(:geo_upload_registry, :avatar) create(:geo_upload_registry, :avatar)
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -129,7 +133,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -129,7 +133,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_5.id) create(:geo_lfs_object_registry, lfs_object_id: lfs_object_5.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_1.id) create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_1.id)
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -146,7 +152,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -146,7 +152,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) } let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
end end
it 'counts LFS objects that has been synced' do it 'counts LFS objects that has been synced' do
...@@ -188,7 +196,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -188,7 +196,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_5.id) create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_5.id)
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_remote_1.id) create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_remote_1.id)
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2)
...@@ -233,7 +243,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -233,7 +243,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_3.id, missing_on_primary: true) create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_3.id, missing_on_primary: true)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_1.id, missing_on_primary: true) create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_1.id, missing_on_primary: true)
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2)
...@@ -451,7 +463,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -451,7 +463,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_3.id) create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_3.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_4.id) create(:geo_lfs_object_registry, lfs_object_id: lfs_object_4.id)
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -543,7 +557,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -543,7 +557,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) } let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_remote_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_remote_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_remote_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_remote_2)
...@@ -565,7 +581,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -565,7 +581,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) } let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_remote_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_remote_1)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_remote_2) create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_remote_2)
...@@ -612,7 +630,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -612,7 +630,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) } let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_1) create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -631,7 +651,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -631,7 +651,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) } let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_1) create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -664,7 +686,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -664,7 +686,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) } let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
...@@ -682,7 +706,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -682,7 +706,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) } let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_next_instance_of(LfsObjectsProject) do |instance|
allow(instance).to receive(:update_project_statistics).and_return(nil)
end
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1) create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2) create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
......
...@@ -23,7 +23,9 @@ describe SubscriptionsHelper do ...@@ -23,7 +23,9 @@ describe SubscriptionsHelper do
before do before do
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id') allow(helper).to receive(:params).and_return(plan_id: 'bronze_id')
allow_any_instance_of(FetchSubscriptionPlansService).to receive(:execute).and_return(raw_plan_data) allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute).and_return(raw_plan_data)
end
end end
describe '#subscription_data' do describe '#subscription_data' do
......
...@@ -27,7 +27,9 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do ...@@ -27,7 +27,9 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
end end
it 'calls remove_keys_not_found_in_db on Gitlab::Shell' do it 'calls remove_keys_not_found_in_db on Gitlab::Shell' do
expect_any_instance_of(Gitlab::Shell).to receive(:remove_keys_not_found_in_db) expect_next_instance_of(Gitlab::Shell) do |instance|
expect(instance).to receive(:remove_keys_not_found_in_db)
end
subject subject
end end
end end
...@@ -63,7 +65,9 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do ...@@ -63,7 +65,9 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
describe '#remove_keys_not_found_in_db' do describe '#remove_keys_not_found_in_db' do
it 'calls remove_keys_not_found_in_db on Gitlab::Shell' do it 'calls remove_keys_not_found_in_db on Gitlab::Shell' do
expect_any_instance_of(Gitlab::Shell).to receive(:remove_keys_not_found_in_db) expect_next_instance_of(Gitlab::Shell) do |instance|
expect(instance).to receive(:remove_keys_not_found_in_db)
end
background_migration.remove_keys_not_found_in_db background_migration.remove_keys_not_found_in_db
end end
end end
......
...@@ -38,7 +38,9 @@ describe Gitlab::Auth::GroupSaml::FailureHandler do ...@@ -38,7 +38,9 @@ describe Gitlab::Auth::GroupSaml::FailureHandler do
callback_path = callback_group_saml_providers_path(group) callback_path = callback_group_saml_providers_path(group)
env = failure_env(callback_path, strategy) env = failure_env(callback_path, strategy)
expect_any_instance_of(Groups::OmniauthCallbacksController).to receive(:failure).and_call_original expect_next_instance_of(Groups::OmniauthCallbacksController) do |instance|
expect(instance).to receive(:failure).and_call_original
end
subject.call(env) subject.call(env)
end end
......
...@@ -154,7 +154,9 @@ describe Gitlab::Auth::LDAP::Person do ...@@ -154,7 +154,9 @@ describe Gitlab::Auth::LDAP::Person do
subject { described_class.new(entry, 'ldapmain') } subject { described_class.new(entry, 'ldapmain') }
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(sync_ssh_keys: ssh_key_attribute_name) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(sync_ssh_keys: ssh_key_attribute_name)
end
end end
context 'when the SSH key is literal' do context 'when the SSH key is literal' do
......
...@@ -13,7 +13,9 @@ describe Gitlab::Checks::ChangeAccess do ...@@ -13,7 +13,9 @@ describe Gitlab::Checks::ChangeAccess do
it_behaves_like 'check ignored when push rule unlicensed' it_behaves_like 'check ignored when push rule unlicensed'
it 'calls push rules validators' do it 'calls push rules validators' do
expect_any_instance_of(EE::Gitlab::Checks::PushRuleCheck).to receive(:validate!) expect_next_instance_of(EE::Gitlab::Checks::PushRuleCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.exec subject.exec
end end
......
...@@ -18,9 +18,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do ...@@ -18,9 +18,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do
subject { described_class.new('localhost').resolve } subject { described_class.new('localhost').resolve }
it 'looks the nameserver up in the hosts file' do it 'looks the nameserver up in the hosts file' do
allow_any_instance_of(Resolv::Hosts).to receive(:getaddress) allow_next_instance_of(Resolv::Hosts) do |instance|
.with('localhost') allow(instance).to receive(:getaddress).with('localhost').and_return('127.0.0.2')
.and_return('127.0.0.2') end
expect(subject).to eq(ip_addr) expect(subject).to eq(ip_addr)
end end
...@@ -30,9 +30,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do ...@@ -30,9 +30,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do
resource = double(:resource, address: ip_addr) resource = double(:resource, address: ip_addr)
packet = double(:packet, answer: [resource]) packet = double(:packet, answer: [resource])
allow_any_instance_of(Resolv::Hosts).to receive(:getaddress) allow_next_instance_of(Resolv::Hosts) do |instance|
.with('localhost') allow(instance).to receive(:getaddress).with('localhost').and_raise(Resolv::ResolvError)
.and_raise(Resolv::ResolvError) end
allow(Net::DNS::Resolver).to receive(:start) allow(Net::DNS::Resolver).to receive(:start)
.with('localhost', Net::DNS::A) .with('localhost', Net::DNS::A)
...@@ -43,9 +43,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do ...@@ -43,9 +43,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do
context 'when nameserver is not in DNS' do context 'when nameserver is not in DNS' do
it 'raises an exception' do it 'raises an exception' do
allow_any_instance_of(Resolv::Hosts).to receive(:getaddress) allow_next_instance_of(Resolv::Hosts) do |instance|
.with('localhost') allow(instance).to receive(:getaddress).with('localhost').and_raise(Resolv::ResolvError)
.and_raise(Resolv::ResolvError) end
allow(Net::DNS::Resolver).to receive(:start) allow(Net::DNS::Resolver).to receive(:start)
.with('localhost', Net::DNS::A) .with('localhost', Net::DNS::A)
......
...@@ -23,7 +23,9 @@ describe Gitlab::Email::Handler::CreateNoteHandler do ...@@ -23,7 +23,9 @@ describe Gitlab::Email::Handler::CreateNoteHandler do
context "when the note could not be saved" do context "when the note could not be saved" do
before do before do
allow_any_instance_of(Note).to receive(:persisted?).and_return(false) allow_next_instance_of(Note) do |instance|
allow(instance).to receive(:persisted?).and_return(false)
end
end end
it "raises an InvalidNoteError" do it "raises an InvalidNoteError" do
......
...@@ -181,8 +181,9 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do ...@@ -181,8 +181,9 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do
context 'when there is no from address' do context 'when there is no from address' do
before do before do
allow_any_instance_of(described_class).to receive(:from_address) allow_next_instance_of(described_class) do |instance|
.and_return(nil) allow(instance).to receive(:from_address).and_return(nil)
end
end end
it "creates a new issue" do it "creates a new issue" do
......
...@@ -53,7 +53,9 @@ describe Gitlab::Geo::JwtRequestDecoder do ...@@ -53,7 +53,9 @@ describe Gitlab::Geo::JwtRequestDecoder do
end end
it 'raises invalid decryption key error' do it 'raises invalid decryption key error' do
allow_any_instance_of(described_class).to receive(:decode_auth_header).and_raise(Gitlab::Geo::InvalidDecryptionKeyError) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:decode_auth_header).and_raise(Gitlab::Geo::InvalidDecryptionKeyError)
end
expect { subject.decode }.to raise_error(Gitlab::Geo::InvalidDecryptionKeyError) expect { subject.decode }.to raise_error(Gitlab::Geo::InvalidDecryptionKeyError)
end end
......
...@@ -22,8 +22,9 @@ describe Gitlab::Geo::Oauth::LogoutState do ...@@ -22,8 +22,9 @@ describe Gitlab::Geo::Oauth::LogoutState do
end end
it 'returns nil when encryption fails' do it 'returns nil when encryption fails' do
allow_any_instance_of(OpenSSL::Cipher::AES256) allow_next_instance_of(OpenSSL::Cipher::AES256) do |instance|
.to receive(:final) { raise OpenSSL::OpenSSLError } allow(instance).to receive(:final) { raise OpenSSL::OpenSSLError }
end
subject = described_class.new(token: access_token, return_to: return_to) subject = described_class.new(token: access_token, return_to: return_to)
...@@ -77,8 +78,9 @@ describe Gitlab::Geo::Oauth::LogoutState do ...@@ -77,8 +78,9 @@ describe Gitlab::Geo::Oauth::LogoutState do
end end
it 'returns nil when decryption fails' do it 'returns nil when decryption fails' do
allow_any_instance_of(OpenSSL::Cipher::AES256) allow_next_instance_of(OpenSSL::Cipher::AES256) do |instance|
.to receive(:final) { raise OpenSSL::OpenSSLError } allow(instance).to receive(:final) { raise OpenSSL::OpenSSLError }
end
subject = described_class.new(salt: salt, tag: tag, token: encrypted_token, return_to: return_to) subject = described_class.new(salt: salt, tag: tag, token: encrypted_token, return_to: return_to)
......
...@@ -32,9 +32,9 @@ describe Gitlab::Geo::Oauth::LogoutToken do ...@@ -32,9 +32,9 @@ describe Gitlab::Geo::Oauth::LogoutToken do
end end
it 'returns false when token has an incorrect encoding' do it 'returns false when token has an incorrect encoding' do
allow_any_instance_of(Gitlab::Geo::Oauth::LogoutState) allow_next_instance_of(Gitlab::Geo::Oauth::LogoutState) do |instance|
.to receive(:decode) allow(instance).to receive(:decode).and_return("\xD800\xD801\xD802")
.and_return("\xD800\xD801\xD802") end
token = described_class.new(user, state) token = described_class.new(user, state)
......
...@@ -58,8 +58,9 @@ describe Gitlab::Geo::Oauth::Session, :geo do ...@@ -58,8 +58,9 @@ describe Gitlab::Geo::Oauth::Session, :geo do
api_response = double(parsed: true) api_response = double(parsed: true)
expect_any_instance_of(OAuth2::AccessToken) expect_next_instance_of(OAuth2::AccessToken) do |instance|
.to receive(:get).with(%r{^#{api_url}}).and_return(api_response) expect(instance).to receive(:get).with(%r{^#{api_url}}).and_return(api_response)
end
subject.authenticate('any token') subject.authenticate('any token')
end end
......
...@@ -11,8 +11,9 @@ describe Gitlab::Geo::Replication::JobArtifactDownloader, :geo do ...@@ -11,8 +11,9 @@ describe Gitlab::Geo::Replication::JobArtifactDownloader, :geo do
downloader = described_class.new(:job_artifact, job_artifact.id) downloader = described_class.new(:job_artifact, job_artifact.id)
result = Gitlab::Geo::Replication::BaseTransfer::Result.new(success: true, bytes_downloaded: 1) result = Gitlab::Geo::Replication::BaseTransfer::Result.new(success: true, bytes_downloaded: 1)
allow_any_instance_of(Gitlab::Geo::Replication::JobArtifactTransfer) allow_next_instance_of(Gitlab::Geo::Replication::JobArtifactTransfer) do |instance|
.to receive(:download_from_primary).and_return(result) allow(instance).to receive(:download_from_primary).and_return(result)
end
expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result) expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result)
end end
......
...@@ -11,8 +11,9 @@ describe Gitlab::Geo::Replication::LfsDownloader, :geo do ...@@ -11,8 +11,9 @@ describe Gitlab::Geo::Replication::LfsDownloader, :geo do
downloader = described_class.new(:lfs, lfs_object.id) downloader = described_class.new(:lfs, lfs_object.id)
result = Gitlab::Geo::Replication::BaseTransfer::Result.new(success: true, bytes_downloaded: 1) result = Gitlab::Geo::Replication::BaseTransfer::Result.new(success: true, bytes_downloaded: 1)
allow_any_instance_of(Gitlab::Geo::Replication::LfsTransfer) allow_next_instance_of(Gitlab::Geo::Replication::LfsTransfer) do |instance|
.to receive(:download_from_primary).and_return(result) allow(instance).to receive(:download_from_primary).and_return(result)
end
expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result) expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result)
end end
......
...@@ -68,7 +68,9 @@ describe Gitlab::GitAccess do ...@@ -68,7 +68,9 @@ describe Gitlab::GitAccess do
bad_commit = double("Commit", safe_message: 'Some change').as_null_object bad_commit = double("Commit", safe_message: 'Some change').as_null_object
ref_object = double(name: 'heads/master') ref_object = double(name: 'heads/master')
allow(bad_commit).to receive(:refs).and_return([ref_object]) allow(bad_commit).to receive(:refs).and_return([ref_object])
allow_any_instance_of(Repository).to receive(:commits_between).and_return([bad_commit]) allow_next_instance_of(Repository) do |instance|
allow(instance).to receive(:commits_between).and_return([bad_commit])
end
project.create_push_rule(commit_message_regex: "Change some files") project.create_push_rule(commit_message_regex: "Change some files")
...@@ -324,7 +326,9 @@ describe Gitlab::GitAccess do ...@@ -324,7 +326,9 @@ describe Gitlab::GitAccess do
stub_licensed_features(geo: true) stub_licensed_features(geo: true)
stub_current_geo_node(create(:geo_node)) stub_current_geo_node(create(:geo_node))
allow_any_instance_of(Gitlab::Geo::HealthCheck).to receive(:db_replication_lag_seconds).and_return(current_replication_lag) allow_next_instance_of(Gitlab::Geo::HealthCheck) do |instance|
allow(instance).to receive(:db_replication_lag_seconds).and_return(current_replication_lag)
end
end end
context 'that has no DB replication lag' do context 'that has no DB replication lag' do
......
...@@ -20,7 +20,9 @@ describe Gitlab::ImportExport::DesignRepoRestorer do ...@@ -20,7 +20,9 @@ describe Gitlab::ImportExport::DesignRepoRestorer do
end end
before do before do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow(instance).to receive(:storage_path).and_return(export_path)
end
bundler.save bundler.save
end end
......
...@@ -13,7 +13,9 @@ describe Gitlab::ImportExport::DesignRepoSaver do ...@@ -13,7 +13,9 @@ describe Gitlab::ImportExport::DesignRepoSaver do
before do before do
project.add_maintainer(user) project.add_maintainer(user)
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow(instance).to receive(:storage_path).and_return(export_path)
end
end end
after do after do
......
...@@ -12,8 +12,12 @@ describe Gitlab::ImportExport::Importer do ...@@ -12,8 +12,12 @@ describe Gitlab::ImportExport::Importer do
subject(:importer) { described_class.new(project) } subject(:importer) { described_class.new(project) }
before do before do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(test_path) allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow_any_instance_of(Gitlab::ImportExport::FileImporter).to receive(:remove_import_file) allow(instance).to receive(:storage_path).and_return(test_path)
end
allow_next_instance_of(Gitlab::ImportExport::FileImporter) do |instance|
allow(instance).to receive(:remove_import_file)
end
stub_uploads_object_storage(FileUploader) stub_uploads_object_storage(FileUploader)
FileUtils.mkdir_p(shared.export_path) FileUtils.mkdir_p(shared.export_path)
......
...@@ -13,7 +13,9 @@ describe Gitlab::Kerberos::Authentication do ...@@ -13,7 +13,9 @@ describe Gitlab::Kerberos::Authentication do
describe '.kerberos_default_realm' do describe '.kerberos_default_realm' do
it "returns the default realm exposed by the Kerberos library" do it "returns the default realm exposed by the Kerberos library" do
allow_any_instance_of(::Krb5Auth::Krb5).to receive_messages(get_default_realm: "FOO.COM") allow_next_instance_of(::Krb5Auth::Krb5) do |instance|
allow(instance).to receive_messages(get_default_realm: "FOO.COM")
end
expect(described_class.kerberos_default_realm).to eq("FOO.COM") expect(described_class.kerberos_default_realm).to eq("FOO.COM")
end end
...@@ -26,20 +28,26 @@ describe Gitlab::Kerberos::Authentication do ...@@ -26,20 +28,26 @@ describe Gitlab::Kerberos::Authentication do
end end
it "finds the user if authentication is successful (login without kerberos realm)" do it "finds the user if authentication is successful (login without kerberos realm)" do
allow_any_instance_of(::Krb5Auth::Krb5).to receive_messages(get_init_creds_password: true, get_default_principal: 'gitlab@FOO.COM') allow_next_instance_of(::Krb5Auth::Krb5) do |instance|
allow(instance).to receive_messages(get_init_creds_password: true, get_default_principal: 'gitlab@FOO.COM')
end
expect(described_class.login('gitlab', password)).to be_truthy expect(described_class.login('gitlab', password)).to be_truthy
end end
it "finds the user if authentication is successful (login with a kerberos realm)" do it "finds the user if authentication is successful (login with a kerberos realm)" do
allow_any_instance_of(::Krb5Auth::Krb5).to receive_messages(get_init_creds_password: true, get_default_principal: 'gitlab@FOO.COM') allow_next_instance_of(::Krb5Auth::Krb5) do |instance|
allow(instance).to receive_messages(get_init_creds_password: true, get_default_principal: 'gitlab@FOO.COM')
end
expect(described_class.login('gitlab@FOO.COM', password)).to be_truthy expect(described_class.login('gitlab@FOO.COM', password)).to be_truthy
end end
it "returns false if there is no such user in kerberos" do it "returns false if there is no such user in kerberos" do
kerberos_login = "some-login" kerberos_login = "some-login"
allow_any_instance_of(::Krb5Auth::Krb5).to receive_messages(get_init_creds_password: true, get_default_principal: 'some-login@FOO.COM') allow_next_instance_of(::Krb5Auth::Krb5) do |instance|
allow(instance).to receive_messages(get_init_creds_password: true, get_default_principal: 'some-login@FOO.COM')
end
expect(described_class.login(kerberos_login, password)).to be_falsy expect(described_class.login(kerberos_login, password)).to be_falsy
end end
......
...@@ -32,8 +32,9 @@ describe EE::UsageStatistics do ...@@ -32,8 +32,9 @@ describe EE::UsageStatistics do
context 'the count query times out' do context 'the count query times out' do
before do before do
allow_any_instance_of(ActiveRecord::Relation) allow_next_instance_of(ActiveRecord::Relation) do |instance|
.to receive(:count).and_raise(ActiveRecord::StatementInvalid.new('')) allow(instance).to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
end
end end
it 'does not raise an error' do it 'does not raise an error' do
......
...@@ -39,7 +39,9 @@ RSpec.describe Geo::DeletedProject, type: :model do ...@@ -39,7 +39,9 @@ RSpec.describe Geo::DeletedProject, type: :model do
end end
it 'picks storage from ApplicationSetting when value is not initialized' do it 'picks storage from ApplicationSetting when value is not initialized' do
allow_any_instance_of(ApplicationSetting).to receive(:pick_repository_storage).and_return('bar') allow_next_instance_of(ApplicationSetting) do |instance|
allow(instance).to receive(:pick_repository_storage).and_return('bar')
end
subject = described_class.new(id: 1, name: 'sample', disk_path: 'root/sample', repository_storage: nil) subject = described_class.new(id: 1, name: 'sample', disk_path: 'root/sample', repository_storage: nil)
......
...@@ -70,7 +70,9 @@ describe API::Geo do ...@@ -70,7 +70,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers } let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
before do before do
allow_any_instance_of(Gitlab::Geo::TransferRequest).to receive(:requesting_node).and_return(secondary_node) allow_next_instance_of(Gitlab::Geo::TransferRequest) do |instance|
allow(instance).to receive(:requesting_node).and_return(secondary_node)
end
end end
it 'responds with 401 with invalid auth header' do it 'responds with 401 with invalid auth header' do
...@@ -109,7 +111,9 @@ describe API::Geo do ...@@ -109,7 +111,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers } let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
before do before do
allow_any_instance_of(Gitlab::Geo::TransferRequest).to receive(:requesting_node).and_return(secondary_node) allow_next_instance_of(Gitlab::Geo::TransferRequest) do |instance|
allow(instance).to receive(:requesting_node).and_return(secondary_node)
end
end end
it 'responds with 401 with invalid auth header' do it 'responds with 401 with invalid auth header' do
...@@ -160,7 +164,9 @@ describe API::Geo do ...@@ -160,7 +164,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers } let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
before do before do
allow_any_instance_of(Gitlab::Geo::TransferRequest).to receive(:requesting_node).and_return(secondary_node) allow_next_instance_of(Gitlab::Geo::TransferRequest) do |instance|
allow(instance).to receive(:requesting_node).and_return(secondary_node)
end
FileUploader.new(project).store!(fixture_file_upload('spec/fixtures/dk.png', 'image/png')) FileUploader.new(project).store!(fixture_file_upload('spec/fixtures/dk.png', 'image/png'))
end end
...@@ -212,7 +218,9 @@ describe API::Geo do ...@@ -212,7 +218,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers } let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
before do before do
allow_any_instance_of(Gitlab::Geo::TransferRequest).to receive(:requesting_node).and_return(secondary_node) allow_next_instance_of(Gitlab::Geo::TransferRequest) do |instance|
allow(instance).to receive(:requesting_node).and_return(secondary_node)
end
end end
it 'responds with 401 with invalid auth header' do it 'responds with 401 with invalid auth header' do
...@@ -311,7 +319,9 @@ describe API::Geo do ...@@ -311,7 +319,9 @@ describe API::Geo do
end end
it 'responds with 401 when the db_key_base is wrong' do it 'responds with 401 when the db_key_base is wrong' do
allow_any_instance_of(Gitlab::Geo::JwtRequestDecoder).to receive(:decode).and_raise(Gitlab::Geo::InvalidDecryptionKeyError) allow_next_instance_of(Gitlab::Geo::JwtRequestDecoder) do |instance|
allow(instance).to receive(:decode).and_raise(Gitlab::Geo::InvalidDecryptionKeyError)
end
request request
......
...@@ -38,7 +38,9 @@ describe API::Internal::Base do ...@@ -38,7 +38,9 @@ describe API::Internal::Base do
before do before do
project.add_developer(user) project.add_developer(user)
allow(described_class).to receive(:identify).and_return(user) allow(described_class).to receive(:identify).and_return(user)
allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(user) allow_next_instance_of(Gitlab::Identifier) do |instance|
allow(instance).to receive(:identify).and_return(user)
end
stub_current_geo_node(primary_node) stub_current_geo_node(primary_node)
end end
......
...@@ -11,7 +11,9 @@ describe API::ProjectImport do ...@@ -11,7 +11,9 @@ describe API::ProjectImport do
let(:namespace) { create(:group) } let(:namespace) { create(:group) }
before do before do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow(instance).to receive(:storage_path).and_return(export_path)
end
namespace.add_owner(user) namespace.add_owner(user)
end end
......
...@@ -37,7 +37,9 @@ describe API::ProjectMirror do ...@@ -37,7 +37,9 @@ describe API::ProjectMirror do
context 'when project is mirrored' do context 'when project is mirrored' do
before do before do
allow_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_return(status: :success) allow_next_instance_of(Projects::UpdateMirrorService) do |instance|
allow(instance).to receive(:execute).and_return(status: :success)
end
end end
context 'when "pull_request" event is received' do context 'when "pull_request" event is received' do
......
...@@ -86,7 +86,9 @@ describe 'Rack Attack EE throttles' do ...@@ -86,7 +86,9 @@ describe 'Rack Attack EE throttles' do
describe 'requests to prometheus alert notify endpoint with oauth token' do describe 'requests to prometheus alert notify endpoint with oauth token' do
before do before do
allow_any_instance_of(Projects::Prometheus::Alerts::NotifyService).to receive(:execute).and_return true allow_next_instance_of(Projects::Prometheus::Alerts::NotifyService) do |instance|
allow(instance).to receive(:execute).and_return true
end
end end
it_behaves_like 'incident management rate limiting' do it_behaves_like 'incident management rate limiting' do
...@@ -96,7 +98,9 @@ describe 'Rack Attack EE throttles' do ...@@ -96,7 +98,9 @@ describe 'Rack Attack EE throttles' do
describe 'requests to generic alert notify endpoint with oauth token' do describe 'requests to generic alert notify endpoint with oauth token' do
before do before do
allow_any_instance_of(Projects::Alerting::NotifyService).to receive(:execute).and_return double(success?: true) allow_next_instance_of(Projects::Alerting::NotifyService) do |instance|
allow(instance).to receive(:execute).and_return double(success?: true)
end
end end
it_behaves_like 'incident management rate limiting' do it_behaves_like 'incident management rate limiting' do
......
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