Commit c8df6bcf authored by Ash McKenzie's avatar Ash McKenzie

Fix some rspec deprecations

parent f2eb95f0
......@@ -17,19 +17,19 @@ describe GitlabAccess do
end
subject do
GitlabAccess.new(nil, repo_path, 'key-123', 'wow', 'ssh').tap do |access|
access.stub(exec_cmd: :exec_called)
access.stub(api: api)
allow(access).to receive(:exec_cmd).and_return(:exec_called)
allow(access).to receive(:api).and_return(api)
end
end
before do
GitlabConfig.any_instance.stub(repos_path: repository_path)
allow_any_instance_of(GitlabConfig).to receive(:repos_path).and_return(repository_path)
end
describe :initialize do
it { subject.repo_path.should == repo_path }
it { subject.changes.should == ['wow'] }
it { subject.protocol.should == 'ssh' }
it { expect(subject.send(:repo_path)).to eql repo_path } # FIXME: don't access private instance variables
it { expect(subject.send(:changes)).to eql ['wow'] } # FIXME: don't access private instance variables
it { expect(subject.send(:protocol)).to eql 'ssh' } # FIXME: don't access private instance variables
end
describe "#exec" do
......@@ -61,7 +61,7 @@ describe GitlabAccess do
context "API connection fails" do
before do
api.stub(:check_access).and_raise(GitlabNet::ApiUnreachableError)
allow(api).to receive(:check_access).and_raise(GitlabNet::ApiUnreachableError)
end
it "returns false" do
......
......@@ -14,7 +14,7 @@ describe GitlabKeys do
end
it 'raises KeyError on invalid input' do
expect { described_class.command("\nssh-rsa AAA") }.to raise_error(described_class::KeyError)
expect do described_class.command("\nssh-rsa AAA") end.to raise_error(described_class::KeyError)
end
end
......@@ -30,16 +30,16 @@ describe GitlabKeys do
end
it 'raises KeyError on invalid input' do
expect { described_class.key_line('key-741', "ssh-rsa AAA\nssh-rsa AAA") }.to raise_error(described_class::KeyError)
expect do described_class.key_line('key-741', "ssh-rsa AAA\nssh-rsa AAA") end.to raise_error(described_class::KeyError)
end
end
describe :initialize do
let(:gitlab_keys) { build_gitlab_keys('add-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') }
it { gitlab_keys.key.should == 'ssh-rsa AAAAB3NzaDAxx2E' }
it { gitlab_keys.instance_variable_get(:@command).should == 'add-key' }
it { gitlab_keys.instance_variable_get(:@key_id).should == 'key-741' }
it { expect(gitlab_keys.key).to eql 'ssh-rsa AAAAB3NzaDAxx2E' }
it { expect(gitlab_keys.instance_variable_get(:@command)).to eql 'add-key' }
it { expect(gitlab_keys.instance_variable_get(:@key_id)).to eql 'key-741' }
end
describe :add_key do
......@@ -49,7 +49,7 @@ describe GitlabKeys do
create_authorized_keys_fixture
gitlab_keys.send :add_key
auth_line = "command=\"#{ROOT_PATH}/bin/gitlab-shell key-741\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E"
File.read(tmp_authorized_keys_path).should == "existing content\n#{auth_line}\n"
expect(File.read(tmp_authorized_keys_path)).to eql "existing content\n#{auth_line}\n"
end
context "without file writing" do
......@@ -57,12 +57,12 @@ describe GitlabKeys do
before { create_authorized_keys_fixture }
it "should log an add-key event" do
$logger.should_receive(:info).with("Adding key", {:key_id=>"key-741", :public_key=>"ssh-rsa AAAAB3NzaDAxx2E"})
expect($logger).to receive(:info).with("Adding key", {:key_id=>"key-741", :public_key=>"ssh-rsa AAAAB3NzaDAxx2E"})
gitlab_keys.send :add_key
end
it "should return true" do
gitlab_keys.send(:add_key).should be_truthy
expect(gitlab_keys.send(:add_key)).to be_truthy
end
end
end
......@@ -76,7 +76,7 @@ describe GitlabKeys do
create_authorized_keys_fixture
gitlab_keys.send :add_key
auth_line1 = 'key-741 AAAAB3NzaDAxx2E'
gitlab_keys.send(:list_keys).should == "#{auth_line1}\n"
expect(gitlab_keys.send(:list_keys)).to eql "#{auth_line1}\n"
end
end
......@@ -90,10 +90,9 @@ describe GitlabKeys do
end
it 'outputs the key IDs, separated by newlines' do
output = capture_stdout do
expect do
gitlab_keys.send(:list_key_ids)
end
output.should match "1\n2\n3\n9000"
end.to output("1\n2\n3\n9000\n").to_stdout
end
end
......@@ -102,38 +101,38 @@ describe GitlabKeys do
let(:fake_stdin) { StringIO.new("key-12\tssh-dsa ASDFASGADG\nkey-123\tssh-rsa GFDGDFSGSDFG\n", 'r') }
before do
create_authorized_keys_fixture
gitlab_keys.stub(stdin: fake_stdin)
allow(gitlab_keys).to receive(:stdin).and_return(fake_stdin)
end
it "adds lines at the end of the file" do
gitlab_keys.send :batch_add_keys
auth_line1 = "command=\"#{ROOT_PATH}/bin/gitlab-shell key-12\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dsa ASDFASGADG"
auth_line2 = "command=\"#{ROOT_PATH}/bin/gitlab-shell key-123\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa GFDGDFSGSDFG"
File.read(tmp_authorized_keys_path).should == "existing content\n#{auth_line1}\n#{auth_line2}\n"
expect(File.read(tmp_authorized_keys_path)).to eql "existing content\n#{auth_line1}\n#{auth_line2}\n"
end
context "with invalid input" do
let(:fake_stdin) { StringIO.new("key-12\tssh-dsa ASDFASGADG\nkey-123\tssh-rsa GFDGDFSGSDFG\nfoo\tbar\tbaz\n", 'r') }
it "aborts" do
gitlab_keys.should_receive(:abort)
expect(gitlab_keys).to receive(:abort)
gitlab_keys.send :batch_add_keys
end
end
context "without file writing" do
before do
gitlab_keys.should_receive(:open).and_yield(double(:file, puts: nil, chmod: nil))
expect(gitlab_keys).to receive(:open).and_yield(double(:file, puts: nil, chmod: nil))
end
it "should log an add-key event" do
$logger.should_receive(:info).with("Adding key", key_id: 'key-12', public_key: "ssh-dsa ASDFASGADG")
$logger.should_receive(:info).with("Adding key", key_id: 'key-123', public_key: "ssh-rsa GFDGDFSGSDFG")
expect($logger).to receive(:info).with("Adding key", key_id: 'key-12', public_key: "ssh-dsa ASDFASGADG")
expect($logger).to receive(:info).with("Adding key", key_id: 'key-123', public_key: "ssh-rsa GFDGDFSGSDFG")
gitlab_keys.send :batch_add_keys
end
it "should return true" do
gitlab_keys.send(:batch_add_keys).should be_truthy
expect(gitlab_keys.send(:batch_add_keys)).to be_truthy
end
end
end
......@@ -159,22 +158,22 @@ describe GitlabKeys do
end
gitlab_keys.send :rm_key
erased_line = delete_line.gsub(/./, '#')
File.read(tmp_authorized_keys_path).should == "existing content\n#{erased_line}\n#{other_line}\n"
expect(File.read(tmp_authorized_keys_path)).to eql "existing content\n#{erased_line}\n#{other_line}\n"
end
context "without file writing" do
before do
gitlab_keys.stub(:open)
gitlab_keys.stub(:lock).and_yield
allow(gitlab_keys).to receive(:open)
allow(gitlab_keys).to receive(:lock).and_yield
end
it "should log an rm-key event" do
$logger.should_receive(:info).with("Removing key", key_id: "key-741")
expect($logger).to receive(:info).with("Removing key", key_id: "key-741")
gitlab_keys.send :rm_key
end
it "should return true" do
gitlab_keys.send(:rm_key).should be_truthy
expect(gitlab_keys.send(:rm_key)).to be_truthy
end
end
......@@ -191,7 +190,7 @@ describe GitlabKeys do
end
gitlab_keys.send :rm_key
erased_line = delete_line.gsub(/./, '#')
File.read(tmp_authorized_keys_path).should == "existing content\n#{erased_line}\n#{other_line}\n"
expect(File.read(tmp_authorized_keys_path)).to eql "existing content\n#{erased_line}\n#{other_line}\n"
end
end
end
......@@ -200,8 +199,8 @@ describe GitlabKeys do
let(:gitlab_keys) { build_gitlab_keys('clear') }
it "should return true" do
gitlab_keys.stub(:open)
gitlab_keys.send(:clear).should be_truthy
allow(gitlab_keys).to receive(:open)
expect(gitlab_keys.send(:clear)).to be_truthy
end
end
......@@ -214,7 +213,7 @@ describe GitlabKeys do
end
it 'returns false if opening raises an exception' do
gitlab_keys.should_receive(:open_auth_file).and_raise("imaginary error")
expect(gitlab_keys).to receive(:open_auth_file).and_raise("imaginary error")
expect(gitlab_keys.exec).to eq(false)
end
......@@ -229,51 +228,51 @@ describe GitlabKeys do
describe :exec do
it 'add-key arg should execute add_key method' do
gitlab_keys = build_gitlab_keys('add-key')
gitlab_keys.should_receive(:add_key)
expect(gitlab_keys).to receive(:add_key)
gitlab_keys.exec
end
it 'batch-add-keys arg should execute batch_add_keys method' do
gitlab_keys = build_gitlab_keys('batch-add-keys')
gitlab_keys.should_receive(:batch_add_keys)
expect(gitlab_keys).to receive(:batch_add_keys)
gitlab_keys.exec
end
it 'rm-key arg should execute rm_key method' do
gitlab_keys = build_gitlab_keys('rm-key')
gitlab_keys.should_receive(:rm_key)
expect(gitlab_keys).to receive(:rm_key)
gitlab_keys.exec
end
it 'clear arg should execute clear method' do
gitlab_keys = build_gitlab_keys('clear')
gitlab_keys.should_receive(:clear)
expect(gitlab_keys).to receive(:clear)
gitlab_keys.exec
end
it 'check-permissions arg should execute check_permissions method' do
gitlab_keys = build_gitlab_keys('check-permissions')
gitlab_keys.should_receive(:check_permissions)
expect(gitlab_keys).to receive(:check_permissions)
gitlab_keys.exec
end
it 'should puts message if unknown command arg' do
gitlab_keys = build_gitlab_keys('change-key')
gitlab_keys.should_receive(:puts).with('not allowed')
expect(gitlab_keys).to receive(:puts).with('not allowed')
gitlab_keys.exec
end
it 'should log a warning on unknown commands' do
gitlab_keys = build_gitlab_keys('nooope')
gitlab_keys.stub(puts: nil)
$logger.should_receive(:warn).with("Attempt to execute invalid gitlab-keys command", command: '"nooope"')
allow(gitlab_keys).to receive(:puts).and_return(nil)
expect($logger).to receive(:warn).with("Attempt to execute invalid gitlab-keys command", command: '"nooope"')
gitlab_keys.exec
end
end
describe :lock do
before do
GitlabKeys.any_instance.stub(lock_file: tmp_lock_file_path)
allow_any_instance_of(GitlabKeys).to receive(:lock_file).and_return(tmp_lock_file_path)
end
it "should raise exception if operation lasts more then timeout" do
......@@ -282,7 +281,7 @@ describe GitlabKeys do
key.send :lock, 1 do
sleep 2
end
end.to raise_error
end.to raise_error(Timeout::Error)
end
it "should actually lock file" do
......@@ -307,7 +306,7 @@ describe GitlabKeys do
end
thr1.join
$global.should == "foobar"
expect($global).to eql "foobar"
end
end
......@@ -325,7 +324,7 @@ describe GitlabKeys do
def create_authorized_keys_fixture(existing_content: 'existing content')
FileUtils.mkdir_p(File.dirname(tmp_authorized_keys_path))
open(tmp_authorized_keys_path, 'w') { |file| file.puts(existing_content) }
gitlab_keys.stub(auth_file: tmp_authorized_keys_path)
allow(gitlab_keys).to receive(:auth_file).and_return(tmp_authorized_keys_path)
end
def tmp_authorized_keys_path
......
......@@ -16,22 +16,22 @@ describe GitlabLfsAuthentication do
end
describe '#build_from_json' do
it { subject.username.should == 'dzaporozhets' }
it { subject.lfs_token.should == 'wsnys8Zm8Jn7zyhHTAAK' }
it { subject.repository_http_path.should == 'http://gitlab.dev/repo' }
it { expect(subject.username).to eql 'dzaporozhets' }
it { expect(subject.lfs_token).to eql 'wsnys8Zm8Jn7zyhHTAAK' }
it { expect(subject.repository_http_path).to eql 'http://gitlab.dev/repo' }
end
describe '#authentication_payload' do
result = "{\"header\":{\"Authorization\":\"Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL\"},\"href\":\"http://gitlab.dev/repo/info/lfs/\"}"
it { subject.authentication_payload.should eq(result) }
it { expect(subject.authentication_payload).to eq(result) }
it 'should be a proper JSON' do
payload = subject.authentication_payload
json_payload = JSON.parse(payload)
json_payload['header']['Authorization'].should eq('Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL')
json_payload['href'].should eq('http://gitlab.dev/repo/info/lfs/')
expect(json_payload['header']['Authorization']).to eq('Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL')
expect(json_payload['href']).to eq('http://gitlab.dev/repo/info/lfs/')
end
end
end
......@@ -6,7 +6,7 @@ describe :convert_log_level do
subject { convert_log_level :extreme }
it "converts invalid log level to Logger::INFO" do
$stderr.should_receive(:puts).at_least(:once)
expect($stderr).to receive(:puts).at_least(:once)
should eq(Logger::INFO)
end
end
......
require_relative 'spec_helper'
require_relative '../lib/gitlab_net'
require_relative '../lib/gitlab_access_status'
describe GitlabNet, vcr: true do
let(:gitlab_net) { described_class.new }
......@@ -14,28 +13,28 @@ describe GitlabNet, vcr: true do
before do
$logger = double('logger').as_null_object
gitlab_net.stub(:base_api_endpoint).and_return(base_api_endpoint)
gitlab_net.stub(:secret_token).and_return(secret)
allow(gitlab_net).to receive(:base_api_endpoint).and_return(base_api_endpoint)
allow(gitlab_net).to receive(:secret_token).and_return(secret)
end
describe '#check' do
it 'should return 200 code for gitlab check' do
VCR.use_cassette("check-ok") do
result = gitlab_net.check
result.code.should == '200'
expect(result.code).to eql('200')
end
end
it 'adds the secret_token to request' do
VCR.use_cassette("check-ok") do
Net::HTTP::Get.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
allow_any_instance_of(Net::HTTP::Get).to receive(:set_form_data).with(hash_including(secret_token: secret))
gitlab_net.check
end
end
it "raises an exception if the connection fails" do
Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
expect { gitlab_net.check }.to raise_error(GitlabNet::ApiUnreachableError)
allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
expect do gitlab_net.check end.to raise_error(GitlabNet::ApiUnreachableError)
end
end
......@@ -43,21 +42,21 @@ describe GitlabNet, vcr: true do
it 'should return user has based on key id' do
VCR.use_cassette("discover-ok") do
user = gitlab_net.discover(key)
user['name'].should == 'Administrator'
user['username'].should == 'root'
expect(user['name']).to eql 'Administrator'
expect(user['username']).to eql 'root'
end
end
it 'adds the secret_token to request' do
VCR.use_cassette("discover-ok") do
Net::HTTP::Get.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
allow_any_instance_of(Net::HTTP::Get).to receive(:set_form_data).with(hash_including(secret_token: secret))
gitlab_net.discover(key)
end
end
it "raises an exception if the connection fails" do
VCR.use_cassette("discover-ok") do
Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
expect { gitlab_net.discover(key) }.to raise_error(GitlabNet::ApiUnreachableError)
end
end
......@@ -68,9 +67,9 @@ describe GitlabNet, vcr: true do
it 'should return the correct data' do
VCR.use_cassette('lfs-authenticate-ok') do
lfs_access = gitlab_net.lfs_authenticate(key, project)
lfs_access.username.should == 'root'
lfs_access.lfs_token.should == 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
lfs_access.repository_http_path.should == URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s
expect(lfs_access.username).to eql 'root'
expect(lfs_access.lfs_token).to eql 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
expect(lfs_access.repository_http_path).to eql URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s
end
end
end
......@@ -81,7 +80,7 @@ describe GitlabNet, vcr: true do
it 'should return message' do
VCR.use_cassette("broadcast_message-ok") do
result = gitlab_net.broadcast_message
result["message"].should == "Message"
expect(result["message"]).to eql "Message"
end
end
end
......@@ -90,7 +89,7 @@ describe GitlabNet, vcr: true do
it 'should return nil' do
VCR.use_cassette("broadcast_message-none") do
result = gitlab_net.broadcast_message
result.should == {}
expect(result).to eql({})
end
end
end
......@@ -102,13 +101,13 @@ describe GitlabNet, vcr: true do
let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" }
it "sends the given arguments as encoded URL parameters" do
gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
gitlab_net.merge_request_urls(gl_repository, project, changes)
end
it "omits the gl_repository parameter if it's nil" do
gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
gitlab_net.merge_request_urls(nil, project, changes)
end
......@@ -135,8 +134,7 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.pre_receive(gl_repository) }
it 'sends the correct parameters and returns the request body parsed' do
Net::HTTP::Post.any_instance.should_receive(:set_form_data)
.with(hash_including(params))
allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
VCR.use_cassette("pre-receive") { subject }
end
......@@ -149,7 +147,7 @@ describe GitlabNet, vcr: true do
it 'throws a NotFound error when pre-receive is not available' do
VCR.use_cassette("pre-receive-not-found") do
expect { subject }.to raise_error(GitlabNet::NotFound)
expect do subject end.to raise_error(GitlabNet::NotFound)
end
end
end
......@@ -171,7 +169,7 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.post_receive(gl_repository, key, changes) }
it 'sends the correct parameters' do
Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
VCR.use_cassette("post-receive") do
......@@ -189,7 +187,7 @@ describe GitlabNet, vcr: true do
it 'throws a NotFound error when post-receive is not available' do
VCR.use_cassette("post-receive-not-found") do
expect { subject }.to raise_error(GitlabNet::NotFound)
expect do subject end.to raise_error(GitlabNet::NotFound)
end
end
end
......@@ -200,21 +198,21 @@ describe GitlabNet, vcr: true do
it "should return nil when the resource is not implemented" do
VCR.use_cassette("ssh-key-not-implemented") do
result = gitlab_net.authorized_key("whatever")
result.should be_nil
expect(result).to be_nil
end
end
it "should return nil when the fingerprint is not found" do
VCR.use_cassette("ssh-key-not-found") do
result = gitlab_net.authorized_key("whatever")
result.should be_nil
expect(result).to be_nil
end
end
it "should return a ssh key with a valid fingerprint" do
VCR.use_cassette("ssh-key-ok") do
result = gitlab_net.authorized_key(ssh_key)
result.should eq({
expect(result).to eql({
"can_push" => false,
"created_at" => "2017-06-21T09:50:07.150Z",
"id" => 99,
......@@ -252,7 +250,7 @@ describe GitlabNet, vcr: true do
it 'sets the arguments as form parameters' do
VCR.use_cassette('notify-post-receive') do
Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
gitlab_net.notify_post_receive(gl_repository, repo_path)
end
end
......@@ -274,8 +272,8 @@ describe GitlabNet, vcr: true do
end
it 'adds the secret_token to the request' do
VCR.use_cassette("allowed-pull") do
Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
VCR.use_cassette('allowed-pull') do
allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(secret_token: secret))
gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh')
end
end
......@@ -377,8 +375,8 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_client_for, URI('https://localhost/') }
before do
gitlab_net.stub :cert_store
gitlab_net.send(:config).stub(:http_settings) { {'self_signed_cert' => true} }
allow(gitlab_net).to receive(:cert_store)
allow(gitlab_net.send(:config)).to receive(:http_settings).and_return({ 'self_signed_cert' => true })
end
its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) }
......@@ -398,11 +396,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url }
before do
gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
Net::HTTP::Get.should_receive(:new).with('/', {}).and_return(get)
get.should_receive(:basic_auth).with(user, password).once
get.should_receive(:set_form_data).with(hash_including(secret_token: secret)).once
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
expect(Net::HTTP::Get).to receive(:new).with('/', {}).and_return(get)
expect(get).to receive(:basic_auth).with(user, password).once
expect(get).to receive(:set_form_data).with(hash_including(secret_token: secret)).once
end
it { should_not be_nil }
......@@ -412,11 +410,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, params: params, headers: headers }
before do
gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
Net::HTTP::Get.should_receive(:new).with('/', headers).and_return(get)
get.should_receive(:basic_auth).with(user, password).once
get.should_receive(:set_form_data).with({ 'key1' => 'value1', secret_token: secret }).once
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
expect(Net::HTTP::Get).to receive(:new).with('/', headers).and_return(get)
expect(get).to receive(:basic_auth).with(user, password).once
expect(get).to receive(:set_form_data).with({ 'key1' => 'value1', secret_token: secret }).once
end
it { should_not be_nil }
......@@ -426,11 +424,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, headers: headers }
before do
gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
Net::HTTP::Get.should_receive(:new).with('/', headers).and_return(get)
get.should_receive(:basic_auth).with(user, password).once
get.should_receive(:set_form_data).with(hash_including(secret_token: secret)).once
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
expect(Net::HTTP::Get).to receive(:new).with('/', headers).and_return(get)
expect(get).to receive(:basic_auth).with(user, password).once
expect(get).to receive(:set_form_data).with(hash_including(secret_token: secret)).once
end
it { should_not be_nil }
......@@ -441,12 +439,12 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, options: options }
before do
gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
Net::HTTP::Get.should_receive(:new).with('/', {}).and_return(get)
get.should_receive(:basic_auth).with(user, password).once
get.should_receive(:body=).with({ 'key2' => 'value2', secret_token: secret }.to_json).once
get.should_not_receive(:set_form_data)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
expect(Net::HTTP::Get).to receive(:new).with('/', {}).and_return(get)
expect(get).to receive(:basic_auth).with(user, password).once
expect(get).to receive(:body=).with({ 'key2' => 'value2', secret_token: secret }.to_json).once
expect(get).to_not receive(:set_form_data)
end
it { should_not be_nil }
......@@ -457,7 +455,7 @@ describe GitlabNet, vcr: true do
context 'Unix socket' do
it 'sets the Host header to "localhost"' do
gitlab_net = described_class.new
gitlab_net.should_receive(:secret_token).and_return(secret)
expect(gitlab_net).to receive(:secret_token).and_return(secret)
request = gitlab_net.send(:http_request_for, :get, URI('http+unix://%2Ffoo'))
......@@ -469,12 +467,12 @@ describe GitlabNet, vcr: true do
describe '#cert_store' do
let(:store) do
double(OpenSSL::X509::Store).tap do |store|
OpenSSL::X509::Store.stub(:new) { store }
allow(OpenSSL::X509::Store).to receive(:new).and_return(store)
end
end
before :each do
store.should_receive(:set_default_paths).once
expect(store).to receive(:set_default_paths).once
end
after do
......@@ -482,17 +480,17 @@ describe GitlabNet, vcr: true do
end
it "calls add_file with http_settings['ca_file']" do
gitlab_net.send(:config).http_settings.stub(:[]).with('ca_file') { 'test_file' }
gitlab_net.send(:config).http_settings.stub(:[]).with('ca_path') { nil }
store.should_receive(:add_file).with('test_file')
store.should_not_receive(:add_path)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_file').and_return('test_file')
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_path').and_return(nil)
expect(store).to receive(:add_file).with('test_file')
expect(store).to_not receive(:add_path)
end
it "calls add_path with http_settings['ca_path']" do
gitlab_net.send(:config).http_settings.stub(:[]).with('ca_file') { nil }
gitlab_net.send(:config).http_settings.stub(:[]).with('ca_path') { 'test_path' }
store.should_not_receive(:add_file)
store.should_receive(:add_path).with('test_path')
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_file').and_return(nil)
allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_path').and_return('test_path')
expect(store).to_not receive(:add_file)
expect(store).to receive(:add_path).with('test_path')
end
end
end
......@@ -31,7 +31,7 @@ describe GitlabPostReceive do
before do
$logger = double('logger').as_null_object # Global vars are bad
GitlabConfig.any_instance.stub(repos_path: repository_path)
allow_any_instance_of(GitlabConfig).to receive(:repos_path).and_return(repository_path)
end
describe "#exec" do
......
......@@ -5,8 +5,8 @@ describe NamesHelper do
include NamesHelper
describe :extract_ref_name do
it { extract_ref_name('refs/heads/awesome-feature').should == 'awesome-feature' }
it { extract_ref_name('refs/tags/v2.2.1').should == 'v2.2.1' }
it { extract_ref_name('refs/tags/releases/v2.2.1').should == 'releases/v2.2.1' }
it { expect(extract_ref_name('refs/heads/awesome-feature')).to eql 'awesome-feature' }
it { expect(extract_ref_name('refs/tags/v2.2.1')).to eql 'v2.2.1' }
it { expect(extract_ref_name('refs/tags/releases/v2.2.1')).to eql 'releases/v2.2.1' }
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