Commit dcfbfb8c authored by Rémy Coutable's avatar Rémy Coutable

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

Update RSpec helper methods to *_next_instance_of

See merge request gitlab-org/gitlab!21743
parents 5e622fef 216eb2fa
......@@ -14,8 +14,9 @@ describe Gitlab::ImportExport::AvatarRestorer do
context 'with avatar' do
before do
allow_any_instance_of(described_class).to receive(:avatar_export_file)
.and_return(uploaded_image_temp_path)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:avatar_export_file).and_return(uploaded_image_temp_path)
end
end
it 'restores a project avatar' do
......@@ -33,8 +34,9 @@ describe Gitlab::ImportExport::AvatarRestorer do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p("#{tmpdir}/a/b")
allow_any_instance_of(described_class).to receive(:avatar_export_path)
.and_return("#{tmpdir}/a")
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:avatar_export_path).and_return("#{tmpdir}/a")
end
expect(described_class.new(project: project, shared: shared).restore).to be true
end
......
......@@ -10,7 +10,9 @@ describe Gitlab::ImportExport::AvatarSaver do
before do
FileUtils.mkdir_p("#{shared.export_path}/avatar/")
allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:export_path).and_return(export_path)
allow_next_instance_of(Gitlab::ImportExport::Shared) do |instance|
allow(instance).to receive(:export_path).and_return(export_path)
end
end
after do
......
......@@ -18,9 +18,15 @@ describe Gitlab::ImportExport::FileImporter do
stub_const('Gitlab::ImportExport::FileImporter::MAX_RETRIES', 0)
stub_uploads_object_storage(FileUploader)
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(storage_path)
allow_any_instance_of(Gitlab::ImportExport::CommandLineUtil).to receive(:untar_zxf).and_return(true)
allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:relative_archive_path).and_return('test')
allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow(instance).to receive(:storage_path).and_return(storage_path)
end
allow_next_instance_of(Gitlab::ImportExport::CommandLineUtil) do |instance|
allow(instance).to receive(:untar_zxf).and_return(true)
end
allow_next_instance_of(Gitlab::ImportExport::Shared) do |instance|
allow(instance).to receive(:relative_archive_path).and_return('test')
end
allow(SecureRandom).to receive(:hex).and_return('abcd')
setup_files
end
......@@ -69,7 +75,9 @@ describe Gitlab::ImportExport::FileImporter do
context 'error' do
before do
allow_any_instance_of(described_class).to receive(:wait_for_archived_file).and_raise(StandardError)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:wait_for_archived_file).and_raise(StandardError)
end
described_class.import(importable: build(:project), archive_file: '', shared: shared)
end
......
......@@ -32,7 +32,9 @@ describe 'forked project import' 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
saver.save
repo_saver.save
......
......@@ -10,7 +10,9 @@ describe Gitlab::ImportExport::LfsSaver do
subject(:saver) { described_class.new(project: project, shared: shared) }
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
FileUtils.mkdir_p(shared.export_path)
end
......
......@@ -35,9 +35,11 @@ describe Gitlab::ImportExport::MergeRequestParser do
end
it 'parses a MR that has no source branch' do
allow_any_instance_of(described_class).to receive(:branch_exists?).and_call_original
allow_any_instance_of(described_class).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
allow_any_instance_of(described_class).to receive(:fork_merge_request?).and_return(true)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:branch_exists?).and_call_original
allow(instance).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
allow(instance).to receive(:fork_merge_request?).and_return(true)
end
allow(Gitlab::GitalyClient).to receive(:migrate).and_call_original
allow(Gitlab::GitalyClient).to receive(:migrate).with(:fetch_ref).and_return([nil, 0])
......
......@@ -9,19 +9,18 @@ describe Gitlab::ImportExport::Reader do
subject { described_class.new(shared: shared).project_tree }
it 'delegates to AttributesFinder#find_root' do
expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
.to receive(:find_root)
.with(:project)
expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
expect(instance).to receive(:find_root).with(:project)
end
subject
end
context 'when exception raised' do
before do
expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
.to receive(:find_root)
.with(:project)
.and_raise(StandardError)
expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
expect(instance).to receive(:find_root).with(:project).and_raise(StandardError)
end
end
it { is_expected.to be false }
......@@ -38,9 +37,9 @@ describe Gitlab::ImportExport::Reader do
subject { described_class.new(shared: shared).group_members_tree }
it 'delegates to AttributesFinder#find_root' do
expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
.to receive(:find_root)
.with(:group_members)
expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
expect(instance).to receive(:find_root).with(:group_members)
end
subject
end
......
......@@ -20,7 +20,9 @@ describe Gitlab::ImportExport::RepoRestorer 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
......
......@@ -12,7 +12,9 @@ describe Gitlab::ImportExport::RepoSaver 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
......
......@@ -11,7 +11,9 @@ describe Gitlab::ImportExport::Saver do
subject { described_class.new(exportable: project, shared: shared) }
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
FileUtils.mkdir_p(shared.export_path)
FileUtils.touch("#{shared.export_path}/tmp.bundle")
......
......@@ -12,7 +12,9 @@ describe Gitlab::ImportExport::UploadsManager do
subject(:manager) { described_class.new(project: project, shared: shared) }
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
FileUtils.mkdir_p(shared.export_path)
end
......
......@@ -8,7 +8,9 @@ describe Gitlab::ImportExport::UploadsRestorer do
let(:shared) { project.import_export_shared }
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
FileUtils.mkdir_p(File.join(shared.export_path, 'uploads/random'))
FileUtils.touch(File.join(shared.export_path, 'uploads/random', 'dummy.txt'))
end
......
......@@ -9,7 +9,9 @@ describe Gitlab::ImportExport::UploadsSaver do
let(:shared) { project.import_export_shared }
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
end
after do
......
......@@ -13,7 +13,9 @@ describe Gitlab::ImportExport::WikiRepoSaver 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
project_wiki.wiki
project_wiki.create_page("index", "test content")
end
......
......@@ -87,7 +87,9 @@ describe Gitlab::Metrics::Instrumentation do
allow(described_class).to receive(:transaction)
.and_return(transaction)
expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure)
expect_next_instance_of(Gitlab::Metrics::MethodCall) do |instance|
expect(instance).to receive(:measure)
end
@dummy.foo
end
......@@ -165,7 +167,9 @@ describe Gitlab::Metrics::Instrumentation do
allow(described_class).to receive(:transaction)
.and_return(transaction)
expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure)
expect_next_instance_of(Gitlab::Metrics::MethodCall) do |instance|
expect(instance).to receive(:measure)
end
@dummy.new.bar
end
......
......@@ -7,8 +7,9 @@ describe Gitlab::QueryLimiting::Middleware do
it 'runs the application with query limiting in place' do
middleware = described_class.new(-> (env) { env })
expect_any_instance_of(Gitlab::QueryLimiting::Transaction)
.to receive(:act_upon_results)
expect_next_instance_of(Gitlab::QueryLimiting::Transaction) do |instance|
expect(instance).to receive(:act_upon_results)
end
expect(middleware.call({ number: 10 }))
.to eq({ number: 10 })
......
......@@ -14,7 +14,9 @@ describe Gitlab::Sanitizers::SVG do
let(:sanitized) { File.read(sanitized_svg_path) }
it 'delegates sanitization to scrubber' do
expect_any_instance_of(Gitlab::Sanitizers::SVG::Scrubber).to receive(:scrub).at_least(:once)
expect_next_instance_of(Gitlab::Sanitizers::SVG::Scrubber) do |instance|
expect(instance).to receive(:scrub).at_least(:once)
end
described_class.clean(data)
end
......
......@@ -167,8 +167,9 @@ describe Gitlab::Sherlock::Transaction do
allow(Gitlab::Sherlock).to receive(:enable_line_profiler?)
.and_return(true)
allow_any_instance_of(Gitlab::Sherlock::LineProfiler)
.to receive(:profile).and_return('cats are amazing', [])
allow_next_instance_of(Gitlab::Sherlock::LineProfiler) do |instance|
allow(instance).to receive(:profile).and_return('cats are amazing', [])
end
retval = transaction.profile_lines { 'cats are amazing' }
......
......@@ -28,7 +28,9 @@ describe Gitlab::SidekiqMiddleware::CorrelationInjector do
end
it 'injects into payload the correlation id' do
expect_any_instance_of(described_class).to receive(:call).and_call_original
expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:call).and_call_original
end
Labkit::Correlation::CorrelationId.use_id('new-correlation-id') do
TestWorker.perform_async(1234)
......
......@@ -56,13 +56,13 @@ describe Gitlab::SlashCommands::Run do
context 'when a pipeline could not be scheduled' do
it 'returns an error' do
expect_any_instance_of(Gitlab::Chat::Command)
.to receive(:try_create_pipeline)
.and_return(nil)
expect_next_instance_of(Gitlab::Chat::Command) do |instance|
expect(instance).to receive(:try_create_pipeline).and_return(nil)
end
expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
.to receive(:failed_to_schedule)
.with('foo')
expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
expect(instance).to receive(:failed_to_schedule).with('foo')
end
command.execute(command: 'foo', arguments: '')
end
......@@ -77,17 +77,18 @@ describe Gitlab::SlashCommands::Run do
persisted?: true
)
expect_any_instance_of(Gitlab::Chat::Command)
.to receive(:try_create_pipeline)
.and_return(pipeline)
expect_next_instance_of(Gitlab::Chat::Command) do |instance|
expect(instance).to receive(:try_create_pipeline).and_return(pipeline)
end
expect(Gitlab::Chat::Responder)
.to receive(:responder_for)
.with(build)
.and_return(nil)
expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
.to receive(:unsupported_chat_service)
expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
expect(instance).to receive(:unsupported_chat_service)
end
command.execute(command: 'foo', arguments: '')
end
......@@ -103,18 +104,18 @@ describe Gitlab::SlashCommands::Run do
persisted?: true
)
expect_any_instance_of(Gitlab::Chat::Command)
.to receive(:try_create_pipeline)
.and_return(pipeline)
expect_next_instance_of(Gitlab::Chat::Command) do |instance|
expect(instance).to receive(:try_create_pipeline).and_return(pipeline)
end
expect(Gitlab::Chat::Responder)
.to receive(:responder_for)
.with(build)
.and_return(responder)
expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
.to receive(:in_channel_response)
.with(responder.scheduled_output)
expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
expect(instance).to receive(:in_channel_response).with(responder.scheduled_output)
end
command.execute(command: 'foo', arguments: '')
end
......
......@@ -629,7 +629,9 @@ describe API::Branches do
describe 'DELETE /projects/:id/repository/branches/:branch' do
before do
allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true)
allow_next_instance_of(Repository) do |instance|
allow(instance).to receive(:rm_branch).and_return(true)
end
end
it 'removes branch' do
......@@ -666,7 +668,9 @@ describe API::Branches do
describe 'DELETE /projects/:id/repository/merged_branches' do
before do
allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true)
allow_next_instance_of(Repository) do |instance|
allow(instance).to receive(:rm_branch).and_return(true)
end
end
it 'returns 202 with json body' do
......
......@@ -548,8 +548,9 @@ describe API::Files do
end
it "returns a 400 if editor fails to create file" do
allow_any_instance_of(Repository).to receive(:create_file)
.and_raise(Gitlab::Git::CommitError, 'Cannot create file')
allow_next_instance_of(Repository) do |instance|
allow(instance).to receive(:create_file).and_raise(Gitlab::Git::CommitError, 'Cannot create file')
end
post api(route("any%2Etxt"), user), params: params
......@@ -698,7 +699,9 @@ describe API::Files do
end
it "returns a 400 if fails to delete file" do
allow_any_instance_of(Repository).to receive(:delete_file).and_raise(Gitlab::Git::CommitError, 'Cannot delete file')
allow_next_instance_of(Repository) do |instance|
allow(instance).to receive(:delete_file).and_raise(Gitlab::Git::CommitError, 'Cannot delete file')
end
delete api(route(file_path), user), params: params
......
......@@ -1075,8 +1075,9 @@ describe API::Groups do
let(:project_path) { CGI.escape(project.full_path) }
before do
allow_any_instance_of(Projects::TransferService)
.to receive(:execute).and_return(true)
allow_next_instance_of(Projects::TransferService) do |instance|
allow(instance).to receive(:execute).and_return(true)
end
end
context "when authenticated as user" do
......
......@@ -795,9 +795,11 @@ describe API::Jobs do
before do
stub_remote_url_206(url, file_path)
allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false }
allow_any_instance_of(JobArtifactUploader).to receive(:url) { url }
allow_any_instance_of(JobArtifactUploader).to receive(:size) { File.size(file_path) }
allow_next_instance_of(JobArtifactUploader) do |instance|
allow(instance).to receive(:file_storage?) { false }
allow(instance).to receive(:url) { url }
allow(instance).to receive(:size) { File.size(file_path) }
end
end
it 'returns specific job trace' do
......
......@@ -179,7 +179,9 @@ describe API::ProjectSnippets do
end
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
context 'when the snippet is private' do
......@@ -269,7 +271,9 @@ describe API::ProjectSnippets do
end
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
context 'when the snippet is private' do
......
......@@ -238,7 +238,9 @@ describe API::Snippets do
end
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
context 'when the snippet is private' do
......@@ -325,7 +327,9 @@ describe API::Snippets do
end
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
context 'when the snippet is private' do
......
......@@ -328,7 +328,9 @@ describe API::Tags do
let(:route) { "/projects/#{project_id}/repository/tags/#{tag_name}" }
before do
allow_any_instance_of(Repository).to receive(:rm_tag).and_return(true)
allow_next_instance_of(Repository) do |instance|
allow(instance).to receive(:rm_tag).and_return(true)
end
end
shared_examples_for 'repository delete tag' do
......
......@@ -134,7 +134,9 @@ describe JwtController do
context 'when internal auth is disabled' do
it 'rejects the authorization attempt with personal access token message' do
allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false }
allow_next_instance_of(ApplicationSetting) do |instance|
allow(instance).to receive(:password_authentication_enabled_for_git?) { false }
end
get '/jwt/auth', params: parameters, headers: headers
expect(response).to have_gitlab_http_status(401)
......
......@@ -84,7 +84,9 @@ describe 'Rack Attack global throttles' do
expect(response).to have_http_status 200
end
expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
expect_next_instance_of(Rack::Attack::Request) do |instance|
expect(instance).to receive(:ip).at_least(:once).and_return('1.2.3.4')
end
# would be over limit for the same IP
get url_that_does_not_require_authentication
......
......@@ -62,7 +62,9 @@ describe RuboCop::Cop::AvoidBreakFromStrongMemoize do
end
end
RUBY
expect_any_instance_of(described_class).to receive(:add_offense).once
expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:add_offense).once
end
inspect_source(source)
end
......
......@@ -29,7 +29,9 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
end
end
RUBY
expect_any_instance_of(described_class).to receive(:add_offense).once
expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:add_offense).once
end
inspect_source(source)
end
......
......@@ -16,8 +16,9 @@ describe AnalyticsSummarySerializer do
end
before do
allow_any_instance_of(Gitlab::CycleAnalytics::Summary::Issue)
.to receive(:value).and_return(1.12)
allow_next_instance_of(Gitlab::CycleAnalytics::Summary::Issue) do |instance|
allow(instance).to receive(:value).and_return(1.12)
end
end
it 'generates payload for single object' do
......
......@@ -20,7 +20,9 @@ describe Auth::ContainerRegistryAuthenticationService do
before do
allow(Gitlab.config.registry).to receive_messages(enabled: true, issuer: 'rspec', key: nil)
allow_any_instance_of(JSONWebToken::RSAToken).to receive(:key).and_return(rsa_key)
allow_next_instance_of(JSONWebToken::RSAToken) do |instance|
allow(instance).to receive(:key).and_return(rsa_key)
end
end
shared_examples 'an authenticated' do
......
......@@ -17,7 +17,9 @@ describe Boards::Issues::CreateService do
end
it 'delegates the create proceedings to Issues::CreateService' do
expect_any_instance_of(Issues::CreateService).to receive(:execute).once
expect_next_instance_of(Issues::CreateService) do |instance|
expect(instance).to receive(:execute).once
end
service.execute
end
......
......@@ -41,7 +41,9 @@ describe Ci::ArchiveTraceService, '#execute' do
context 'when job failed to archive trace but did not raise an exception' do
before do
allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!) {}
allow_next_instance_of(Gitlab::Ci::Trace) do |instance|
allow(instance).to receive(:archive!) {}
end
end
it 'leaves a warning message in sidekiq log' do
......
......@@ -13,7 +13,9 @@ describe Ci::CreatePipelineService do
context 'job:rules' do
before do
stub_ci_pipeline_yaml_file(config)
allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
allow_next_instance_of(Ci::BuildScheduleWorker) do |instance|
allow(instance).to receive(:perform).and_return(true)
end
end
context 'exists:' do
......
......@@ -45,7 +45,9 @@ describe Ci::PipelineTriggerService do
context 'when commit message has [ci skip]' do
before do
allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' }
allow_next_instance_of(Ci::Pipeline) do |instance|
allow(instance).to receive(:git_commit_message) { '[ci skip]' }
end
end
it 'ignores [ci skip] and create as general' do
......@@ -124,7 +126,9 @@ describe Ci::PipelineTriggerService do
context 'when commit message has [ci skip]' do
before do
allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' }
allow_next_instance_of(Ci::Pipeline) do |instance|
allow(instance).to receive(:git_commit_message) { '[ci skip]' }
end
end
it 'ignores [ci skip] and create as general' do
......
......@@ -51,8 +51,9 @@ describe Ci::PlayManualStageService, '#execute' do
context 'when user does not have permission on a specific build' do
before do
allow_any_instance_of(Ci::Build).to receive(:play)
.and_raise(Gitlab::Access::AccessDeniedError)
allow_next_instance_of(Ci::Build) do |instance|
allow(instance).to receive(:play).and_raise(Gitlab::Access::AccessDeniedError)
end
service.execute(stage)
end
......
......@@ -426,7 +426,9 @@ describe Ci::ProcessPipelineService, '#execute' do
before do
successful_build('test', stage_idx: 0)
allow_any_instance_of(Ci::PersistentRef).to receive(:delete_refs) { raise ArgumentError }
allow_next_instance_of(Ci::PersistentRef) do |instance|
allow(instance).to receive(:delete_refs) { raise ArgumentError }
end
end
it 'process the pipeline' do
......
......@@ -144,10 +144,9 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
end
it 'removes the installation POD' do
expect_any_instance_of(Gitlab::Kubernetes::Helm::Api)
.to receive(:delete_pod!)
.with(kind_of(String))
.once
expect_next_instance_of(Gitlab::Kubernetes::Helm::Api) do |instance|
expect(instance).to receive(:delete_pod!).with(kind_of(String)).once
end
expect(service).to receive(:remove_installation_pod).and_call_original
service.execute
......
......@@ -48,10 +48,9 @@ describe Clusters::Applications::CheckUninstallProgressService do
let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED }
before do
expect_any_instance_of(Gitlab::Kubernetes::Helm::Api)
.to receive(:delete_pod!)
.with(kind_of(String))
.once
expect_next_instance_of(Gitlab::Kubernetes::Helm::Api) do |instance|
expect(instance).to receive(:delete_pod!).with(kind_of(String)).once
end
expect(service).to receive(:pod_phase).once.and_return(phase)
end
......
......@@ -21,7 +21,9 @@ describe Clusters::Gcp::VerifyProvisionStatusService do
shared_examples 'finalize_creation' do
it 'schedules a worker for status minitoring' do
expect_any_instance_of(Clusters::Gcp::FinalizeCreationService).to receive(:execute)
expect_next_instance_of(Clusters::Gcp::FinalizeCreationService) do |instance|
expect(instance).to receive(:execute)
end
described_class.new.execute(provider)
end
......
......@@ -60,7 +60,9 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do
end
it 'creates project service account' do
expect_any_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:execute).once
expect_next_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService) do |instance|
expect(instance).to receive(:execute).once
end
subject
end
......@@ -127,7 +129,9 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do
end
it 'creates project service account' do
expect_any_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:execute).once
expect_next_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService) do |instance|
expect(instance).to receive(:execute).once
end
subject
end
......
......@@ -29,7 +29,9 @@ describe Discussions::ResolveService do
end
it 'executes the notification service' do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(discussion.noteable)
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(discussion.noteable)
end
service.execute(discussion)
end
......
......@@ -131,9 +131,9 @@ describe EventCreateService do
end
it 'caches the last push event for the user' do
expect_any_instance_of(Users::LastPushEventService)
.to receive(:cache_last_push_event)
.with(an_instance_of(PushEvent))
expect_next_instance_of(Users::LastPushEventService) do |instance|
expect(instance).to receive(:cache_last_push_event).with(an_instance_of(PushEvent))
end
subject
end
......
......@@ -41,7 +41,9 @@ describe Groups::DestroyService do
let!(:chat_team) { create(:chat_team, namespace: group) }
it 'destroys the team too' do
expect_any_instance_of(Mattermost::Team).to receive(:destroy)
expect_next_instance_of(Mattermost::Team) do |instance|
expect(instance).to receive(:destroy)
end
destroy_group(group, user, async)
end
......
......@@ -13,7 +13,9 @@ describe Groups::TransferService do
let(:new_parent_group) { create(:group, :public) }
before do
allow_any_instance_of(described_class).to receive(:update_group_attributes).and_raise(Gitlab::UpdatePathError, 'namespace directory cannot be moved')
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:update_group_attributes).and_raise(Gitlab::UpdatePathError, 'namespace directory cannot be moved')
end
create(:group_member, :owner, group: new_parent_group, user: user)
end
......
......@@ -18,7 +18,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
......@@ -29,7 +31,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'imports CSV without errors' do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([])
......@@ -41,7 +45,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') }
it 'imports CSV with some error rows' do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(subject[:success]).to eq(2)
expect(subject[:error_lines]).to eq([3])
......@@ -53,7 +59,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') }
it 'imports CSV with a blank row' do
expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([4])
......
......@@ -131,7 +131,9 @@ describe Issues::MoveService do
let!(:hook) { create(:project_hook, project: old_project, issues_events: true) }
it 'executes project 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,
# but since the entire spec run takes place in a transaction, we never
......
......@@ -54,7 +54,9 @@ describe Lfs::LockFileService do
context 'when an error is raised' do
it "doesn't succeed" do
allow_any_instance_of(described_class).to receive(:create_lock!).and_raise(StandardError)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:create_lock!).and_raise(StandardError)
end
expect(subject.execute[:status]).to eq(:error)
end
......
......@@ -91,7 +91,9 @@ describe Lfs::LocksFinderService do
context 'when an error is raised' do
it "doesn't succeed" do
allow_any_instance_of(described_class).to receive(:find_locks).and_raise(StandardError)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:find_locks).and_raise(StandardError)
end
result = subject.execute
......
......@@ -467,7 +467,9 @@ describe SystemNoteService do
before do
allow(JIRA::Resource::Remotelink).to receive(:all).and_return([])
message = "[#{author.name}|http://localhost/#{author.username}] mentioned this issue in [a commit of #{project.full_path}|http://localhost/#{project.full_path}/commit/#{commit.id}]:\n'#{commit.title.chomp}'"
allow_any_instance_of(JIRA::Resource::Issue).to receive(:comments).and_return([OpenStruct.new(body: message)])
allow_next_instance_of(JIRA::Resource::Issue) do |instance|
allow(instance).to receive(:comments).and_return([OpenStruct.new(body: message)])
end
end
it "does not return success message" 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