Commit c92bfcef authored by Ash McKenzie's avatar Ash McKenzie

Rspec upgrade and deprecation fixes

parent 41396a77
...@@ -4,7 +4,8 @@ group :development, :test do ...@@ -4,7 +4,8 @@ group :development, :test do
gem 'guard', '~> 1.5.0' gem 'guard', '~> 1.5.0'
gem 'guard-rspec', '~> 2.1.0' gem 'guard-rspec', '~> 2.1.0'
gem 'listen', '~> 0.5.0' gem 'listen', '~> 0.5.0'
gem 'rspec', '~> 2.14.0' gem 'rspec', '~> 2.0'
gem 'rspec-its', '~> 1.0.0'
gem 'rubocop', '0.49.1', require: false gem 'rubocop', '0.49.1', require: false
gem 'simplecov', '~> 0.9.0', require: false gem 'simplecov', '~> 0.9.0', require: false
gem 'vcr', '~> 2.4.0' gem 'vcr', '~> 2.4.0'
......
...@@ -32,14 +32,17 @@ GEM ...@@ -32,14 +32,17 @@ GEM
rainbow (2.2.2) rainbow (2.2.2)
rake rake
rake (12.3.1) rake (12.3.1)
rspec (2.14.1) rspec (2.99.0)
rspec-core (~> 2.14.0) rspec-core (~> 2.99.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.99.0)
rspec-core (2.14.8) rspec-core (2.99.2)
rspec-expectations (2.14.5) rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6) rspec-its (1.0.1)
rspec-core (>= 2.99.0.beta1)
rspec-expectations (>= 2.99.0.beta1)
rspec-mocks (2.99.4)
rubocop (0.49.1) rubocop (0.49.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0) parser (>= 2.3.3.1, < 3.0)
...@@ -68,11 +71,12 @@ DEPENDENCIES ...@@ -68,11 +71,12 @@ DEPENDENCIES
guard (~> 1.5.0) guard (~> 1.5.0)
guard-rspec (~> 2.1.0) guard-rspec (~> 2.1.0)
listen (~> 0.5.0) listen (~> 0.5.0)
rspec (~> 2.14.0) rspec (~> 2.0)
rspec-its (~> 1.0.0)
rubocop (= 0.49.1) rubocop (= 0.49.1)
simplecov (~> 0.9.0) simplecov (~> 0.9.0)
vcr (~> 2.4.0) vcr (~> 2.4.0)
webmock (~> 1.9.0) webmock (~> 1.9.0)
BUNDLED WITH BUNDLED WITH
1.16.2 1.16.3
...@@ -36,7 +36,7 @@ describe GitlabAccess do ...@@ -36,7 +36,7 @@ describe GitlabAccess do
context "access is granted" do context "access is granted" do
it "returns true" do it "returns true" do
expect(subject.exec).to be_true expect(subject.exec).to be_truthy
end end
end end
...@@ -54,7 +54,7 @@ describe GitlabAccess do ...@@ -54,7 +54,7 @@ describe GitlabAccess do
end end
it "returns false" do it "returns false" do
expect(subject.exec).to be_false expect(subject.exec).to be_falsey
end end
end end
...@@ -65,7 +65,7 @@ describe GitlabAccess do ...@@ -65,7 +65,7 @@ describe GitlabAccess do
end end
it "returns false" do it "returns false" do
expect(subject.exec).to be_false expect(subject.exec).to be_falsey
end end
end end
end end
......
...@@ -62,7 +62,7 @@ describe GitlabKeys do ...@@ -62,7 +62,7 @@ describe GitlabKeys do
end end
it "should return true" do it "should return true" do
gitlab_keys.send(:add_key).should be_true gitlab_keys.send(:add_key).should be_truthy
end end
end end
end end
...@@ -133,7 +133,7 @@ describe GitlabKeys do ...@@ -133,7 +133,7 @@ describe GitlabKeys do
end end
it "should return true" do it "should return true" do
gitlab_keys.send(:batch_add_keys).should be_true gitlab_keys.send(:batch_add_keys).should be_truthy
end end
end end
end end
...@@ -174,7 +174,7 @@ describe GitlabKeys do ...@@ -174,7 +174,7 @@ describe GitlabKeys do
end end
it "should return true" do it "should return true" do
gitlab_keys.send(:rm_key).should be_true gitlab_keys.send(:rm_key).should be_truthy
end end
end end
...@@ -201,7 +201,7 @@ describe GitlabKeys do ...@@ -201,7 +201,7 @@ describe GitlabKeys do
it "should return true" do it "should return true" do
gitlab_keys.stub(:open) gitlab_keys.stub(:open)
gitlab_keys.send(:clear).should be_true gitlab_keys.send(:clear).should be_truthy
end end
end end
......
...@@ -3,6 +3,10 @@ require_relative '../lib/gitlab_metrics' ...@@ -3,6 +3,10 @@ require_relative '../lib/gitlab_metrics'
describe GitlabMetrics do describe GitlabMetrics do
describe '.measure' do describe '.measure' do
before do
$logger = double('logger').as_null_object
end
it 'returns the return value of the block' do it 'returns the return value of the block' do
val = described_class.measure('foo') { 10 } val = described_class.measure('foo') { 10 }
...@@ -10,7 +14,7 @@ describe GitlabMetrics do ...@@ -10,7 +14,7 @@ describe GitlabMetrics do
end end
it 'writes the metrics data to a log file' do it 'writes the metrics data to a log file' do
expect(described_class.logger).to receive(:debug). expect($logger).to receive(:debug).
with('metrics', a_metrics_log_message('foo')) with('metrics', a_metrics_log_message('foo'))
described_class.measure('foo') { 10 } described_class.measure('foo') { 10 }
......
...@@ -3,7 +3,7 @@ require_relative '../lib/gitlab_net' ...@@ -3,7 +3,7 @@ require_relative '../lib/gitlab_net'
require_relative '../lib/gitlab_access_status' require_relative '../lib/gitlab_access_status'
describe GitlabNet, vcr: true do describe GitlabNet, vcr: true do
let(:gitlab_net) { GitlabNet.new } let(:gitlab_net) { described_class.new }
let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] } let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] }
let(:base_api_endpoint) { 'http://localhost:3000/api/v4' } let(:base_api_endpoint) { 'http://localhost:3000/api/v4' }
let(:internal_api_endpoint) { 'http://localhost:3000/api/v4/internal' } let(:internal_api_endpoint) { 'http://localhost:3000/api/v4/internal' }
...@@ -13,11 +13,12 @@ describe GitlabNet, vcr: true do ...@@ -13,11 +13,12 @@ describe GitlabNet, vcr: true do
let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" } let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" }
before do before do
$logger = double('logger').as_null_object
gitlab_net.stub(:base_api_endpoint).and_return(base_api_endpoint) gitlab_net.stub(:base_api_endpoint).and_return(base_api_endpoint)
gitlab_net.stub(:secret_token).and_return(secret) gitlab_net.stub(:secret_token).and_return(secret)
end end
describe :check do describe '#check' do
it 'should return 200 code for gitlab check' do it 'should return 200 code for gitlab check' do
VCR.use_cassette("check-ok") do VCR.use_cassette("check-ok") do
result = gitlab_net.check result = gitlab_net.check
...@@ -38,7 +39,7 @@ describe GitlabNet, vcr: true do ...@@ -38,7 +39,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :discover do describe '#discover' do
it 'should return user has based on key id' do it 'should return user has based on key id' do
VCR.use_cassette("discover-ok") do VCR.use_cassette("discover-ok") do
user = gitlab_net.discover(key) user = gitlab_net.discover(key)
...@@ -75,7 +76,7 @@ describe GitlabNet, vcr: true do ...@@ -75,7 +76,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :broadcast_message do describe '#broadcast_message' do
context "broadcast message exists" do context "broadcast message exists" do
it 'should return message' do it 'should return message' do
VCR.use_cassette("broadcast_message-ok") do VCR.use_cassette("broadcast_message-ok") do
...@@ -95,7 +96,7 @@ describe GitlabNet, vcr: true do ...@@ -95,7 +96,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :merge_request_urls do describe '#merge_request_urls' do
let(:gl_repository) { "project-1" } let(:gl_repository) { "project-1" }
let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" } let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" }
let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" } let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" }
...@@ -127,7 +128,7 @@ describe GitlabNet, vcr: true do ...@@ -127,7 +128,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :pre_receive do describe '#pre_receive' do
let(:gl_repository) { "project-1" } let(:gl_repository) { "project-1" }
let(:params) { { gl_repository: gl_repository } } let(:params) { { gl_repository: gl_repository } }
...@@ -153,7 +154,7 @@ describe GitlabNet, vcr: true do ...@@ -153,7 +154,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :post_receive do describe '#post_receive' do
let(:gl_repository) { "project-1" } let(:gl_repository) { "project-1" }
let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" } let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" }
let(:params) do let(:params) do
...@@ -193,7 +194,7 @@ describe GitlabNet, vcr: true do ...@@ -193,7 +194,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :authorized_key do describe '#authorized_key' do
let (:ssh_key) { "rsa-key" } let (:ssh_key) { "rsa-key" }
it "should return nil when the resource is not implemented" do it "should return nil when the resource is not implemented" do
...@@ -228,7 +229,7 @@ describe GitlabNet, vcr: true do ...@@ -228,7 +229,7 @@ describe GitlabNet, vcr: true do
it 'returns two factor recovery codes' do it 'returns two factor recovery codes' do
VCR.use_cassette('two-factor-recovery-codes') do VCR.use_cassette('two-factor-recovery-codes') do
result = gitlab_net.two_factor_recovery_codes(key) result = gitlab_net.two_factor_recovery_codes(key)
expect(result['success']).to be_true expect(result['success']).to be_truthy
expect(result['recovery_codes']).to eq(['f67c514de60c4953','41278385fc00c1e0']) expect(result['recovery_codes']).to eq(['f67c514de60c4953','41278385fc00c1e0'])
end end
end end
...@@ -236,7 +237,7 @@ describe GitlabNet, vcr: true do ...@@ -236,7 +237,7 @@ describe GitlabNet, vcr: true do
it 'returns false when recovery codes cannot be generated' do it 'returns false when recovery codes cannot be generated' do
VCR.use_cassette('two-factor-recovery-codes-fail') do VCR.use_cassette('two-factor-recovery-codes-fail') do
result = gitlab_net.two_factor_recovery_codes('key-777') result = gitlab_net.two_factor_recovery_codes('key-777')
expect(result['success']).to be_false expect(result['success']).to be_falsey
expect(result['message']).to eq('Could not find the given key') expect(result['message']).to eq('Could not find the given key')
end end
end end
...@@ -258,17 +259,17 @@ describe GitlabNet, vcr: true do ...@@ -258,17 +259,17 @@ describe GitlabNet, vcr: true do
it 'returns true if notification was succesful' do it 'returns true if notification was succesful' do
VCR.use_cassette('notify-post-receive') do VCR.use_cassette('notify-post-receive') do
expect(gitlab_net.notify_post_receive(gl_repository, repo_path)).to be_true expect(gitlab_net.notify_post_receive(gl_repository, repo_path)).to be_truthy
end end
end end
end end
describe :check_access do describe '#check_access' do
context 'ssh key with access nil, to project' do context 'ssh key with access nil, to project' do
it 'should allow pull access for host' do it 'should allow pull access for host' do
VCR.use_cassette("allowed-pull") do VCR.use_cassette("allowed-pull") do
access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh') access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh')
access.allowed?.should be_true access.allowed?.should be_truthy
end end
end end
...@@ -282,7 +283,7 @@ describe GitlabNet, vcr: true do ...@@ -282,7 +283,7 @@ describe GitlabNet, vcr: true do
it 'should allow push access for host' do it 'should allow push access for host' do
VCR.use_cassette("allowed-push") do VCR.use_cassette("allowed-push") do
access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'ssh') access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'ssh')
access.allowed?.should be_true access.allowed?.should be_truthy
end end
end end
end end
...@@ -291,7 +292,7 @@ describe GitlabNet, vcr: true do ...@@ -291,7 +292,7 @@ describe GitlabNet, vcr: true do
it 'should deny pull access for host' do it 'should deny pull access for host' do
VCR.use_cassette('ssh-pull-disabled') do VCR.use_cassette('ssh-pull-disabled') do
access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'ssh') access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'ssh')
access.allowed?.should be_false access.allowed?.should be_falsey
access.message.should eq 'Git access over SSH is not allowed' access.message.should eq 'Git access over SSH is not allowed'
end end
end end
...@@ -299,7 +300,7 @@ describe GitlabNet, vcr: true do ...@@ -299,7 +300,7 @@ describe GitlabNet, vcr: true do
it 'should deny push access for host' do it 'should deny push access for host' do
VCR.use_cassette('ssh-push-disabled') do VCR.use_cassette('ssh-push-disabled') do
access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh') access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh')
access.allowed?.should be_false access.allowed?.should be_falsey
access.message.should eq 'Git access over SSH is not allowed' access.message.should eq 'Git access over SSH is not allowed'
end end
end end
...@@ -309,7 +310,7 @@ describe GitlabNet, vcr: true do ...@@ -309,7 +310,7 @@ describe GitlabNet, vcr: true do
it 'should deny pull access for host' do it 'should deny pull access for host' do
VCR.use_cassette('http-pull-disabled') do VCR.use_cassette('http-pull-disabled') do
access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'http') access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'http')
access.allowed?.should be_false access.allowed?.should be_falsey
access.message.should eq 'Pulling over HTTP is not allowed.' access.message.should eq 'Pulling over HTTP is not allowed.'
end end
end end
...@@ -317,7 +318,7 @@ describe GitlabNet, vcr: true do ...@@ -317,7 +318,7 @@ describe GitlabNet, vcr: true do
it 'should deny push access for host' do it 'should deny push access for host' do
VCR.use_cassette("http-push-disabled") do VCR.use_cassette("http-push-disabled") do
access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'http') access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'http')
access.allowed?.should be_false access.allowed?.should be_falsey
access.message.should eq 'Pushing over HTTP is not allowed.' access.message.should eq 'Pushing over HTTP is not allowed.'
end end
end end
...@@ -327,21 +328,21 @@ describe GitlabNet, vcr: true do ...@@ -327,21 +328,21 @@ describe GitlabNet, vcr: true do
it 'should deny pull access for host' do it 'should deny pull access for host' do
VCR.use_cassette("ssh-pull-project-denied") do VCR.use_cassette("ssh-pull-project-denied") do
access = gitlab_net.check_access('git-receive-pack', nil, project, key2, changes, 'ssh') access = gitlab_net.check_access('git-receive-pack', nil, project, key2, changes, 'ssh')
access.allowed?.should be_false access.allowed?.should be_falsey
end end
end end
it 'should deny push access for host' do it 'should deny push access for host' do
VCR.use_cassette("ssh-push-project-denied") do VCR.use_cassette("ssh-push-project-denied") do
access = gitlab_net.check_access('git-upload-pack', nil, project, key2, changes, 'ssh') access = gitlab_net.check_access('git-upload-pack', nil, project, key2, changes, 'ssh')
access.allowed?.should be_false access.allowed?.should be_falsey
end end
end end
it 'should deny push access for host (with user)' do it 'should deny push access for host (with user)' do
VCR.use_cassette("ssh-push-project-denied-with-user") do VCR.use_cassette("ssh-push-project-denied-with-user") do
access = gitlab_net.check_access('git-upload-pack', nil, project, 'user-2', changes, 'ssh') access = gitlab_net.check_access('git-upload-pack', nil, project, 'user-2', changes, 'ssh')
access.allowed?.should be_false access.allowed?.should be_falsey
end end
end end
end end
...@@ -354,24 +355,27 @@ describe GitlabNet, vcr: true do ...@@ -354,24 +355,27 @@ describe GitlabNet, vcr: true do
end end
end end
describe :base_api_endpoint do describe '#base_api_endpoint' do
let(:net) { GitlabNet.new } let(:net) { described_class.new }
subject { net.send :base_api_endpoint } subject { net.send :base_api_endpoint }
it { should include(net.send(:config).gitlab_url) } it { is_expected.to include(net.send(:config).gitlab_url) }
it("uses API version 4") { should end_with("api/v4") } it("uses API version 4") { should end_with("api/v4") }
end end
describe :internal_api_endpoint do describe '#internal_api_endpoint' do
let(:net) { GitlabNet.new } let(:net) { described_class.new }
subject { net.send :internal_api_endpoint } subject { net.send :internal_api_endpoint }
it { should include(net.send(:config).gitlab_url) } it { is_expected.to include(net.send(:config).gitlab_url) }
it("uses API version 4") { should end_with("api/v4/internal") } it("uses API version 4") { should end_with("api/v4/internal") }
end end
describe :http_client_for do describe '#http_client_for' do
subject { gitlab_net.send :http_client_for, URI('https://localhost/') } subject { gitlab_net.send :http_client_for, URI('https://localhost/') }
before do before do
gitlab_net.stub :cert_store gitlab_net.stub :cert_store
gitlab_net.send(:config).stub(:http_settings) { {'self_signed_cert' => true} } gitlab_net.send(:config).stub(:http_settings) { {'self_signed_cert' => true} }
...@@ -380,7 +384,7 @@ describe GitlabNet, vcr: true do ...@@ -380,7 +384,7 @@ describe GitlabNet, vcr: true do
its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) } its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) }
end end
describe :http_request_for do describe '#http_request_for' do
context 'with stub' do context 'with stub' do
let(:get) { double(Net::HTTP::Get) } let(:get) { double(Net::HTTP::Get) }
let(:user) { 'user' } let(:user) { 'user' }
...@@ -462,7 +466,7 @@ describe GitlabNet, vcr: true do ...@@ -462,7 +466,7 @@ describe GitlabNet, vcr: true do
end end
end end
describe :cert_store do describe '#cert_store' do
let(:store) do let(:store) do
double(OpenSSL::X509::Store).tap do |store| double(OpenSSL::X509::Store).tap do |store|
OpenSSL::X509::Store.stub(:new) { store } OpenSSL::X509::Store.stub(:new) { store }
......
...@@ -4,6 +4,7 @@ require_relative '../lib/gitlab_access_status' ...@@ -4,6 +4,7 @@ require_relative '../lib/gitlab_access_status'
describe GitlabShell do describe GitlabShell do
before do before do
$logger = double('logger').as_null_object
FileUtils.mkdir_p(tmp_repos_path) FileUtils.mkdir_p(tmp_repos_path)
end end
...@@ -428,7 +429,7 @@ describe GitlabShell do ...@@ -428,7 +429,7 @@ describe GitlabShell do
it "refuses to assign the path" do it "refuses to assign the path" do
$stderr.should_receive(:puts).with("GitLab: Invalid repository path") $stderr.should_receive(:puts).with("GitLab: Invalid repository path")
expect(subject.exec(ssh_cmd)).to be_false expect(subject.exec(ssh_cmd)).to be_falsey
end end
end end
end end
......
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..")) ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), ".."))
require 'rspec/its'
require 'simplecov' require 'simplecov'
SimpleCov.start SimpleCov.start
......
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