Commit 8efe5921 authored by Ash McKenzie's avatar Ash McKenzie

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

Update RSpec helper methods to *_next_instance_of

See merge request gitlab-org/gitlab!26890
parents 1957302d 93e8701d
...@@ -61,7 +61,9 @@ describe Analytics::CycleAnalytics::Stages::UpdateService do ...@@ -61,7 +61,9 @@ describe Analytics::CycleAnalytics::Stages::UpdateService do
context 'when the update fails' do context 'when the update fails' do
before do before do
invalid_stage = Analytics::CycleAnalytics::GroupStage.new(name: '') invalid_stage = Analytics::CycleAnalytics::GroupStage.new(name: '')
expect_any_instance_of(described_class).to receive(:find_stage).and_return(invalid_stage) expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:find_stage).and_return(invalid_stage)
end
end end
it 'returns unsuccessful service response' do it 'returns unsuccessful service response' do
......
...@@ -97,7 +97,9 @@ describe DesignManagement::DeleteDesignsService do ...@@ -97,7 +97,9 @@ describe DesignManagement::DeleteDesignsService do
it 'calls repository#log_geo_updated_event' do it 'calls repository#log_geo_updated_event' do
design_repository = EE::Gitlab::GlRepository::DESIGN.repository_resolver.call(project) design_repository = EE::Gitlab::GlRepository::DESIGN.repository_resolver.call(project)
allow_any_instance_of(described_class).to receive(:repository).and_return(design_repository) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:repository).and_return(design_repository)
end
expect(design_repository).to receive(:log_geo_updated_event) expect(design_repository).to receive(:log_geo_updated_event)
......
...@@ -193,7 +193,9 @@ describe DesignManagement::SaveDesignsService do ...@@ -193,7 +193,9 @@ describe DesignManagement::SaveDesignsService do
it 'calls repository#log_geo_updated_event' do it 'calls repository#log_geo_updated_event' do
expect(design_repository).to receive(:log_geo_updated_event) expect(design_repository).to receive(:log_geo_updated_event)
allow_any_instance_of(described_class).to receive(:repository).and_return(design_repository) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:repository).and_return(design_repository)
end
run_service run_service
end end
......
...@@ -241,7 +241,9 @@ describe DraftNotes::PublishService do ...@@ -241,7 +241,9 @@ describe DraftNotes::PublishService do
end end
it 'sends notifications if all threads are resolved' do it 'sends notifications if all threads are resolved' do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request) expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
publish publish
end end
......
...@@ -30,7 +30,9 @@ describe Issues::CreateFromVulnerabilityDataService, '#execute' do ...@@ -30,7 +30,9 @@ describe Issues::CreateFromVulnerabilityDataService, '#execute' do
let(:result) { described_class.new(project, user, {}).execute } let(:result) { described_class.new(project, user, {}).execute }
before do before do
allow_any_instance_of(described_class).to receive(:can?).with(user, :create_issue, project).and_return(false) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:can?).with(user, :create_issue, project).and_return(false)
end
end end
it 'returns expected error' do it 'returns expected error' do
......
...@@ -19,7 +19,9 @@ describe Issues::MoveService do ...@@ -19,7 +19,9 @@ describe Issues::MoveService do
let!(:hook) { create(:group_hook, group: new_project.group, issues_events: true) } let!(:hook) { create(:group_hook, group: new_project.group, issues_events: true) }
it 'executes group issue hooks' do it 'executes group issue hooks' do
allow_any_instance_of(WebHookService).to receive(:execute) allow_next_instance_of(WebHookService) do |instance|
allow(instance).to receive(:execute)
end
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1, # Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never # but since the entire spec run takes place in a transaction, we never
......
...@@ -398,7 +398,9 @@ describe EE::NotificationService, :mailer do ...@@ -398,7 +398,9 @@ describe EE::NotificationService, :mailer do
it_behaves_like 'project emails are disabled' do it_behaves_like 'project emails are disabled' do
before do before do
allow_any_instance_of(::Gitlab::Alerting::Alert).to receive(:valid?).and_return(true) allow_next_instance_of(::Gitlab::Alerting::Alert) do |instance|
allow(instance).to receive(:valid?).and_return(true)
end
end end
let(:alert_params) { { 'labels' => { 'gitlab_alert_id' => 'unknown' } } } let(:alert_params) { { 'labels' => { 'gitlab_alert_id' => 'unknown' } } }
......
...@@ -80,7 +80,9 @@ describe Geo::ContainerRepositorySync, :geo do ...@@ -80,7 +80,9 @@ describe Geo::ContainerRepositorySync, :geo do
describe 'execute' do describe 'execute' do
it 'determines list of tags to sync and to remove correctly' do it 'determines list of tags to sync and to remove correctly' do
expect(container_repository).to receive(:delete_tag_by_digest).with('sha256:aaaaa') expect(container_repository).to receive(:delete_tag_by_digest).with('sha256:aaaaa')
expect_any_instance_of(described_class).to receive(:sync_tag).with('tag-to-sync').and_call_original expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:sync_tag).with('tag-to-sync').and_call_original
end
described_class.new(container_repository).execute described_class.new(container_repository).execute
end end
......
...@@ -195,7 +195,9 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do ...@@ -195,7 +195,9 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do
end end
it 'increments a counter when metrics fail to retrieve' do it 'increments a counter when metrics fail to retrieve' do
allow_any_instance_of(Geo::NodeStatusPostService).to receive(:execute).and_return(false) allow_next_instance_of(Geo::NodeStatusPostService) do |instance|
allow(instance).to receive(:execute).and_return(false)
end
# Run once to get the gauge set # Run once to get the gauge set
subject.execute subject.execute
......
...@@ -18,13 +18,14 @@ describe JiraConnect::SyncService do ...@@ -18,13 +18,14 @@ describe JiraConnect::SyncService do
end end
def expect_jira_client_call(return_value = { 'status': 'success' }) def expect_jira_client_call(return_value = { 'status': 'success' })
expect_any_instance_of(Atlassian::JiraConnect::Client) expect_next_instance_of(Atlassian::JiraConnect::Client) do |instance|
.to receive(:store_dev_info).with( expect(instance).to receive(:store_dev_info).with(
project: project, project: project,
commits: commits, commits: commits,
branches: [instance_of(Gitlab::Git::Branch)], branches: [instance_of(Gitlab::Git::Branch)],
merge_requests: merge_requests merge_requests: merge_requests
).and_return(return_value) ).and_return(return_value)
end
end end
def expect_log(type, message) def expect_log(type, message)
......
...@@ -148,7 +148,9 @@ describe MergeTrains::RefreshMergeRequestService do ...@@ -148,7 +148,9 @@ describe MergeTrains::RefreshMergeRequestService do
context 'when it failed to create a pipeline' do context 'when it failed to create a pipeline' do
before do before do
allow_any_instance_of(MergeTrains::CreatePipelineService).to receive(:execute) { { result: :error, message: 'failed to create pipeline' } } allow_next_instance_of(MergeTrains::CreatePipelineService) do |instance|
allow(instance).to receive(:execute) { { result: :error, message: 'failed to create pipeline' } }
end
end end
it_behaves_like 'drops the merge request from the merge train' do it_behaves_like 'drops the merge request from the merge train' do
...@@ -212,7 +214,9 @@ describe MergeTrains::RefreshMergeRequestService do ...@@ -212,7 +214,9 @@ describe MergeTrains::RefreshMergeRequestService do
before do before do
allow(merge_request).to receive(:mergeable_state?) { true } allow(merge_request).to receive(:mergeable_state?) { true }
merge_request.update(merge_error: 'Branch has been updated since the merge was requested.') merge_request.update(merge_error: 'Branch has been updated since the merge was requested.')
allow_any_instance_of(MergeRequests::MergeService).to receive(:execute) { { result: :error } } allow_next_instance_of(MergeRequests::MergeService) do |instance|
allow(instance).to receive(:execute) { { result: :error } }
end
end end
it 'does not finish merge and drops the merge request from train' do it 'does not finish merge and drops the merge request from train' do
......
...@@ -8,7 +8,9 @@ describe PathLocks::LockService do ...@@ -8,7 +8,9 @@ describe PathLocks::LockService do
let(:path) { 'app/models' } let(:path) { 'app/models' }
it 'locks path' do it 'locks path' do
allow_any_instance_of(described_class).to receive(:can?).and_return(true) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:can?).and_return(true)
end
described_class.new(project, current_user).execute(path) described_class.new(project, current_user).execute(path)
expect(project.path_locks.find_by(path: path)).to be_truthy expect(project.path_locks.find_by(path: path)).to be_truthy
......
...@@ -9,7 +9,9 @@ describe PathLocks::UnlockService do ...@@ -9,7 +9,9 @@ describe PathLocks::UnlockService do
let(:path) { path_lock.path } let(:path) { path_lock.path }
it 'unlocks path' do it 'unlocks path' do
allow_any_instance_of(described_class).to receive(:can?).and_return(true) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:can?).and_return(true)
end
described_class.new(project, current_user).execute(path_lock) described_class.new(project, current_user).execute(path_lock)
expect(project.path_locks.find_by(path: path)).to be_falsey expect(project.path_locks.find_by(path: path)).to be_falsey
......
...@@ -236,7 +236,9 @@ describe Projects::CreateService, '#execute' do ...@@ -236,7 +236,9 @@ describe Projects::CreateService, '#execute' do
context 'when importing Project by repo URL' do context 'when importing Project by repo URL' do
context 'and check namespace plan is enabled' do context 'and check namespace plan is enabled' do
before do before 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
enable_namespace_license_check! enable_namespace_license_check!
end end
......
...@@ -36,7 +36,9 @@ describe Projects::GitlabProjectsImportService do ...@@ -36,7 +36,9 @@ describe Projects::GitlabProjectsImportService do
context 'does not create export job' do context 'does not create export job' do
it 'if project not saved' do it 'if project not saved' do
allow_any_instance_of(Project).to receive(:saved?).and_return(false) allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:saved?).and_return(false)
end
expect(custom_template).not_to receive(:add_export_job) expect(custom_template).not_to receive(:add_export_job)
......
...@@ -11,8 +11,9 @@ describe Projects::SlackApplicationInstallService do ...@@ -11,8 +11,9 @@ describe Projects::SlackApplicationInstallService do
end end
def stub_slack_response_with(response) def stub_slack_response_with(response)
expect_any_instance_of(Projects::SlackApplicationInstallService) expect_next_instance_of(Projects::SlackApplicationInstallService) do |instance|
.to receive(:exchange_slack_token).and_return(response.stringify_keys) expect(instance).to receive(:exchange_slack_token).and_return(response.stringify_keys)
end
end end
def expect_slack_integration_is_created(project) def expect_slack_integration_is_created(project)
......
...@@ -30,8 +30,9 @@ describe Projects::TransferService do ...@@ -30,8 +30,9 @@ describe Projects::TransferService do
include_examples 'audit event logging' do include_examples 'audit event logging' do
let(:operation) { subject.execute(group) } let(:operation) { subject.execute(group) }
let(:fail_condition!) do let(:fail_condition!) do
expect_any_instance_of(Project) expect_next_instance_of(Project) do |instance|
.to receive(:has_container_registry_tags?).and_return(true) expect(instance).to receive(:has_container_registry_tags?).and_return(true)
end
end end
let(:attributes) do let(:attributes) do
{ {
......
...@@ -359,7 +359,9 @@ describe Projects::UpdateMirrorService do ...@@ -359,7 +359,9 @@ describe Projects::UpdateMirrorService do
it 'updates LFS objects' do it 'updates LFS objects' do
expect(Projects::LfsPointers::LfsImportService).to receive(:new).and_call_original expect(Projects::LfsPointers::LfsImportService).to receive(:new).and_call_original
expect_any_instance_of(Projects::LfsPointers::LfsObjectDownloadListService).to receive(:execute).and_return({}) expect_next_instance_of(Projects::LfsPointers::LfsObjectDownloadListService) do |instance|
expect(instance).to receive(:execute).and_return({})
end
service.execute service.execute
end end
...@@ -368,7 +370,9 @@ describe Projects::UpdateMirrorService do ...@@ -368,7 +370,9 @@ describe Projects::UpdateMirrorService do
let(:error_message) { 'error_message' } let(:error_message) { 'error_message' }
before do before do
expect_any_instance_of(Projects::LfsPointers::LfsImportService).to receive(:execute).and_return(status: :error, message: error_message) expect_next_instance_of(Projects::LfsPointers::LfsImportService) do |instance|
expect(instance).to receive(:execute).and_return(status: :error, message: error_message)
end
end end
# Uncomment once https://gitlab.com/gitlab-org/gitlab-foss/issues/61834 is closed # Uncomment once https://gitlab.com/gitlab-org/gitlab-foss/issues/61834 is closed
...@@ -389,7 +393,9 @@ describe Projects::UpdateMirrorService do ...@@ -389,7 +393,9 @@ describe Projects::UpdateMirrorService do
end end
it 'logs the error' do it 'logs the error' do
expect_any_instance_of(Gitlab::UpdateMirrorServiceJsonLogger).to receive(:error).with(hash_including(error_message: error_message)) expect_next_instance_of(Gitlab::UpdateMirrorServiceJsonLogger) do |instance|
expect(instance).to receive(:error).with(hash_including(error_message: error_message))
end
subject.execute subject.execute
end end
......
...@@ -68,7 +68,9 @@ describe Security::StoreReportsService do ...@@ -68,7 +68,9 @@ describe Security::StoreReportsService do
end end
it 'caches vulnerability history' do it 'caches vulnerability history' do
expect_any_instance_of(Gitlab::Vulnerabilities::HistoryCache).to receive(:fetch) expect_next_instance_of(Gitlab::Vulnerabilities::HistoryCache) do |instance|
expect(instance).to receive(:fetch)
end
subject subject
end end
......
...@@ -84,7 +84,9 @@ describe Security::SyncReportsToApprovalRulesService, '#execute' do ...@@ -84,7 +84,9 @@ describe Security::SyncReportsToApprovalRulesService, '#execute' do
context "when an unexpected error occurs" do context "when an unexpected error occurs" do
before do before do
allow_any_instance_of(Gitlab::Ci::Reports::LicenseScanning::Report).to receive(:violates?).and_raise('heck') allow_next_instance_of(Gitlab::Ci::Reports::LicenseScanning::Report) do |instance|
allow(instance).to receive(:violates?).and_raise('heck')
end
end end
specify { expect(subject[:status]).to be(:error) } specify { expect(subject[:status]).to be(:error) }
......
...@@ -63,7 +63,9 @@ describe SoftwareLicensePolicies::CreateService do ...@@ -63,7 +63,9 @@ describe SoftwareLicensePolicies::CreateService do
context "when an argument error is raised" do context "when an argument error is raised" do
before do before do
allow_any_instance_of(Project).to receive(:software_license_policies).and_raise(ArgumentError) allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:software_license_policies).and_raise(ArgumentError)
end
end end
specify { expect(subject.execute[:status]).to be(:error) } specify { expect(subject.execute[:status]).to be(:error) }
......
...@@ -124,8 +124,9 @@ describe VulnerabilityFeedback::CreateService, '#execute' do ...@@ -124,8 +124,9 @@ describe VulnerabilityFeedback::CreateService, '#execute' do
end end
it 'delegates the Issue creation to CreateFromVulnerabilityDataService' do it 'delegates the Issue creation to CreateFromVulnerabilityDataService' do
expect_any_instance_of(Issues::CreateFromVulnerabilityDataService) expect_next_instance_of(Issues::CreateFromVulnerabilityDataService) do |instance|
.to receive(:execute).once.and_call_original expect(instance).to receive(:execute).once.and_call_original
end
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
end end
......
...@@ -20,7 +20,9 @@ module EE ...@@ -20,7 +20,9 @@ module EE
def mock_group_saml(uid:) def mock_group_saml(uid:)
allow(Devise).to receive(:omniauth_providers).and_return(%i(group_saml)) allow(Devise).to receive(:omniauth_providers).and_return(%i(group_saml))
allow_any_instance_of(::Gitlab::Auth::Saml::OriginValidator).to receive(:gitlab_initiated?).and_return(true) allow_next_instance_of(::Gitlab::Auth::Saml::OriginValidator) do |instance|
allow(instance).to receive(:gitlab_initiated?).and_return(true)
end
configure_group_saml_mock_auth(uid: uid) configure_group_saml_mock_auth(uid: uid)
stub_omniauth_provider(:group_saml) stub_omniauth_provider(:group_saml)
end end
......
...@@ -9,8 +9,9 @@ describe ClearSharedRunnersMinutesWorker do ...@@ -9,8 +9,9 @@ describe ClearSharedRunnersMinutesWorker do
let(:namespace) { create(:namespace) } let(:namespace) { create(:namespace) }
before do before do
expect_any_instance_of(described_class) expect_next_instance_of(described_class) do |instance|
.to receive(:try_obtain_lease).and_return(true) expect(instance).to receive(:try_obtain_lease).and_return(true)
end
end end
subject { worker.perform } subject { worker.perform }
......
...@@ -23,21 +23,23 @@ describe CreateGithubWebhookWorker do ...@@ -23,21 +23,23 @@ describe CreateGithubWebhookWorker do
end end
it 'creates the webhook' do it 'creates the webhook' do
expect_any_instance_of(Gitlab::LegacyGithubImport::Client).to receive(:create_hook) expect_next_instance_of(Gitlab::LegacyGithubImport::Client) do |instance|
.with( expect(instance).to receive(:create_hook)
'foo/bar', .with(
'web', 'foo/bar',
{ 'web',
url: "http://localhost#{api_v4_projects_mirror_pull_path(id: project.id)}", {
content_type: 'json', url: "http://localhost#{api_v4_projects_mirror_pull_path(id: project.id)}",
secret: project.external_webhook_token, content_type: 'json',
insecure_ssl: 1 secret: project.external_webhook_token,
}, insecure_ssl: 1
{ },
events: %w[push pull_request], {
active: true events: %w[push pull_request],
} active: true
) }
)
end
subject.perform(project.id) subject.perform(project.id)
end end
......
...@@ -12,7 +12,9 @@ describe Geo::ContainerRepositorySyncDispatchWorker, :geo, :geo_fdw, :use_sql_qu ...@@ -12,7 +12,9 @@ describe Geo::ContainerRepositorySyncDispatchWorker, :geo, :geo_fdw, :use_sql_qu
before do before do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
stub_exclusive_lease(renew: true) stub_exclusive_lease(renew: true)
allow_any_instance_of(described_class).to receive(:over_time?).and_return(false) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:over_time?).and_return(false)
end
stub_registry_replication_config(enabled: true) stub_registry_replication_config(enabled: true)
end end
......
...@@ -12,7 +12,9 @@ describe Geo::FileDownloadDispatchWorker, :geo, :geo_fdw, :use_sql_query_cache_f ...@@ -12,7 +12,9 @@ describe Geo::FileDownloadDispatchWorker, :geo, :geo_fdw, :use_sql_query_cache_f
before do before do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
stub_exclusive_lease(renew: true) stub_exclusive_lease(renew: true)
allow_any_instance_of(described_class).to receive(:over_time?).and_return(false) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:over_time?).and_return(false)
end
WebMock.stub_request(:get, /primary-geo-node/).to_return(status: 200, body: "", headers: {}) WebMock.stub_request(:get, /primary-geo-node/).to_return(status: 200, body: "", headers: {})
end end
......
...@@ -155,7 +155,9 @@ describe Geo::RepositoryShardSyncWorker, :geo, :geo_fdw, :clean_gitlab_redis_cac ...@@ -155,7 +155,9 @@ describe Geo::RepositoryShardSyncWorker, :geo, :geo_fdw, :clean_gitlab_redis_cac
unsynced_project.destroy unsynced_project.destroy
unsynced_project_in_restricted_group.destroy unsynced_project_in_restricted_group.destroy
allow_any_instance_of(described_class).to receive(:db_retrieve_batch_size).and_return(2) # Must be >1 because of the Geo::BaseSchedulerWorker#interleave allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:db_retrieve_batch_size).and_return(2) # Must be >1 because of the Geo::BaseSchedulerWorker#interleave
end
secondary.update!(repos_max_capacity: 3) # Must be more than db_retrieve_batch_size secondary.update!(repos_max_capacity: 3) # Must be more than db_retrieve_batch_size
project_list.each do |project| project_list.each do |project|
...@@ -165,8 +167,12 @@ describe Geo::RepositoryShardSyncWorker, :geo, :geo_fdw, :clean_gitlab_redis_cac ...@@ -165,8 +167,12 @@ describe Geo::RepositoryShardSyncWorker, :geo, :geo_fdw, :clean_gitlab_redis_cac
.and_call_original .and_call_original
end end
allow_any_instance_of(Geo::ProjectRegistry).to receive(:wiki_sync_due?).and_return(false) allow_next_instance_of(Geo::ProjectRegistry) do |instance|
allow_any_instance_of(Geo::RepositorySyncService).to receive(:expire_repository_caches) allow(instance).to receive(:wiki_sync_due?).and_return(false)
end
allow_next_instance_of(Geo::RepositorySyncService) do |instance|
allow(instance).to receive(:expire_repository_caches)
end
end end
it 'tries to sync project where last attempt to sync failed' do it 'tries to sync project where last attempt to sync failed' do
...@@ -216,12 +222,22 @@ describe Geo::RepositoryShardSyncWorker, :geo, :geo_fdw, :clean_gitlab_redis_cac ...@@ -216,12 +222,22 @@ describe Geo::RepositoryShardSyncWorker, :geo, :geo_fdw, :clean_gitlab_redis_cac
unsynced_project.destroy unsynced_project.destroy
unsynced_project_in_restricted_group.destroy unsynced_project_in_restricted_group.destroy
allow_any_instance_of(described_class).to receive(:db_retrieve_batch_size).and_return(2) # Must be >1 because of the Geo::BaseSchedulerWorker#interleave allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:db_retrieve_batch_size).and_return(2) # Must be >1 because of the Geo::BaseSchedulerWorker#interleave
end
secondary.update!(repos_max_capacity: 3) # Must be more than db_retrieve_batch_size secondary.update!(repos_max_capacity: 3) # Must be more than db_retrieve_batch_size
allow_any_instance_of(Project).to receive(:ensure_repository).and_raise(Gitlab::Shell::Error.new('foo')) allow_next_instance_of(Project) do |instance|
allow_any_instance_of(Geo::ProjectRegistry).to receive(:wiki_sync_due?).and_return(false) allow(instance).to receive(:ensure_repository).and_raise(Gitlab::Shell::Error.new('foo'))
allow_any_instance_of(Geo::RepositorySyncService).to receive(:expire_repository_caches) end
allow_any_instance_of(Geo::ProjectHousekeepingService).to receive(:do_housekeeping) allow_next_instance_of(Geo::ProjectRegistry) do |instance|
allow(instance).to receive(:wiki_sync_due?).and_return(false)
end
allow_next_instance_of(Geo::RepositorySyncService) do |instance|
allow(instance).to receive(:expire_repository_caches)
end
allow_next_instance_of(Geo::ProjectHousekeepingService) do |instance|
allow(instance).to receive(:do_housekeeping)
end
end end
it 'tries to sync every project' do it 'tries to sync every project' do
......
...@@ -7,7 +7,9 @@ describe GeoRepositoryDestroyWorker do ...@@ -7,7 +7,9 @@ describe GeoRepositoryDestroyWorker do
it 'delegates project removal to Geo::RepositoryDestroyService' do it 'delegates project removal to Geo::RepositoryDestroyService' do
project = create(:project) project = create(:project)
expect_any_instance_of(Geo::RepositoryDestroyService).to receive(:execute) expect_next_instance_of(Geo::RepositoryDestroyService) do |instance|
expect(instance).to receive(:execute)
end
described_class.new.perform(project.id, project.name, project.path, 'default') described_class.new.perform(project.id, project.name, project.path, 'default')
end end
......
...@@ -91,9 +91,9 @@ describe IncidentManagement::ProcessPrometheusAlertWorker do ...@@ -91,9 +91,9 @@ describe IncidentManagement::ProcessPrometheusAlertWorker do
context 'when issue could not be created' do context 'when issue could not be created' do
before do before do
allow_any_instance_of(IncidentManagement::CreateIssueService) allow_next_instance_of(IncidentManagement::CreateIssueService) do |instance|
.to receive(:execute) allow(instance).to receive(:execute).and_return( { error: true } )
.and_return( { error: true } ) end
end end
it 'does not relate issue to an event' do it 'does not relate issue to an event' do
......
...@@ -12,8 +12,9 @@ describe JiraConnect::SyncBranchWorker do ...@@ -12,8 +12,9 @@ describe JiraConnect::SyncBranchWorker do
subject { described_class.new.perform(project_id, branch_name, commit_shas) } subject { described_class.new.perform(project_id, branch_name, commit_shas) }
def expect_jira_sync_service_execute(args) def expect_jira_sync_service_execute(args)
expect_any_instance_of(JiraConnect::SyncService) expect_next_instance_of(JiraConnect::SyncService) do |instance|
.to receive(:execute).with(args) expect(instance).to receive(:execute).with(args)
end
end end
it 'calls JiraConnect::SyncService#execute' do it 'calls JiraConnect::SyncService#execute' do
......
...@@ -16,7 +16,9 @@ describe ProjectImportScheduleWorker do ...@@ -16,7 +16,9 @@ describe ProjectImportScheduleWorker do
it 'schedules an import for a project' do it 'schedules an import for a project' do
import_state = create(:import_state) import_state = create(:import_state)
allow_any_instance_of(EE::Project).to receive(:add_import_job).and_return(nil) allow_next_instance_of(EE::Project) do |instance|
allow(instance).to receive(:add_import_job).and_return(nil)
end
expect do expect do
subject.perform(import_state.project_id) subject.perform(import_state.project_id)
......
...@@ -13,13 +13,17 @@ describe RepositoryUpdateMirrorWorker do ...@@ -13,13 +13,17 @@ describe RepositoryUpdateMirrorWorker do
end end
it 'sets status as finished when update mirror service executes successfully' do it 'sets status as finished when update mirror service executes successfully' do
expect_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_return(status: :success) expect_next_instance_of(Projects::UpdateMirrorService) do |instance|
expect(instance).to receive(:execute).and_return(status: :success)
end
expect { subject.perform(project.id) }.to change { import_state.reload.status }.to('finished') expect { subject.perform(project.id) }.to change { import_state.reload.status }.to('finished')
end end
it 'sets status as failed when update mirror service executes with errors' do it 'sets status as failed when update mirror service executes with errors' do
allow_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_return(status: :error, message: 'error') allow_next_instance_of(Projects::UpdateMirrorService) do |instance|
allow(instance).to receive(:execute).and_return(status: :error, message: 'error')
end
expect { subject.perform(project.id) }.to raise_error(RepositoryUpdateMirrorWorker::UpdateError, 'error') expect { subject.perform(project.id) }.to raise_error(RepositoryUpdateMirrorWorker::UpdateError, 'error')
expect(project.reload.import_status).to eq('failed') expect(project.reload.import_status).to eq('failed')
...@@ -34,7 +38,9 @@ describe RepositoryUpdateMirrorWorker do ...@@ -34,7 +38,9 @@ describe RepositoryUpdateMirrorWorker do
end end
it 'marks mirror as failed when an error occurs' do it 'marks mirror as failed when an error occurs' do
allow_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_raise(RuntimeError) allow_next_instance_of(Projects::UpdateMirrorService) do |instance|
allow(instance).to receive(:execute).and_raise(RuntimeError)
end
expect { subject.perform(project.id) }.to raise_error(RepositoryUpdateMirrorWorker::UpdateError) expect { subject.perform(project.id) }.to raise_error(RepositoryUpdateMirrorWorker::UpdateError)
expect(import_state.reload.status).to eq('failed') expect(import_state.reload.status).to eq('failed')
...@@ -45,7 +51,9 @@ describe RepositoryUpdateMirrorWorker do ...@@ -45,7 +51,9 @@ describe RepositoryUpdateMirrorWorker do
let(:import_state) { create(:import_state, :mirror, :started, project: started_project, jid: jid) } let(:import_state) { create(:import_state, :mirror, :started, project: started_project, jid: jid) }
it 'sets status as finished when update mirror service executes successfully' do it 'sets status as finished when update mirror service executes successfully' do
expect_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_return(status: :success) expect_next_instance_of(Projects::UpdateMirrorService) do |instance|
expect(instance).to receive(:execute).and_return(status: :success)
end
expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished') expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished')
end end
......
...@@ -9,8 +9,9 @@ describe ProjectUpdateRepositoryStorageWorker do ...@@ -9,8 +9,9 @@ describe ProjectUpdateRepositoryStorageWorker do
describe "#perform" do describe "#perform" do
it "calls the update repository storage service" do it "calls the update repository storage service" do
expect_any_instance_of(Projects::UpdateRepositoryStorageService) expect_next_instance_of(Projects::UpdateRepositoryStorageService) do |instance|
.to receive(:execute).with('new_storage') expect(instance).to receive(:execute).with('new_storage')
end
subject.perform(project.id, 'new_storage') subject.perform(project.id, 'new_storage')
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