Commit 9ea6f8ed authored by Michael Kozono's avatar Michael Kozono

Merge branch 'rspec-next-instance-of' into 'master'

Update RSpec helper methods to *_next_instance_of

See merge request gitlab-org/gitlab!25798
parents e12074f0 91693d40
......@@ -14,8 +14,9 @@ describe Admin::GroupsController do
subject { post :reset_runners_minutes, params: { id: group } }
before do
allow_any_instance_of(ClearNamespaceSharedRunnersMinutesService)
.to receive(:execute).and_return(clear_runners_minutes_service_result)
allow_next_instance_of(ClearNamespaceSharedRunnersMinutesService) do |instance|
allow(instance).to receive(:execute).and_return(clear_runners_minutes_service_result)
end
end
context 'when the reset is successful' do
......
......@@ -19,7 +19,9 @@ describe Admin::PushRulesController do
end
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 }
......
......@@ -64,8 +64,9 @@ describe Admin::UsersController do
subject { post :reset_runners_minutes, params: { id: user } }
before do
allow_any_instance_of(ClearNamespaceSharedRunnersMinutesService)
.to receive(:execute).and_return(clear_runners_minutes_service_result)
allow_next_instance_of(ClearNamespaceSharedRunnersMinutesService) do |instance|
allow(instance).to receive(:execute).and_return(clear_runners_minutes_service_result)
end
end
context 'when the reset is successful' do
......
......@@ -74,7 +74,9 @@ describe Analytics::ProductivityAnalyticsController do
before do
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)
.to receive(:new)
.with(merge_requests: merge_requests, sort: params[:sort])
......
......@@ -10,8 +10,9 @@ describe Groups::DependencyProxyForContainersController do
allow(Gitlab.config.dependency_proxy)
.to receive(:enabled).and_return(true)
allow_any_instance_of(DependencyProxy::RequestTokenService)
.to receive(:execute).and_return(token_response)
allow_next_instance_of(DependencyProxy::RequestTokenService) do |instance|
allow(instance).to receive(:execute).and_return(token_response)
end
end
describe 'GET #manifest' do
......@@ -19,8 +20,9 @@ describe Groups::DependencyProxyForContainersController do
let(:pull_response) { { status: :success, manifest: manifest } }
before do
allow_any_instance_of(DependencyProxy::PullManifestService)
.to receive(:execute).and_return(pull_response)
allow_next_instance_of(DependencyProxy::PullManifestService) do |instance|
allow(instance).to receive(:execute).and_return(pull_response)
end
end
context 'feature enabled' do
......@@ -87,8 +89,9 @@ describe Groups::DependencyProxyForContainersController do
let(:blob_response) { { status: :success, blob: blob } }
before do
allow_any_instance_of(DependencyProxy::FindOrCreateBlobService)
.to receive(:execute).and_return(blob_response)
allow_next_instance_of(DependencyProxy::FindOrCreateBlobService) do |instance|
allow(instance).to receive(:execute).and_return(blob_response)
end
end
context 'feature enabled' do
......
......@@ -12,7 +12,9 @@ describe Profiles::BillingsController do
end
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)
get :index
......@@ -23,7 +25,9 @@ describe Profiles::BillingsController do
it 'fetch subscription plans data from customers.gitlab.com' do
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)
get :index
......
......@@ -14,7 +14,9 @@ describe Projects::ImportsController do
context 'POST #create' do
context 'mirror user is not 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)
project.add_maintainer(new_user)
......
......@@ -25,7 +25,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
project.add_developer(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)
......@@ -73,7 +75,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
project.add_developer(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)
......@@ -98,7 +102,9 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
project.add_developer(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)
......
......@@ -73,7 +73,9 @@ describe Projects::LogsController do
before do
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
shared_examples 'resource not found' do |message|
......
......@@ -107,8 +107,9 @@ describe Projects::WebIdeTerminalsController do
let(:result) { { status: :success } }
before do
allow_any_instance_of(::Ci::WebIdeConfigService)
.to receive(:execute).and_return(result)
allow_next_instance_of(::Ci::WebIdeConfigService) do |instance|
allow(instance).to receive(:execute).and_return(result)
end
post :check_config, params: {
namespace_id: project.namespace.to_param,
......@@ -145,8 +146,9 @@ describe Projects::WebIdeTerminalsController do
let(:pipeline) { build.pipeline }
before do
allow_any_instance_of(::Ci::CreateWebIdeTerminalService)
.to receive(:execute).and_return(status: :success, pipeline: pipeline)
allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance|
allow(instance).to receive(:execute).and_return(status: :success, pipeline: pipeline)
end
subject
end
......@@ -169,8 +171,9 @@ describe Projects::WebIdeTerminalsController do
let(:user) { admin }
it 'returns 400' do
allow_any_instance_of(::Ci::CreateWebIdeTerminalService)
.to receive(:execute).and_return(status: :error, message: 'foobar')
allow_next_instance_of(::Ci::CreateWebIdeTerminalService) do |instance|
allow(instance).to receive(:execute).and_return(status: :error, message: 'foobar')
end
subject
......
......@@ -11,7 +11,9 @@ describe Boards::UsersFinder do
let(:board) { create(:board, project: project) }
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
end
......@@ -34,7 +36,9 @@ describe Boards::UsersFinder do
end
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
end
......
......@@ -36,7 +36,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
context 'counts all the things' do
describe '#count_syncable' 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_in_nested_group, lfs_object: lfs_object_2)
......@@ -82,7 +84,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_4.id)
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_in_nested_group, lfs_object: lfs_object_2)
......@@ -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_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_in_nested_group, lfs_object: lfs_object_2)
......@@ -146,7 +152,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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
it 'counts LFS objects that has been synced' 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_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_2)
......@@ -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, 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_2)
......@@ -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, 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_in_nested_group, lfs_object: lfs_object_2)
......@@ -543,7 +557,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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_in_nested_group, lfs_object: lfs_object_remote_2)
......@@ -565,7 +581,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
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: project_broken_storage, lfs_object: lfs_object_remote_2)
......@@ -612,7 +630,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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: synced_project_in_nested_group, lfs_object: lfs_object_2)
......@@ -631,7 +651,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
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: synced_project_in_nested_group, lfs_object: lfs_object_2)
......@@ -664,7 +686,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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_in_nested_group, lfs_object: lfs_object_2)
......@@ -682,7 +706,9 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
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_in_nested_group, lfs_object: lfs_object_2)
......
......@@ -23,7 +23,9 @@ describe SubscriptionsHelper do
before do
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
describe '#subscription_data' do
......
......@@ -27,7 +27,9 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
end
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
end
end
......@@ -63,7 +65,9 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
describe '#remove_keys_not_found_in_db' 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
end
end
......
......@@ -38,7 +38,9 @@ describe Gitlab::Auth::GroupSaml::FailureHandler do
callback_path = callback_group_saml_providers_path(group)
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)
end
......
......@@ -154,7 +154,9 @@ describe Gitlab::Auth::LDAP::Person do
subject { described_class.new(entry, 'ldapmain') }
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
context 'when the SSH key is literal' do
......
......@@ -13,7 +13,9 @@ describe Gitlab::Checks::ChangeAccess do
it_behaves_like 'check ignored when push rule unlicensed'
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
end
......
......@@ -18,9 +18,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do
subject { described_class.new('localhost').resolve }
it 'looks the nameserver up in the hosts file' do
allow_any_instance_of(Resolv::Hosts).to receive(:getaddress)
.with('localhost')
.and_return('127.0.0.2')
allow_next_instance_of(Resolv::Hosts) do |instance|
allow(instance).to receive(:getaddress).with('localhost').and_return('127.0.0.2')
end
expect(subject).to eq(ip_addr)
end
......@@ -30,9 +30,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do
resource = double(:resource, address: ip_addr)
packet = double(:packet, answer: [resource])
allow_any_instance_of(Resolv::Hosts).to receive(:getaddress)
.with('localhost')
.and_raise(Resolv::ResolvError)
allow_next_instance_of(Resolv::Hosts) do |instance|
allow(instance).to receive(:getaddress).with('localhost').and_raise(Resolv::ResolvError)
end
allow(Net::DNS::Resolver).to receive(:start)
.with('localhost', Net::DNS::A)
......@@ -43,9 +43,9 @@ describe Gitlab::Database::LoadBalancing::Resolver do
context 'when nameserver is not in DNS' do
it 'raises an exception' do
allow_any_instance_of(Resolv::Hosts).to receive(:getaddress)
.with('localhost')
.and_raise(Resolv::ResolvError)
allow_next_instance_of(Resolv::Hosts) do |instance|
allow(instance).to receive(:getaddress).with('localhost').and_raise(Resolv::ResolvError)
end
allow(Net::DNS::Resolver).to receive(:start)
.with('localhost', Net::DNS::A)
......
......@@ -23,7 +23,9 @@ describe Gitlab::Email::Handler::CreateNoteHandler do
context "when the note could not be saved" 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
it "raises an InvalidNoteError" do
......
......@@ -181,8 +181,9 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do
context 'when there is no from address' do
before do
allow_any_instance_of(described_class).to receive(:from_address)
.and_return(nil)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:from_address).and_return(nil)
end
end
it "creates a new issue" do
......
......@@ -53,7 +53,9 @@ describe Gitlab::Geo::JwtRequestDecoder do
end
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)
end
......
......@@ -22,8 +22,9 @@ describe Gitlab::Geo::Oauth::LogoutState do
end
it 'returns nil when encryption fails' do
allow_any_instance_of(OpenSSL::Cipher::AES256)
.to receive(:final) { raise OpenSSL::OpenSSLError }
allow_next_instance_of(OpenSSL::Cipher::AES256) do |instance|
allow(instance).to receive(:final) { raise OpenSSL::OpenSSLError }
end
subject = described_class.new(token: access_token, return_to: return_to)
......@@ -77,8 +78,9 @@ describe Gitlab::Geo::Oauth::LogoutState do
end
it 'returns nil when decryption fails' do
allow_any_instance_of(OpenSSL::Cipher::AES256)
.to receive(:final) { raise OpenSSL::OpenSSLError }
allow_next_instance_of(OpenSSL::Cipher::AES256) do |instance|
allow(instance).to receive(:final) { raise OpenSSL::OpenSSLError }
end
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
end
it 'returns false when token has an incorrect encoding' do
allow_any_instance_of(Gitlab::Geo::Oauth::LogoutState)
.to receive(:decode)
.and_return("\xD800\xD801\xD802")
allow_next_instance_of(Gitlab::Geo::Oauth::LogoutState) do |instance|
allow(instance).to receive(:decode).and_return("\xD800\xD801\xD802")
end
token = described_class.new(user, state)
......
......@@ -58,8 +58,9 @@ describe Gitlab::Geo::Oauth::Session, :geo do
api_response = double(parsed: true)
expect_any_instance_of(OAuth2::AccessToken)
.to receive(:get).with(%r{^#{api_url}}).and_return(api_response)
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:get).with(%r{^#{api_url}}).and_return(api_response)
end
subject.authenticate('any token')
end
......
......@@ -11,8 +11,9 @@ describe Gitlab::Geo::Replication::JobArtifactDownloader, :geo do
downloader = described_class.new(:job_artifact, job_artifact.id)
result = Gitlab::Geo::Replication::BaseTransfer::Result.new(success: true, bytes_downloaded: 1)
allow_any_instance_of(Gitlab::Geo::Replication::JobArtifactTransfer)
.to receive(:download_from_primary).and_return(result)
allow_next_instance_of(Gitlab::Geo::Replication::JobArtifactTransfer) do |instance|
allow(instance).to receive(:download_from_primary).and_return(result)
end
expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result)
end
......
......@@ -11,8 +11,9 @@ describe Gitlab::Geo::Replication::LfsDownloader, :geo do
downloader = described_class.new(:lfs, lfs_object.id)
result = Gitlab::Geo::Replication::BaseTransfer::Result.new(success: true, bytes_downloaded: 1)
allow_any_instance_of(Gitlab::Geo::Replication::LfsTransfer)
.to receive(:download_from_primary).and_return(result)
allow_next_instance_of(Gitlab::Geo::Replication::LfsTransfer) do |instance|
allow(instance).to receive(:download_from_primary).and_return(result)
end
expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result)
end
......
......@@ -68,7 +68,9 @@ describe Gitlab::GitAccess do
bad_commit = double("Commit", safe_message: 'Some change').as_null_object
ref_object = double(name: 'heads/master')
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")
......@@ -324,7 +326,9 @@ describe Gitlab::GitAccess do
stub_licensed_features(geo: true)
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
context 'that has no DB replication lag' do
......
......@@ -20,7 +20,9 @@ describe Gitlab::ImportExport::DesignRepoRestorer do
end
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
end
......
......@@ -13,7 +13,9 @@ describe Gitlab::ImportExport::DesignRepoSaver do
before do
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
after do
......
......@@ -12,8 +12,12 @@ describe Gitlab::ImportExport::Importer do
subject(:importer) { described_class.new(project) }
before do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(test_path)
allow_any_instance_of(Gitlab::ImportExport::FileImporter).to receive(:remove_import_file)
allow_next_instance_of(Gitlab::ImportExport) do |instance|
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)
FileUtils.mkdir_p(shared.export_path)
......
......@@ -13,7 +13,9 @@ describe Gitlab::Kerberos::Authentication do
describe '.kerberos_default_realm' 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")
end
......@@ -26,20 +28,26 @@ describe Gitlab::Kerberos::Authentication do
end
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
end
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
end
it "returns false if there is no such user in kerberos" do
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
end
......
......@@ -32,8 +32,9 @@ describe EE::UsageStatistics do
context 'the count query times out' do
before do
allow_any_instance_of(ActiveRecord::Relation)
.to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
allow_next_instance_of(ActiveRecord::Relation) do |instance|
allow(instance).to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
end
end
it 'does not raise an error' do
......
......@@ -39,7 +39,9 @@ RSpec.describe Geo::DeletedProject, type: :model do
end
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)
......
......@@ -70,7 +70,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
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
it 'responds with 401 with invalid auth header' do
......@@ -109,7 +111,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
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
it 'responds with 401 with invalid auth header' do
......@@ -160,7 +164,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
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'))
end
......@@ -212,7 +218,9 @@ describe API::Geo do
let(:req_header) { Gitlab::Geo::TransferRequest.new(transfer.request_data).headers }
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
it 'responds with 401 with invalid auth header' do
......@@ -311,7 +319,9 @@ describe API::Geo do
end
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
......
......@@ -38,7 +38,9 @@ describe API::Internal::Base do
before do
project.add_developer(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)
end
......
......@@ -11,7 +11,9 @@ describe API::ProjectImport do
let(:namespace) { create(:group) }
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)
end
......
......@@ -37,7 +37,9 @@ describe API::ProjectMirror do
context 'when project is mirrored' 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
context 'when "pull_request" event is received' do
......
......@@ -86,7 +86,9 @@ describe 'Rack Attack EE throttles' do
describe 'requests to prometheus alert notify endpoint with oauth token' 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
it_behaves_like 'incident management rate limiting' do
......@@ -96,7 +98,9 @@ describe 'Rack Attack EE throttles' do
describe 'requests to generic alert notify endpoint with oauth token' 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
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