Commit b52fca0c authored by Arturo Herrero's avatar Arturo Herrero

Update RSpec helper methods to *_next_instance_of

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

Related to https://gitlab.com/gitlab-org/gitlab/issues/34997
parent c2757d29
...@@ -136,7 +136,9 @@ describe Gitlab::Auth::LDAP::Access do ...@@ -136,7 +136,9 @@ describe Gitlab::Auth::LDAP::Access do
context 'without ActiveDirectory enabled' do context 'without ActiveDirectory enabled' do
before do before do
allow(Gitlab::Auth::LDAP::Config).to receive(:enabled?).and_return(true) allow(Gitlab::Auth::LDAP::Config).to receive(:enabled?).and_return(true)
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive(:active_directory).and_return(false) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive(:active_directory).and_return(false)
end
end end
it 'returns true' do it 'returns true' do
......
...@@ -58,7 +58,9 @@ describe Gitlab::Auth::LDAP::AuthHash do ...@@ -58,7 +58,9 @@ describe Gitlab::Auth::LDAP::AuthHash do
end end
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive(:attributes).and_return(attributes) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive(:attributes).and_return(attributes)
end
end end
it "has the correct username" do it "has the correct username" do
......
...@@ -18,8 +18,9 @@ describe Gitlab::Auth::LDAP::Authentication do ...@@ -18,8 +18,9 @@ describe Gitlab::Auth::LDAP::Authentication do
# try only to fake the LDAP call # try only to fake the LDAP call
adapter = double('adapter', dn: dn).as_null_object adapter = double('adapter', dn: dn).as_null_object
allow_any_instance_of(described_class) allow_next_instance_of(described_class) do |instance|
.to receive(:adapter).and_return(adapter) allow(instance).to receive(:adapter).and_return(adapter)
end
expect(described_class.login(login, password)).to be_truthy expect(described_class.login(login, password)).to be_truthy
end end
...@@ -27,8 +28,9 @@ describe Gitlab::Auth::LDAP::Authentication do ...@@ -27,8 +28,9 @@ describe Gitlab::Auth::LDAP::Authentication do
it "is false if the user does not exist" do it "is false if the user does not exist" do
# try only to fake the LDAP call # try only to fake the LDAP call
adapter = double('adapter', dn: dn).as_null_object adapter = double('adapter', dn: dn).as_null_object
allow_any_instance_of(described_class) allow_next_instance_of(described_class) do |instance|
.to receive(:adapter).and_return(adapter) allow(instance).to receive(:adapter).and_return(adapter)
end
expect(described_class.login(login, password)).to be_falsey expect(described_class.login(login, password)).to be_falsey
end end
...@@ -38,8 +40,9 @@ describe Gitlab::Auth::LDAP::Authentication do ...@@ -38,8 +40,9 @@ describe Gitlab::Auth::LDAP::Authentication do
# try only to fake the LDAP call # try only to fake the LDAP call
adapter = double('adapter', bind_as: nil).as_null_object adapter = double('adapter', bind_as: nil).as_null_object
allow_any_instance_of(described_class) allow_next_instance_of(described_class) do |instance|
.to receive(:adapter).and_return(adapter) allow(instance).to receive(:adapter).and_return(adapter)
end
expect(described_class.login(login, password)).to be_falsey expect(described_class.login(login, password)).to be_falsey
end end
......
...@@ -396,7 +396,9 @@ describe Gitlab::Auth::OAuth::User do ...@@ -396,7 +396,9 @@ describe Gitlab::Auth::OAuth::User do
context "and no account for the LDAP user" do context "and no account for the LDAP user" do
context 'dont block on create (LDAP)' do context 'dont block on create (LDAP)' do
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(block_auto_created_users: false) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(block_auto_created_users: false)
end
end end
it do it do
...@@ -408,7 +410,9 @@ describe Gitlab::Auth::OAuth::User do ...@@ -408,7 +410,9 @@ describe Gitlab::Auth::OAuth::User do
context 'block on create (LDAP)' do context 'block on create (LDAP)' do
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(block_auto_created_users: true) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(block_auto_created_users: true)
end
end end
it do it do
...@@ -424,7 +428,9 @@ describe Gitlab::Auth::OAuth::User do ...@@ -424,7 +428,9 @@ describe Gitlab::Auth::OAuth::User do
context 'dont block on create (LDAP)' do context 'dont block on create (LDAP)' do
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(block_auto_created_users: false) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(block_auto_created_users: false)
end
end end
it do it do
...@@ -436,7 +442,9 @@ describe Gitlab::Auth::OAuth::User do ...@@ -436,7 +442,9 @@ describe Gitlab::Auth::OAuth::User do
context 'block on create (LDAP)' do context 'block on create (LDAP)' do
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(block_auto_created_users: true) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(block_auto_created_users: true)
end
end end
it do it do
...@@ -480,7 +488,9 @@ describe Gitlab::Auth::OAuth::User do ...@@ -480,7 +488,9 @@ describe Gitlab::Auth::OAuth::User do
context 'dont block on create (LDAP)' do context 'dont block on create (LDAP)' do
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(block_auto_created_users: false) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(block_auto_created_users: false)
end
end end
it do it do
...@@ -492,7 +502,9 @@ describe Gitlab::Auth::OAuth::User do ...@@ -492,7 +502,9 @@ describe Gitlab::Auth::OAuth::User do
context 'block on create (LDAP)' do context 'block on create (LDAP)' do
before do before do
allow_any_instance_of(Gitlab::Auth::LDAP::Config).to receive_messages(block_auto_created_users: true) allow_next_instance_of(Gitlab::Auth::LDAP::Config) do |instance|
allow(instance).to receive_messages(block_auto_created_users: true)
end
end end
it do it do
......
...@@ -75,7 +75,9 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do ...@@ -75,7 +75,9 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do
end end
it 'does not schedule an import' do it 'does not schedule an import' do
expect_any_instance_of(Project).not_to receive(:import_schedule) expect_next_instance_of(Project) do |instance|
expect(instance).not_to receive(:import_schedule)
end
importer.create_project_if_needed importer.create_project_if_needed
end end
......
...@@ -9,7 +9,9 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do ...@@ -9,7 +9,9 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do
describe '.load_for_project' do describe '.load_for_project' do
it "loads the status" do it "loads the status" do
expect_any_instance_of(described_class).to receive(:load_status) expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:load_status)
end
described_class.load_for_project(project) described_class.load_for_project(project)
end end
......
...@@ -32,7 +32,9 @@ describe Gitlab::Checks::BranchCheck do ...@@ -32,7 +32,9 @@ describe Gitlab::Checks::BranchCheck do
end end
it 'raises an error if the user is not allowed to merge to protected branches' do it 'raises an error if the user is not allowed to merge to protected branches' do
expect_any_instance_of(Gitlab::Checks::MatchingMergeRequest).to receive(:match?).and_return(true) expect_next_instance_of(Gitlab::Checks::MatchingMergeRequest) do |instance|
expect(instance).to receive(:match?).and_return(true)
end
expect(user_access).to receive(:can_merge_to_branch?).and_return(false) expect(user_access).to receive(:can_merge_to_branch?).and_return(false)
expect(user_access).to receive(:can_push_to_branch?).and_return(false) expect(user_access).to receive(:can_push_to_branch?).and_return(false)
......
...@@ -14,31 +14,41 @@ describe Gitlab::Checks::ChangeAccess do ...@@ -14,31 +14,41 @@ describe Gitlab::Checks::ChangeAccess do
end end
it 'calls pushes checks' do it 'calls pushes checks' do
expect_any_instance_of(Gitlab::Checks::PushCheck).to receive(:validate!) expect_next_instance_of(Gitlab::Checks::PushCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.exec subject.exec
end end
it 'calls branches checks' do it 'calls branches checks' do
expect_any_instance_of(Gitlab::Checks::BranchCheck).to receive(:validate!) expect_next_instance_of(Gitlab::Checks::BranchCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.exec subject.exec
end end
it 'calls tags checks' do it 'calls tags checks' do
expect_any_instance_of(Gitlab::Checks::TagCheck).to receive(:validate!) expect_next_instance_of(Gitlab::Checks::TagCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.exec subject.exec
end end
it 'calls lfs checks' do it 'calls lfs checks' do
expect_any_instance_of(Gitlab::Checks::LfsCheck).to receive(:validate!) expect_next_instance_of(Gitlab::Checks::LfsCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.exec subject.exec
end end
it 'calls diff checks' do it 'calls diff checks' do
expect_any_instance_of(Gitlab::Checks::DiffCheck).to receive(:validate!) expect_next_instance_of(Gitlab::Checks::DiffCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.exec subject.exec
end end
......
...@@ -12,12 +12,16 @@ describe Gitlab::Ci::Build::Credentials::Factory do ...@@ -12,12 +12,16 @@ describe Gitlab::Ci::Build::Credentials::Factory do
end end
before do before do
allow_any_instance_of(described_class).to receive(:providers).and_return([TestProvider]) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:providers).and_return([TestProvider])
end
end end
context 'when provider is valid' do context 'when provider is valid' do
before do before do
allow_any_instance_of(TestProvider).to receive(:valid?).and_return(true) allow_next_instance_of(TestProvider) do |instance|
allow(instance).to receive(:valid?).and_return(true)
end
end end
it 'generates an array of credentials objects' do it 'generates an array of credentials objects' do
...@@ -29,7 +33,9 @@ describe Gitlab::Ci::Build::Credentials::Factory do ...@@ -29,7 +33,9 @@ describe Gitlab::Ci::Build::Credentials::Factory do
context 'when provider is not valid' do context 'when provider is not valid' do
before do before do
allow_any_instance_of(TestProvider).to receive(:valid?).and_return(false) allow_next_instance_of(TestProvider) do |instance|
allow(instance).to receive(:valid?).and_return(false)
end
end end
it 'generates an array without specific credential object' do it 'generates an array without specific credential object' do
......
...@@ -15,8 +15,9 @@ describe Gitlab::Ci::Config::External::File::Project do ...@@ -15,8 +15,9 @@ describe Gitlab::Ci::Config::External::File::Project do
before do before do
project.add_developer(user) project.add_developer(user)
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!)
end
end end
describe '#matching?' do describe '#matching?' do
...@@ -159,8 +160,8 @@ describe Gitlab::Ci::Config::External::File::Project do ...@@ -159,8 +160,8 @@ describe Gitlab::Ci::Config::External::File::Project do
private private
def stub_project_blob(ref, path) def stub_project_blob(ref, path)
allow_any_instance_of(Repository) allow_next_instance_of(Repository) do |instance|
.to receive(:blob_data_at) allow(instance).to receive(:blob_data_at).with(ref, path) { yield }
.with(ref, path) { yield } end
end end
end end
...@@ -21,8 +21,9 @@ describe Gitlab::Ci::Config::External::File::Remote do ...@@ -21,8 +21,9 @@ describe Gitlab::Ci::Config::External::File::Remote do
end end
before do before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!)
end
end end
describe '#matching?' do describe '#matching?' do
......
...@@ -14,8 +14,9 @@ describe Gitlab::Ci::Config::External::File::Template do ...@@ -14,8 +14,9 @@ describe Gitlab::Ci::Config::External::File::Template do
let(:template_file) { described_class.new(params, context) } let(:template_file) { described_class.new(params, context) }
before do before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!)
end
end end
describe '#matching?' do describe '#matching?' do
......
...@@ -23,8 +23,9 @@ describe Gitlab::Ci::Config::External::Mapper do ...@@ -23,8 +23,9 @@ describe Gitlab::Ci::Config::External::Mapper do
before do before do
stub_full_request(remote_url).to_return(body: file_content) stub_full_request(remote_url).to_return(body: file_content)
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!)
end
end end
describe '#process' do describe '#process' do
......
...@@ -8,8 +8,9 @@ describe Gitlab::Ci::Config do ...@@ -8,8 +8,9 @@ describe Gitlab::Ci::Config do
set(:user) { create(:user) } set(:user) { create(:user) }
before do before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!)
end
end end
let(:config) do let(:config) do
...@@ -358,18 +359,11 @@ describe Gitlab::Ci::Config do ...@@ -358,18 +359,11 @@ describe Gitlab::Ci::Config do
context "when it takes too long to evaluate includes" do context "when it takes too long to evaluate includes" do
before do before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!).and_call_original
.and_call_original allow(instance).to receive(:set_deadline).with(described_class::TIMEOUT_SECONDS).and_call_original
allow(instance).to receive(:execution_expired?).and_return(true)
allow_any_instance_of(Gitlab::Ci::Config::External::Context) end
.to receive(:set_deadline)
.with(described_class::TIMEOUT_SECONDS)
.and_call_original
allow_any_instance_of(Gitlab::Ci::Config::External::Context)
.to receive(:execution_expired?)
.and_return(true)
end end
it 'raises error TimeoutError' do it 'raises error TimeoutError' do
...@@ -384,9 +378,9 @@ describe Gitlab::Ci::Config do ...@@ -384,9 +378,9 @@ describe Gitlab::Ci::Config do
context 'when context expansion timeout is disabled' do context 'when context expansion timeout is disabled' do
before do before do
allow_any_instance_of(Gitlab::Ci::Config::External::Context) allow_next_instance_of(Gitlab::Ci::Config::External::Context) do |instance|
.to receive(:check_execution_time!) allow(instance).to receive(:check_execution_time!).and_call_original
.and_call_original end
allow(Feature) allow(Feature)
.to receive(:enabled?) .to receive(:enabled?)
......
...@@ -81,7 +81,9 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do ...@@ -81,7 +81,9 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
context 'when a ref is protected' do context 'when a ref is protected' do
before do before do
allow_any_instance_of(Project).to receive(:protected_for?).and_return(true) allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:protected_for?).and_return(true)
end
end end
it 'returns protected builds' do it 'returns protected builds' do
...@@ -91,7 +93,9 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do ...@@ -91,7 +93,9 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
context 'when a ref is not protected' do context 'when a ref is not protected' do
before do before do
allow_any_instance_of(Project).to receive(:protected_for?).and_return(false) allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:protected_for?).and_return(false)
end
end end
it 'returns unprotected builds' do it 'returns unprotected builds' do
......
...@@ -112,8 +112,9 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -112,8 +112,9 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
end end
it 'calls get_chunk only once' do it 'calls get_chunk only once' do
expect_any_instance_of(Gitlab::Ci::Trace::ChunkedIO) expect_next_instance_of(Gitlab::Ci::Trace::ChunkedIO) do |instance|
.to receive(:current_chunk).once.and_call_original expect(instance).to receive(:current_chunk).once.and_call_original
end
chunked_io.each_line { |line| } chunked_io.each_line { |line| }
end end
......
...@@ -9,7 +9,9 @@ shared_examples 'base stage' do ...@@ -9,7 +9,9 @@ shared_examples 'base stage' do
before do before do
allow(stage).to receive(:project_median).and_return(1.12) allow(stage).to receive(:project_median).and_return(1.12)
allow_any_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher).to receive(:event_result).and_return({}) allow_next_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher) do |instance|
allow(instance).to receive(:event_result).and_return({})
end
end end
it 'has the median data value' do it 'has the median data value' do
......
...@@ -17,7 +17,9 @@ describe Gitlab::CycleAnalytics::UsageData do ...@@ -17,7 +17,9 @@ describe Gitlab::CycleAnalytics::UsageData do
projects.each_with_index do |project, time| projects.each_with_index do |project, time|
issue = create(:issue, project: project, created_at: (time + 1).hour.ago) issue = create(:issue, project: project, created_at: (time + 1).hour.ago)
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue]) allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance|
allow(instance).to receive(:issues).and_return([issue])
end
milestone = create(:milestone, project: project) milestone = create(:milestone, project: project)
mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}")
......
...@@ -10,17 +10,25 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do ...@@ -10,17 +10,25 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
describe '#diff_files' do describe '#diff_files' do
it 'does not highlight binary files' do it 'does not highlight binary files' do
allow_any_instance_of(Gitlab::Diff::File).to receive(:text?).and_return(false) allow_next_instance_of(Gitlab::Diff::File) do |instance|
allow(instance).to receive(:text?).and_return(false)
end
expect_any_instance_of(Gitlab::Diff::File).not_to receive(:highlighted_diff_lines) expect_next_instance_of(Gitlab::Diff::File) do |instance|
expect(instance).not_to receive(:highlighted_diff_lines)
end
diff_files diff_files
end end
it 'does not highlight files marked as undiffable in .gitattributes' do it 'does not highlight files marked as undiffable in .gitattributes' do
allow_any_instance_of(Gitlab::Diff::File).to receive(:diffable?).and_return(false) allow_next_instance_of(Gitlab::Diff::File) do |instance|
allow(instance).to receive(:diffable?).and_return(false)
end
expect_any_instance_of(Gitlab::Diff::File).not_to receive(:highlighted_diff_lines) expect_next_instance_of(Gitlab::Diff::File) do |instance|
expect(instance).not_to receive(:highlighted_diff_lines)
end
diff_files diff_files
end end
......
...@@ -95,7 +95,9 @@ describe Gitlab::Email::Handler::CreateMergeRequestHandler do ...@@ -95,7 +95,9 @@ describe Gitlab::Email::Handler::CreateMergeRequestHandler do
context "something is wrong" do context "something is wrong" do
context "when the merge request could not be saved" do context "when the merge request could not be saved" do
before do before do
allow_any_instance_of(MergeRequest).to receive(:save).and_return(false) allow_next_instance_of(MergeRequest) do |instance|
allow(instance).to receive(:save).and_return(false)
end
end end
it "raises an InvalidMergeRequestError" do it "raises an InvalidMergeRequestError" do
......
...@@ -38,8 +38,9 @@ describe Gitlab::EtagCaching::Middleware do ...@@ -38,8 +38,9 @@ describe Gitlab::EtagCaching::Middleware do
end end
it 'generates ETag' do it 'generates ETag' do
expect_any_instance_of(Gitlab::EtagCaching::Store) expect_next_instance_of(Gitlab::EtagCaching::Store) do |instance|
.to receive(:touch).and_return('123') expect(instance).to receive(:touch).and_return('123')
end
middleware.call(build_request(path, if_none_match)) middleware.call(build_request(path, if_none_match))
end end
...@@ -177,9 +178,9 @@ describe Gitlab::EtagCaching::Middleware do ...@@ -177,9 +178,9 @@ describe Gitlab::EtagCaching::Middleware do
'SCRIPT_NAME' => '/relative-gitlab' 'SCRIPT_NAME' => '/relative-gitlab'
} }
expect_any_instance_of(Gitlab::EtagCaching::Store) expect_next_instance_of(Gitlab::EtagCaching::Store) do |instance|
.to receive(:get).with("/relative-gitlab#{enabled_path}") expect(instance).to receive(:get).with("/relative-gitlab#{enabled_path}").and_return(nil)
.and_return(nil) end
middleware.call(env) middleware.call(env)
end end
...@@ -190,8 +191,9 @@ describe Gitlab::EtagCaching::Middleware do ...@@ -190,8 +191,9 @@ describe Gitlab::EtagCaching::Middleware do
end end
def mock_value_in_store(value) def mock_value_in_store(value)
allow_any_instance_of(Gitlab::EtagCaching::Store) allow_next_instance_of(Gitlab::EtagCaching::Store) do |instance|
.to receive(:get).and_return(value) allow(instance).to receive(:get).and_return(value)
end
end end
def build_request(path, if_none_match) def build_request(path, if_none_match)
......
...@@ -158,7 +158,9 @@ describe Gitlab::Experimentation do ...@@ -158,7 +158,9 @@ describe Gitlab::Experimentation do
context 'the user is part of the control group' do context 'the user is part of the control group' do
before do before do
allow_any_instance_of(described_class).to receive(:experiment_enabled?).with(:test_experiment).and_return(false) allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:experiment_enabled?).with(:test_experiment).and_return(false)
end
end end
it 'pushes the right parameters to gon' do it 'pushes the right parameters to gon' do
......
...@@ -20,6 +20,8 @@ describe Gitlab::FogbugzImport::Client do ...@@ -20,6 +20,8 @@ describe Gitlab::FogbugzImport::Client do
end end
def stub_api(users) def stub_api(users)
allow_any_instance_of(::Fogbugz::Interface).to receive(:command).with(:listPeople).and_return(users) allow_next_instance_of(::Fogbugz::Interface) do |instance|
allow(instance).to receive(:command).with(:listPeople).and_return(users)
end
end end
end end
...@@ -134,7 +134,9 @@ describe Gitlab::Git::Blob, :seed_helper do ...@@ -134,7 +134,9 @@ describe Gitlab::Git::Blob, :seed_helper do
describe '.find with Rugged enabled', :enable_rugged do describe '.find with Rugged enabled', :enable_rugged do
it 'calls out to the Rugged implementation' do it 'calls out to the Rugged implementation' do
allow_any_instance_of(Rugged).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original allow_next_instance_of(Rugged) do |instance|
allow(instance).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original
end
described_class.find(repository, SeedRepo::Commit::ID, 'files/images/6049019_460s.jpg') described_class.find(repository, SeedRepo::Commit::ID, 'files/images/6049019_460s.jpg')
end end
......
...@@ -176,7 +176,9 @@ describe Gitlab::Git::Commit, :seed_helper do ...@@ -176,7 +176,9 @@ describe Gitlab::Git::Commit, :seed_helper do
describe '.find with Rugged enabled', :enable_rugged do describe '.find with Rugged enabled', :enable_rugged do
it 'calls out to the Rugged implementation' do it 'calls out to the Rugged implementation' do
allow_any_instance_of(Rugged).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original allow_next_instance_of(Rugged) do |instance|
allow(instance).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original
end
described_class.find(repository, SeedRepo::Commit::ID) described_class.find(repository, SeedRepo::Commit::ID)
end end
...@@ -438,7 +440,9 @@ describe Gitlab::Git::Commit, :seed_helper do ...@@ -438,7 +440,9 @@ describe Gitlab::Git::Commit, :seed_helper do
it_should_behave_like '.batch_by_oid' it_should_behave_like '.batch_by_oid'
it 'calls out to the Rugged implementation' do it 'calls out to the Rugged implementation' do
allow_any_instance_of(Rugged).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original allow_next_instance_of(Rugged) do |instance|
allow(instance).to receive(:rev_parse).with(SeedRepo::Commit::ID).and_call_original
end
described_class.batch_by_oid(repository, [SeedRepo::Commit::ID]) described_class.batch_by_oid(repository, [SeedRepo::Commit::ID])
end end
......
...@@ -145,7 +145,9 @@ describe Gitlab::Git::Tree, :seed_helper do ...@@ -145,7 +145,9 @@ describe Gitlab::Git::Tree, :seed_helper do
describe '.where with Rugged enabled', :enable_rugged do describe '.where with Rugged enabled', :enable_rugged do
it 'calls out to the Rugged implementation' do it 'calls out to the Rugged implementation' do
allow_any_instance_of(Rugged).to receive(:lookup).with(SeedRepo::Commit::ID) allow_next_instance_of(Rugged) do |instance|
allow(instance).to receive(:lookup).with(SeedRepo::Commit::ID)
end
described_class.where(repository, SeedRepo::Commit::ID, 'files', false) described_class.where(repository, SeedRepo::Commit::ID, 'files', false)
end end
......
...@@ -730,7 +730,9 @@ describe Gitlab::GitAccess do ...@@ -730,7 +730,9 @@ describe Gitlab::GitAccess do
it 'checks LFS integrity only for first change' do it 'checks LFS integrity only for first change' do
allow(project).to receive(:lfs_enabled?).and_return(true) allow(project).to receive(:lfs_enabled?).and_return(true)
expect_any_instance_of(Gitlab::Checks::LfsIntegrity).to receive(:objects_missing?).exactly(1).times expect_next_instance_of(Gitlab::Checks::LfsIntegrity) do |instance|
expect(instance).to receive(:objects_missing?).exactly(1).times
end
push_access_check push_access_check
end end
......
...@@ -10,10 +10,11 @@ describe Gitlab::GitalyClient::CleanupService do ...@@ -10,10 +10,11 @@ describe Gitlab::GitalyClient::CleanupService do
describe '#apply_bfg_object_map_stream' do describe '#apply_bfg_object_map_stream' do
it 'sends an apply_bfg_object_map_stream message' do it 'sends an apply_bfg_object_map_stream message' do
expect_any_instance_of(Gitaly::CleanupService::Stub) expect_next_instance_of(Gitaly::CleanupService::Stub) do |instance|
.to receive(:apply_bfg_object_map_stream) expect(instance).to receive(:apply_bfg_object_map_stream)
.with(kind_of(Enumerator), kind_of(Hash)) .with(kind_of(Enumerator), kind_of(Hash))
.and_return([]) .and_return([])
end
client.apply_bfg_object_map_stream(StringIO.new) client.apply_bfg_object_map_stream(StringIO.new)
end end
......
...@@ -55,7 +55,9 @@ describe Gitlab::GitalyClient do ...@@ -55,7 +55,9 @@ describe Gitlab::GitalyClient do
it 'returns an empty string when the storage is not found in the response' do it 'returns an empty string when the storage is not found in the response' do
response = double("response") response = double("response")
allow(response).to receive(:storage_statuses).and_return([]) allow(response).to receive(:storage_statuses).and_return([])
allow_any_instance_of(Gitlab::GitalyClient::ServerService).to receive(:info).and_return(response) allow_next_instance_of(Gitlab::GitalyClient::ServerService) do |instance|
allow(instance).to receive(:info).and_return(response)
end
expect(described_class.filesystem_id('default')).to eq(nil) expect(described_class.filesystem_id('default')).to eq(nil)
end end
......
...@@ -144,9 +144,9 @@ describe Gitlab::GithubImport::Importer::DiffNoteImporter do ...@@ -144,9 +144,9 @@ describe Gitlab::GithubImport::Importer::DiffNoteImporter do
describe '#find_merge_request_id' do describe '#find_merge_request_id' do
it 'returns a merge request ID' do it 'returns a merge request ID' do
expect_any_instance_of(Gitlab::GithubImport::IssuableFinder) expect_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |instance|
.to receive(:database_id) expect(instance).to receive(:database_id).and_return(10)
.and_return(10) end
expect(importer.find_merge_request_id).to eq(10) expect(importer.find_merge_request_id).to eq(10)
end end
......
...@@ -74,9 +74,9 @@ describe Gitlab::GithubImport::Importer::LabelLinksImporter do ...@@ -74,9 +74,9 @@ describe Gitlab::GithubImport::Importer::LabelLinksImporter do
describe '#find_target_id' do describe '#find_target_id' do
it 'returns the ID of the issuable to create the label link for' do it 'returns the ID of the issuable to create the label link for' do
expect_any_instance_of(Gitlab::GithubImport::IssuableFinder) expect_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |instance|
.to receive(:database_id) expect(instance).to receive(:database_id).and_return(10)
.and_return(10) end
expect(importer.find_target_id).to eq(10) expect(importer.find_target_id).to eq(10)
end end
......
...@@ -50,8 +50,9 @@ describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_redis_cac ...@@ -50,8 +50,9 @@ describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_redis_cac
describe '#build_labels_cache' do describe '#build_labels_cache' do
it 'builds the labels cache' do it 'builds the labels cache' do
expect_any_instance_of(Gitlab::GithubImport::LabelFinder) expect_next_instance_of(Gitlab::GithubImport::LabelFinder) do |instance|
.to receive(:build_cache) expect(instance).to receive(:build_cache)
end
importer.build_labels_cache importer.build_labels_cache
end end
......
...@@ -80,8 +80,9 @@ describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab_redis ...@@ -80,8 +80,9 @@ describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab_redis
describe '#build_milestones_cache' do describe '#build_milestones_cache' do
it 'builds the milestones cache' do it 'builds the milestones cache' do
expect_any_instance_of(Gitlab::GithubImport::MilestoneFinder) expect_next_instance_of(Gitlab::GithubImport::MilestoneFinder) do |instance|
.to receive(:build_cache) expect(instance).to receive(:build_cache)
end
importer.build_milestones_cache importer.build_milestones_cache
end end
......
...@@ -143,9 +143,9 @@ describe Gitlab::GithubImport::Importer::NoteImporter do ...@@ -143,9 +143,9 @@ describe Gitlab::GithubImport::Importer::NoteImporter do
describe '#find_noteable_id' do describe '#find_noteable_id' do
it 'returns the ID of the noteable' do it 'returns the ID of the noteable' do
expect_any_instance_of(Gitlab::GithubImport::IssuableFinder) expect_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |instance|
.to receive(:database_id) expect(instance).to receive(:database_id).and_return(10)
.and_return(10) end
expect(importer.find_noteable_id).to eq(10) expect(importer.find_noteable_id).to eq(10)
end end
......
...@@ -9,8 +9,9 @@ describe Gitlab::GithubImport::SequentialImporter do ...@@ -9,8 +9,9 @@ describe Gitlab::GithubImport::SequentialImporter do
project = double(:project, id: 1, repository: repository) project = double(:project, id: 1, repository: repository)
importer = described_class.new(project, token: 'foo') importer = described_class.new(project, token: 'foo')
expect_any_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance|
.to receive(:execute) expect(instance).to receive(:execute)
end
described_class::SEQUENTIAL_IMPORTERS.each do |klass| described_class::SEQUENTIAL_IMPORTERS.each do |klass|
instance = double(:instance) instance = double(:instance)
......
...@@ -21,18 +21,24 @@ describe Gitlab::GitlabImport::Client do ...@@ -21,18 +21,24 @@ describe Gitlab::GitlabImport::Client do
it 'uses membership and simple flags' do it 'uses membership and simple flags' do
stub_request('/api/v4/projects?membership=true&page=1&per_page=100&simple=true') stub_request('/api/v4/projects?membership=true&page=1&per_page=100&simple=true')
expect_any_instance_of(OAuth2::Response).to receive(:parsed).and_return([]) expect_next_instance_of(OAuth2::Response) do |instance|
expect(instance).to receive(:parsed).and_return([])
end
expect(client.projects.to_a).to eq [] expect(client.projects.to_a).to eq []
end end
shared_examples 'pagination params' do shared_examples 'pagination params' do
before do before do
allow_any_instance_of(OAuth2::Response).to receive(:parsed).and_return([]) allow_next_instance_of(OAuth2::Response) do |instance|
allow(instance).to receive(:parsed).and_return([])
end
end end
it 'allows page_limit param' do it 'allows page_limit param' do
allow_any_instance_of(OAuth2::Response).to receive(:parsed).and_return(element_list) allow_next_instance_of(OAuth2::Response) do |instance|
allow(instance).to receive(:parsed).and_return(element_list)
end
expect(client).to receive(:lazy_page_iterator).with(hash_including(page_limit: 2)).and_call_original expect(client).to receive(:lazy_page_iterator).with(hash_including(page_limit: 2)).and_call_original
......
...@@ -109,7 +109,9 @@ describe Gitlab::HttpIO do ...@@ -109,7 +109,9 @@ describe Gitlab::HttpIO do
end end
it 'calls get_chunk only once' do it 'calls get_chunk only once' do
expect_any_instance_of(Net::HTTP).to receive(:request).once.and_call_original expect_next_instance_of(Net::HTTP) do |instance|
expect(instance).to receive(:request).once.and_call_original
end
http_io.each_line { |line| } http_io.each_line { |line| }
end end
......
...@@ -43,7 +43,9 @@ describe Gitlab::RequestContext do ...@@ -43,7 +43,9 @@ describe Gitlab::RequestContext do
let(:ip) { '192.168.1.11' } let(:ip) { '192.168.1.11' }
before do before do
allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip) allow_next_instance_of(Rack::Request) do |instance|
allow(instance).to receive(:ip).and_return(ip)
end
described_class.new(app).call(env) described_class.new(app).call(env)
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