summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-23 10:44:03 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-23 10:44:03 +0200
commitf40b99d02ee9411e5a7f9a93e3e6cf33c1d7890e (patch)
treea55ff4f3ceaa24fcb008114f62b8ac377db6a129 /spec/lib
parent9369adb93d119ca349add2b7f80d6a9b4bbd6703 (diff)
parent4aa1fdd347d1df4001d9e1298e6dc09c0c478c2e (diff)
downloadgitlab-ce-f40b99d02ee9411e5a7f9a93e3e6cf33c1d7890e.tar.gz
Merge branch 'master' into rubocop-for-tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: spec/features/issues_spec.rb spec/models/forked_project_link_spec.rb spec/models/hooks/service_hook_spec.rb spec/models/hooks/web_hook_spec.rb spec/models/project_services/hipchat_service_spec.rb spec/requests/api/project_members_spec.rb spec/requests/api/projects_spec.rb spec/requests/api/system_hooks_spec.rb spec/services/archive_repository_service_spec.rb spec/support/matchers.rb spec/tasks/gitlab/backup_rake_spec.rb
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/extracts_path_spec.rb7
-rw-r--r--spec/lib/gitlab/auth_spec.rb8
-rw-r--r--spec/lib/gitlab/backend/shell_spec.rb2
-rw-r--r--spec/lib/gitlab/google_code_import/client_spec.rb2
-rw-r--r--spec/lib/gitlab/google_code_import/importer_spec.rb8
-rw-r--r--spec/lib/gitlab/ldap/access_spec.rb30
-rw-r--r--spec/lib/gitlab/ldap/adapter_spec.rb15
-rw-r--r--spec/lib/gitlab/ldap/authentication_spec.rb51
-rw-r--r--spec/lib/gitlab/ldap/config_spec.rb2
-rw-r--r--spec/lib/gitlab/ldap/user_spec.rb26
-rw-r--r--spec/lib/gitlab/o_auth/auth_hash_spec.rb2
-rw-r--r--spec/lib/gitlab/o_auth/user_spec.rb85
-rw-r--r--spec/lib/gitlab/popen_spec.rb2
-rw-r--r--spec/lib/gitlab/satellite/merge_action_spec.rb4
-rw-r--r--spec/lib/gitlab/upgrader_spec.rb4
15 files changed, 145 insertions, 103 deletions
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index 85f35d9da66..f077c80d478 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -9,8 +9,11 @@ describe ExtractsPath do
before do
@project = project
- project.stub(repository: double(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']))
- project.stub(path_with_namespace: 'gitlab/gitlab-ci')
+
+ repo = double(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])
+ allow(project).to receive(:repository).and_return(repo)
+ allow(project).to receive(:path_with_namespace).
+ and_return('gitlab/gitlab-ci')
end
describe '#assign_ref' do
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb
index 95fc7e16a11..72806bebe1f 100644
--- a/spec/lib/gitlab/auth_spec.rb
+++ b/spec/lib/gitlab/auth_spec.rb
@@ -27,16 +27,18 @@ describe Gitlab::Auth do
it "should not find user with invalid password" do
password = 'wrong'
- expect( gl_auth.find(username, password) ).to_not eql user
+ expect( gl_auth.find(username, password) ).not_to eql user
end
it "should not find user with invalid login" do
user = 'wrong'
- expect( gl_auth.find(username, password) ).to_not eql user
+ expect( gl_auth.find(username, password) ).not_to eql user
end
context "with ldap enabled" do
- before { Gitlab::LDAP::Config.stub(enabled?: true) }
+ before do
+ allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
+ end
it "tries to autheticate with db before ldap" do
expect(Gitlab::LDAP::Authentication).not_to receive(:login)
diff --git a/spec/lib/gitlab/backend/shell_spec.rb b/spec/lib/gitlab/backend/shell_spec.rb
index 27279465c1a..b6d04330599 100644
--- a/spec/lib/gitlab/backend/shell_spec.rb
+++ b/spec/lib/gitlab/backend/shell_spec.rb
@@ -5,7 +5,7 @@ describe Gitlab::Shell do
let(:gitlab_shell) { Gitlab::Shell.new }
before do
- Project.stub(find: project)
+ allow(Project).to receive(:find).and_return(project)
end
it { is_expected.to respond_to :add_key }
diff --git a/spec/lib/gitlab/google_code_import/client_spec.rb b/spec/lib/gitlab/google_code_import/client_spec.rb
index a66b811e0fd..6aa4428f367 100644
--- a/spec/lib/gitlab/google_code_import/client_spec.rb
+++ b/spec/lib/gitlab/google_code_import/client_spec.rb
@@ -15,7 +15,7 @@ describe Gitlab::GoogleCodeImport::Client do
let(:raw_data) { "No clue" }
it "returns true" do
- expect(subject).to_not be_valid
+ expect(subject).not_to be_valid
end
end
end
diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb
index 3879a6ab898..c53ddeb87b5 100644
--- a/spec/lib/gitlab/google_code_import/importer_spec.rb
+++ b/spec/lib/gitlab/google_code_import/importer_spec.rb
@@ -24,7 +24,7 @@ describe Gitlab::GoogleCodeImport::Importer do
subject.execute
%w(New NeedInfo Accepted Wishlist Started Fixed Invalid Duplicate WontFix Incomplete).each do |status|
- expect(project.labels.find_by(name: "Status: #{status}")).to_not be_nil
+ expect(project.labels.find_by(name: "Status: #{status}")).not_to be_nil
end
end
@@ -38,7 +38,7 @@ describe Gitlab::GoogleCodeImport::Importer do
Component-Systray Component-Clock Component-Launcher Component-Tint2conf Component-Docs Component-New
).each do |label|
label.sub!("-", ": ")
- expect(project.labels.find_by(name: label)).to_not be_nil
+ expect(project.labels.find_by(name: label)).not_to be_nil
end
end
@@ -46,7 +46,7 @@ describe Gitlab::GoogleCodeImport::Importer do
subject.execute
issue = project.issues.first
- expect(issue).to_not be_nil
+ expect(issue).not_to be_nil
expect(issue.iid).to eq(169)
expect(issue.author).to eq(project.creator)
expect(issue.assignee).to eq(mapped_user)
@@ -71,7 +71,7 @@ describe Gitlab::GoogleCodeImport::Importer do
subject.execute
note = project.issues.first.notes.first
- expect(note).to_not be_nil
+ expect(note).not_to be_nil
expect(note.note).to include("Comment 1")
expect(note.note).to include("@#{mapped_user.username}")
expect(note.note).to include("November 18, 2009 05:14")
diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb
index 038ac7e0d75..c38f212b405 100644
--- a/spec/lib/gitlab/ldap/access_spec.rb
+++ b/spec/lib/gitlab/ldap/access_spec.rb
@@ -8,16 +8,24 @@ describe Gitlab::LDAP::Access do
subject { access.allowed? }
context 'when the user cannot be found' do
- before { Gitlab::LDAP::Person.stub(find_by_dn: nil) }
+ before do
+ allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(nil)
+ end
it { is_expected.to be_falsey }
end
context 'when the user is found' do
- before { Gitlab::LDAP::Person.stub(find_by_dn: :ldap_user) }
+ before do
+ allow(Gitlab::LDAP::Person).
+ to receive(:find_by_dn).and_return(:ldap_user)
+ end
context 'and the user is disabled via active directory' do
- before { Gitlab::LDAP::Person.stub(disabled_via_active_directory?: true) }
+ before do
+ allow(Gitlab::LDAP::Person).
+ to receive(:disabled_via_active_directory?).and_return(true)
+ end
it { is_expected.to be_falsey }
@@ -30,8 +38,9 @@ describe Gitlab::LDAP::Access do
context 'and has no disabled flag in active diretory' do
before do
user.block
-
- Gitlab::LDAP::Person.stub(disabled_via_active_directory?: false)
+
+ allow(Gitlab::LDAP::Person).
+ to receive(:disabled_via_active_directory?).and_return(false)
end
it { is_expected.to be_truthy }
@@ -39,7 +48,8 @@ describe Gitlab::LDAP::Access do
context 'when auto-created users are blocked' do
before do
- Gitlab::LDAP::Config.any_instance.stub(block_auto_created_users: true)
+ allow_any_instance_of(Gitlab::LDAP::Config).
+ to receive(:block_auto_created_users).and_return(true)
end
it "does not unblock user in GitLab" do
@@ -51,7 +61,8 @@ describe Gitlab::LDAP::Access do
context "when auto-created users are not blocked" do
before do
- Gitlab::LDAP::Config.any_instance.stub(block_auto_created_users: false)
+ allow_any_instance_of(Gitlab::LDAP::Config).
+ to receive(:block_auto_created_users).and_return(false)
end
it "should unblock user in GitLab" do
@@ -63,8 +74,9 @@ describe Gitlab::LDAP::Access do
context 'without ActiveDirectory enabled' do
before do
- Gitlab::LDAP::Config.stub(enabled?: true)
- Gitlab::LDAP::Config.any_instance.stub(active_directory: false)
+ allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
+ allow_any_instance_of(Gitlab::LDAP::Config).
+ to receive(:active_directory).and_return(false)
end
it { is_expected.to be_truthy }
diff --git a/spec/lib/gitlab/ldap/adapter_spec.rb b/spec/lib/gitlab/ldap/adapter_spec.rb
index b609e4b38f2..38076602df9 100644
--- a/spec/lib/gitlab/ldap/adapter_spec.rb
+++ b/spec/lib/gitlab/ldap/adapter_spec.rb
@@ -3,27 +3,32 @@ require 'spec_helper'
describe Gitlab::LDAP::Adapter do
let(:adapter) { Gitlab::LDAP::Adapter.new 'ldapmain' }
- describe :dn_matches_filter? do
+ describe '#dn_matches_filter?' do
let(:ldap) { double(:ldap) }
subject { adapter.dn_matches_filter?(:dn, :filter) }
- before { adapter.stub(ldap: ldap) }
+ before { allow(adapter).to receive(:ldap).and_return(ldap) }
context "when the search is successful" do
context "and the result is non-empty" do
- before { ldap.stub(search: [:foo]) }
+ before { allow(ldap).to receive(:search).and_return([:foo]) }
it { is_expected.to be_truthy }
end
context "and the result is empty" do
- before { ldap.stub(search: []) }
+ before { allow(ldap).to receive(:search).and_return([]) }
it { is_expected.to be_falsey }
end
end
context "when the search encounters an error" do
- before { ldap.stub(search: nil, get_operation_result: double(code: 1, message: 'some error')) }
+ before do
+ allow(ldap).to receive_messages(
+ search: nil,
+ get_operation_result: double(code: 1, message: 'some error')
+ )
+ end
it { is_expected.to be_falsey }
end
diff --git a/spec/lib/gitlab/ldap/authentication_spec.rb b/spec/lib/gitlab/ldap/authentication_spec.rb
index e98b5955321..6e3de914a45 100644
--- a/spec/lib/gitlab/ldap/authentication_spec.rb
+++ b/spec/lib/gitlab/ldap/authentication_spec.rb
@@ -1,53 +1,58 @@
require 'spec_helper'
describe Gitlab::LDAP::Authentication do
- let(:klass) { Gitlab::LDAP::Authentication }
- let(:user) { create(:omniauth_user, extern_uid: dn) }
- let(:dn) { 'uid=john,ou=people,dc=example,dc=com' }
- let(:login) { 'john' }
+ let(:user) { create(:omniauth_user, extern_uid: dn) }
+ let(:dn) { 'uid=john,ou=people,dc=example,dc=com' }
+ let(:login) { 'john' }
let(:password) { 'password' }
- describe :login do
- let(:adapter) { double :adapter }
+ describe 'login' do
before do
- Gitlab::LDAP::Config.stub(enabled?: true)
+ allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
end
it "finds the user if authentication is successful" do
- user
+ expect(user).not_to be_nil
+
# try only to fake the LDAP call
- klass.any_instance.stub(adapter: double(:adapter,
- bind_as: double(:ldap_user, dn: dn)
- ))
- expect(klass.login(login, password)).to be_truthy
+ adapter = double('adapter', dn: dn).as_null_object
+ allow_any_instance_of(described_class).
+ to receive(:adapter).and_return(adapter)
+
+ expect(described_class.login(login, password)).to be_truthy
end
it "is false if the user does not exist" do
# try only to fake the LDAP call
- klass.any_instance.stub(adapter: double(:adapter,
- bind_as: double(:ldap_user, dn: dn)
- ))
- expect(klass.login(login, password)).to be_falsey
+ adapter = double('adapter', dn: dn).as_null_object
+ allow_any_instance_of(described_class).
+ to receive(:adapter).and_return(adapter)
+
+ expect(described_class.login(login, password)).to be_falsey
end
it "is false if authentication fails" do
- user
+ expect(user).not_to be_nil
+
# try only to fake the LDAP call
- klass.any_instance.stub(adapter: double(:adapter, bind_as: nil))
- expect(klass.login(login, password)).to be_falsey
+ adapter = double('adapter', bind_as: nil).as_null_object
+ allow_any_instance_of(described_class).
+ to receive(:adapter).and_return(adapter)
+
+ expect(described_class.login(login, password)).to be_falsey
end
it "fails if ldap is disabled" do
- Gitlab::LDAP::Config.stub(enabled?: false)
- expect(klass.login(login, password)).to be_falsey
+ allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(false)
+ expect(described_class.login(login, password)).to be_falsey
end
it "fails if no login is supplied" do
- expect(klass.login('', password)).to be_falsey
+ expect(described_class.login('', password)).to be_falsey
end
it "fails if no password is supplied" do
- expect(klass.login(login, '')).to be_falsey
+ expect(described_class.login(login, '')).to be_falsey
end
end
end
diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb
index 00e9076c787..3548d647c84 100644
--- a/spec/lib/gitlab/ldap/config_spec.rb
+++ b/spec/lib/gitlab/ldap/config_spec.rb
@@ -14,7 +14,7 @@ describe Gitlab::LDAP::Config do
end
it "raises an error if a unknow provider is used" do
- expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error
+ expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error(RuntimeError)
end
end
end
diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb
index 42015c28c81..7cfca96f4e0 100644
--- a/spec/lib/gitlab/ldap/user_spec.rb
+++ b/spec/lib/gitlab/ldap/user_spec.rb
@@ -16,31 +16,31 @@ describe Gitlab::LDAP::User do
describe :changed? do
it "marks existing ldap user as changed" do
- existing_user = create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
+ create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
expect(ldap_user.changed?).to be_truthy
end
it "marks existing non-ldap user if the email matches as changed" do
- existing_user = create(:user, email: 'john@example.com')
+ create(:user, email: 'john@example.com')
expect(ldap_user.changed?).to be_truthy
end
it "dont marks existing ldap user as changed" do
- existing_user = create(:omniauth_user, email: 'john@example.com', extern_uid: 'my-uid', provider: 'ldapmain')
+ create(:omniauth_user, email: 'john@example.com', extern_uid: 'my-uid', provider: 'ldapmain')
expect(ldap_user.changed?).to be_falsey
end
end
describe :find_or_create do
it "finds the user if already existing" do
- existing_user = create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
+ create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
- expect{ ldap_user.save }.to_not change{ User.count }
+ expect{ ldap_user.save }.not_to change{ User.count }
end
it "connects to existing non-ldap user if the email matches" do
existing_user = create(:omniauth_user, email: 'john@example.com', provider: "twitter")
- expect{ ldap_user.save }.to_not change{ User.count }
+ expect{ ldap_user.save }.not_to change{ User.count }
existing_user.reload
expect(existing_user.ldap_identity.extern_uid).to eql 'my-uid'
@@ -52,11 +52,15 @@ describe Gitlab::LDAP::User do
end
end
-
describe 'blocking' do
+ def configure_block(value)
+ allow_any_instance_of(Gitlab::LDAP::Config).
+ to receive(:block_auto_created_users).and_return(value)
+ end
+
context 'signup' do
context 'dont block on create' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: false }
+ before { configure_block(false) }
it do
ldap_user.save
@@ -66,7 +70,7 @@ describe Gitlab::LDAP::User do
end
context 'block on create' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: true }
+ before { configure_block(true) }
it do
ldap_user.save
@@ -83,7 +87,7 @@ describe Gitlab::LDAP::User do
end
context 'dont block on create' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: false }
+ before { configure_block(false) }
it do
ldap_user.save
@@ -93,7 +97,7 @@ describe Gitlab::LDAP::User do
end
context 'block on create' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: true }
+ before { configure_block(true) }
it do
ldap_user.save
diff --git a/spec/lib/gitlab/o_auth/auth_hash_spec.rb b/spec/lib/gitlab/o_auth/auth_hash_spec.rb
index d957fe82a45..4c0a4a49d2a 100644
--- a/spec/lib/gitlab/o_auth/auth_hash_spec.rb
+++ b/spec/lib/gitlab/o_auth/auth_hash_spec.rb
@@ -51,7 +51,7 @@ describe Gitlab::OAuth::AuthHash do
it { expect(auth_hash.email).to eql email_utf8 }
it { expect(auth_hash.username).to eql nickname_utf8 }
it { expect(auth_hash.name).to eql name_utf8 }
- it { expect(auth_hash.password).to_not be_empty }
+ it { expect(auth_hash.password).not_to be_empty }
end
context 'email not provided' do
diff --git a/spec/lib/gitlab/o_auth/user_spec.rb b/spec/lib/gitlab/o_auth/user_spec.rb
index d383ea2d051..c6cca98a037 100644
--- a/spec/lib/gitlab/o_auth/user_spec.rb
+++ b/spec/lib/gitlab/o_auth/user_spec.rb
@@ -19,23 +19,34 @@ describe Gitlab::OAuth::User do
let!(:existing_user) { create(:omniauth_user, extern_uid: 'my-uid', provider: 'my-provider') }
it "finds an existing user based on uid and provider (facebook)" do
+ # FIXME (rspeicher): It's unlikely that this test is actually doing anything
+ # `auth` is never used and removing it entirely doesn't break the test, so
+ # what's it doing?
auth = double(info: double(name: 'John'), uid: 'my-uid', provider: 'my-provider')
expect( oauth_user.persisted? ).to be_truthy
end
it "returns false if use is not found in database" do
- auth_hash.stub(uid: 'non-existing')
+ allow(auth_hash).to receive(:uid).and_return('non-existing')
expect( oauth_user.persisted? ).to be_falsey
end
end
describe :save do
+ def stub_omniauth_config(messages)
+ allow(Gitlab.config.omniauth).to receive_messages(messages)
+ end
+
+ def stub_ldap_config(messages)
+ allow(Gitlab::LDAP::Config).to receive_messages(messages)
+ end
+
let(:provider) { 'twitter' }
describe 'signup' do
shared_examples "to verify compliance with allow_single_sign_on" do
context "with allow_single_sign_on enabled" do
- before { Gitlab.config.omniauth.stub allow_single_sign_on: true }
+ before { stub_omniauth_config(allow_single_sign_on: true) }
it "creates a user from Omniauth" do
oauth_user.save
@@ -48,7 +59,7 @@ describe Gitlab::OAuth::User do
end
context "with allow_single_sign_on disabled (Default)" do
- before { Gitlab.config.omniauth.stub allow_single_sign_on: false }
+ before { stub_omniauth_config(allow_single_sign_on: false) }
it "throws an error" do
expect{ oauth_user.save }.to raise_error StandardError
end
@@ -56,36 +67,36 @@ describe Gitlab::OAuth::User do
end
context "with auto_link_ldap_user disabled (default)" do
- before { Gitlab.config.omniauth.stub auto_link_ldap_user: false }
+ before { stub_omniauth_config(auto_link_ldap_user: false) }
include_examples "to verify compliance with allow_single_sign_on"
end
context "with auto_link_ldap_user enabled" do
- before { Gitlab.config.omniauth.stub auto_link_ldap_user: true }
-
+ before { stub_omniauth_config(auto_link_ldap_user: true) }
+
context "and no LDAP provider defined" do
- before { allow(Gitlab::LDAP::Config).to receive(:providers).and_return([]) }
-
+ before { stub_ldap_config(providers: []) }
+
include_examples "to verify compliance with allow_single_sign_on"
end
-
+
context "and at least one LDAP provider is defined" do
- before { allow(Gitlab::LDAP::Config).to receive(:providers).and_return(['ldapmain']) }
+ before { stub_ldap_config(providers: %w(ldapmain)) }
context "and a corresponding LDAP person" do
before do
- ldap_user.stub(:uid) { uid }
- ldap_user.stub(:username) { uid }
- ldap_user.stub(:email) { ['johndoe@example.com','john2@example.com'] }
- ldap_user.stub(:dn) { 'uid=user1,ou=People,dc=example' }
+ allow(ldap_user).to receive(:uid) { uid }
+ allow(ldap_user).to receive(:username) { uid }
+ allow(ldap_user).to receive(:email) { ['johndoe@example.com','john2@example.com'] }
+ allow(ldap_user).to receive(:dn) { 'uid=user1,ou=People,dc=example' }
allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user)
end
-
+
context "and no account for the LDAP user" do
-
+
it "creates a user with dual LDAP and omniauth identities" do
oauth_user.save
-
+
expect(gl_user).to be_valid
expect(gl_user.username).to eql uid
expect(gl_user.email).to eql 'johndoe@example.com'
@@ -97,12 +108,12 @@ describe Gitlab::OAuth::User do
])
end
end
-
+
context "and LDAP user has an account already" do
let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') }
it "adds the omniauth identity to the LDAP account" do
oauth_user.save
-
+
expect(gl_user).to be_valid
expect(gl_user.username).to eql 'john'
expect(gl_user.email).to eql 'john@example.com'
@@ -115,10 +126,10 @@ describe Gitlab::OAuth::User do
end
end
end
-
+
context "and no corresponding LDAP person" do
before { allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(nil) }
-
+
include_examples "to verify compliance with allow_single_sign_on"
end
end
@@ -128,11 +139,11 @@ describe Gitlab::OAuth::User do
describe 'blocking' do
let(:provider) { 'twitter' }
- before { Gitlab.config.omniauth.stub allow_single_sign_on: true }
+ before { stub_omniauth_config(allow_single_sign_on: true) }
context 'signup with omniauth only' do
context 'dont block on create' do
- before { Gitlab.config.omniauth.stub block_auto_created_users: false }
+ before { stub_omniauth_config(block_auto_created_users: false) }
it do
oauth_user.save
@@ -142,7 +153,7 @@ describe Gitlab::OAuth::User do
end
context 'block on create' do
- before { Gitlab.config.omniauth.stub block_auto_created_users: true }
+ before { stub_omniauth_config(block_auto_created_users: true) }
it do
oauth_user.save
@@ -154,17 +165,17 @@ describe Gitlab::OAuth::User do
context 'signup with linked omniauth and LDAP account' do
before do
- Gitlab.config.omniauth.stub auto_link_ldap_user: true
- ldap_user.stub(:uid) { uid }
- ldap_user.stub(:username) { uid }
- ldap_user.stub(:email) { ['johndoe@example.com','john2@example.com'] }
- ldap_user.stub(:dn) { 'uid=user1,ou=People,dc=example' }
+ stub_omniauth_config(auto_link_ldap_user: true)
+ allow(ldap_user).to receive(:uid) { uid }
+ allow(ldap_user).to receive(:username) { uid }
+ allow(ldap_user).to receive(:email) { ['johndoe@example.com','john2@example.com'] }
+ allow(ldap_user).to receive(:dn) { 'uid=user1,ou=People,dc=example' }
allow(oauth_user).to receive(:ldap_person).and_return(ldap_user)
end
context "and no account for the LDAP user" do
context 'dont block on create (LDAP)' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: false }
+ before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) }
it do
oauth_user.save
@@ -174,7 +185,7 @@ describe Gitlab::OAuth::User do
end
context 'block on create (LDAP)' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: true }
+ before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) }
it do
oauth_user.save
@@ -188,7 +199,7 @@ describe Gitlab::OAuth::User do
let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') }
context 'dont block on create (LDAP)' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: false }
+ before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) }
it do
oauth_user.save
@@ -198,7 +209,7 @@ describe Gitlab::OAuth::User do
end
context 'block on create (LDAP)' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: true }
+ before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) }
it do
oauth_user.save
@@ -217,7 +228,7 @@ describe Gitlab::OAuth::User do
end
context 'dont block on create' do
- before { Gitlab.config.omniauth.stub block_auto_created_users: false }
+ before { stub_omniauth_config(block_auto_created_users: false) }
it do
oauth_user.save
@@ -227,7 +238,7 @@ describe Gitlab::OAuth::User do
end
context 'block on create' do
- before { Gitlab.config.omniauth.stub block_auto_created_users: true }
+ before { stub_omniauth_config(block_auto_created_users: true) }
it do
oauth_user.save
@@ -237,7 +248,7 @@ describe Gitlab::OAuth::User do
end
context 'dont block on create (LDAP)' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: false }
+ before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) }
it do
oauth_user.save
@@ -247,7 +258,7 @@ describe Gitlab::OAuth::User do
end
context 'block on create (LDAP)' do
- before { Gitlab::LDAP::Config.any_instance.stub block_auto_created_users: true }
+ before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) }
it do
oauth_user.save
diff --git a/spec/lib/gitlab/popen_spec.rb b/spec/lib/gitlab/popen_spec.rb
index 0bc1d5630e6..e53efec6c67 100644
--- a/spec/lib/gitlab/popen_spec.rb
+++ b/spec/lib/gitlab/popen_spec.rb
@@ -28,7 +28,7 @@ describe 'Gitlab::Popen', no_db: true do
context 'unsafe string command' do
it 'raises an error when it gets called with a string argument' do
- expect { @klass.new.popen('ls', path) }.to raise_error
+ expect { @klass.new.popen('ls', path) }.to raise_error(RuntimeError)
end
end
diff --git a/spec/lib/gitlab/satellite/merge_action_spec.rb b/spec/lib/gitlab/satellite/merge_action_spec.rb
index 27912573dce..9b1c9a34e29 100644
--- a/spec/lib/gitlab/satellite/merge_action_spec.rb
+++ b/spec/lib/gitlab/satellite/merge_action_spec.rb
@@ -27,7 +27,7 @@ describe 'Gitlab::Satellite::MergeAction' do
context 'between branches' do
it 'should raise exception -- not expected to be used by non forks' do
- expect { Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between }.to raise_error
+ expect { Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between }.to raise_error(RuntimeError)
end
end
end
@@ -75,7 +75,7 @@ describe 'Gitlab::Satellite::MergeAction' do
context 'between branches' do
it 'should get proper diffs' do
- expect{ Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diffs_between_satellite }.to raise_error
+ expect{ Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diffs_between_satellite }.to raise_error(RuntimeError)
end
end
end
diff --git a/spec/lib/gitlab/upgrader_spec.rb b/spec/lib/gitlab/upgrader_spec.rb
index baa4bd0f28f..8df84665e16 100644
--- a/spec/lib/gitlab/upgrader_spec.rb
+++ b/spec/lib/gitlab/upgrader_spec.rb
@@ -10,14 +10,14 @@ describe Gitlab::Upgrader do
describe 'latest_version?' do
it 'should be true if newest version' do
- upgrader.stub(latest_version_raw: current_version)
+ allow(upgrader).to receive(:latest_version_raw).and_return(current_version)
expect(upgrader.latest_version?).to be_truthy
end
end
describe 'latest_version_raw' do
it 'should be latest version for GitLab 5' do
- upgrader.stub(current_version_raw: "5.3.0")
+ allow(upgrader).to receive(:current_version_raw).and_return("5.3.0")
expect(upgrader.latest_version_raw).to eq("v5.4.2")
end