diff options
author | Christian Höltje <choltje@us.ibm.com> | 2013-03-15 13:00:13 -0400 |
---|---|---|
committer | Christian Höltje <choltje@us.ibm.com> | 2013-03-15 13:00:13 -0400 |
commit | 0c6686b6e129db9086ac3fe0e896c892fe73f428 (patch) | |
tree | ec2d91d2fc9500e90462f62bb2bf4c91ed4b0aee /spec/gitlab_shell_spec.rb | |
parent | e8d93d0769b99aaab9e5d360345e355b3e682ddf (diff) | |
download | gitlab-shell-0c6686b6e129db9086ac3fe0e896c892fe73f428.tar.gz |
Cleaned up gitlab_shell_spec
* Used mocks to test if methods are colled
* Increased coverage
* Removed duplication and excess verbage
Diffstat (limited to 'spec/gitlab_shell_spec.rb')
-rw-r--r-- | spec/gitlab_shell_spec.rb | 90 |
1 files changed, 60 insertions, 30 deletions
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb index 11815d7..51e02dd 100644 --- a/spec/gitlab_shell_spec.rb +++ b/spec/gitlab_shell_spec.rb @@ -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 |