Commit 0c6686b6 authored by Christian Höltje's avatar Christian Höltje

Cleaned up gitlab_shell_spec

* Used mocks to test if methods are colled
* Increased coverage
* Removed duplication and excess verbage
parent e8d93d07
......@@ -2,58 +2,94 @@ require_relative 'spec_helper'
require_relative '../lib/gitlab_shell'
describe GitlabShell do
describe :initialize do
before do
ssh_cmd 'git-receive-pack'
ARGV[0] = 'key-56'
@shell = GitlabShell.new
subject do
ARGV[0] = 'key-56'
GitlabShell.new.tap do |shell|
shell.stub(process_cmd: true)
shell.stub(api: api)
end
end
let(:api) do
double(GitlabNet).tap do |api|
api.stub(discover: 'John Doe')
api.stub(allowed?: true)
end
end
describe :initialize do
before { ssh_cmd 'git-receive-pack' }
it { @shell.key_id.should == 'key-56' }
it { @shell.repos_path.should == "/home/git/repositories" }
its(:key_id) { should == 'key-56' }
its(:repos_path) { should == "/home/git/repositories" }
end
describe :parse_cmd do
context 'w/o namespace' do
before do
ssh_cmd 'git-upload-pack gitlab-ci.git'
@shell = GitlabShell.new
@shell.send :parse_cmd
subject.send :parse_cmd
end
it { @shell.repo_name.should == 'gitlab-ci.git' }
it { @shell.git_cmd.should == 'git-upload-pack' }
its(:repo_name) { should == 'gitlab-ci.git' }
its(:git_cmd) { should == 'git-upload-pack' }
end
context 'namespace' do
before do
ssh_cmd 'git-upload-pack dmitriy.zaporozhets/gitlab-ci.git'
@shell = GitlabShell.new
@shell.send :parse_cmd
subject.send :parse_cmd
end
it { @shell.repo_name.should == 'dmitriy.zaporozhets/gitlab-ci.git' }
it { @shell.git_cmd.should == 'git-upload-pack' }
its(:repo_name) { should == 'dmitriy.zaporozhets/gitlab-ci.git' }
its(:git_cmd) { should == 'git-upload-pack' }
end
end
describe :exec do
context 'git-upload-pack' do
before do
ssh_cmd 'git-upload-pack gitlab-ci.git'
stubbed_shell
end
before { ssh_cmd 'git-upload-pack gitlab-ci.git' }
after { subject.exec }
it { @shell.exec.should be_true }
it "should process the command" do
subject.should_receive(:process_cmd).with()
end
end
context 'git-receive-pack' do
before do
ssh_cmd 'git-receive-pack gitlab-ci.git'
stubbed_shell
before { ssh_cmd 'git-receive-pack gitlab-ci.git' }
after { subject.exec }
it "should process the command" do
subject.should_receive(:process_cmd).with()
end
end
context 'arbitrary command' do
before { ssh_cmd 'arbitrary command' }
after { subject.exec }
it { @shell.exec.should be_true }
it "should not process the command" do
subject.should_not_receive(:process_cmd)
end
end
context 'no command' do
before { ssh_cmd nil }
after { subject.exec }
it "should call api.discover" do
api.should_receive(:discover).with('key-56')
end
end
end
describe :validate_access do
before { ssh_cmd 'git-upload-pack gitlab-ci.git' }
after { subject.exec }
it "should call api.allowed?" do
api.should_receive(:allowed?).
with('git-upload-pack', 'gitlab-ci.git', 'key-56', '_any')
end
end
......@@ -61,10 +97,4 @@ describe GitlabShell do
ENV['SSH_ORIGINAL_COMMAND'] = cmd
end
def stubbed_shell
ARGV[0] = 'key-56'
@shell = GitlabShell.new
@shell.stub(validate_access: true)
@shell.stub(process_cmd: true)
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