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