summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-05 09:52:10 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-05 09:52:10 +0200
commitea6ea902bea6857d2a0dbdf6d5492105a527d276 (patch)
tree7e49eae43ce42b10c3df61ed7ae8e63884700523
parent8d37428444f255a79ed99cb7726977b7195c6ebb (diff)
downloadgitlab-shell-ea6ea902bea6857d2a0dbdf6d5492105a527d276.tar.gz
More tests
-rw-r--r--Gemfile6
-rw-r--r--Gemfile.lock20
-rw-r--r--Guardfile24
-rw-r--r--lib/gitlab_keys.rb6
-rw-r--r--lib/gitlab_shell.rb2
-rw-r--r--spec/gitlab_shell_spec.rb57
6 files changed, 106 insertions, 9 deletions
diff --git a/Gemfile b/Gemfile
index 838c0e8..1756e4f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,7 @@
source "http://rubygems.org"
-gem 'rspec'
+group :development do
+ gem 'rspec'
+ gem 'guard'
+ gem 'guard-rspec'
+end
diff --git a/Gemfile.lock b/Gemfile.lock
index b210821..6b7360d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,23 @@
GEM
remote: http://rubygems.org/
specs:
+ coderay (1.0.8)
diff-lcs (1.1.3)
+ guard (1.5.4)
+ listen (>= 0.4.2)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
+ thor (>= 0.14.6)
+ guard-rspec (2.1.2)
+ guard (>= 1.1)
+ rspec (~> 2.11)
+ listen (0.5.3)
+ lumberjack (1.0.2)
+ method_source (0.8.1)
+ pry (0.9.10)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.3.1)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
@@ -10,9 +26,13 @@ GEM
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
+ slop (3.3.3)
+ thor (0.16.0)
PLATFORMS
ruby
DEPENDENCIES
+ guard
+ guard-rspec
rspec
diff --git a/Guardfile b/Guardfile
new file mode 100644
index 0000000..f547850
--- /dev/null
+++ b/Guardfile
@@ -0,0 +1,24 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara features specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
+
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index 7eae17c..1cbaffb 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -15,7 +15,6 @@ class GitlabKeys
case @command
when 'add-key'; add_key
when 'rm-key'; rm_key
- when 'rm-user'; rm_user
else
puts 'not allowed'
end
@@ -33,9 +32,4 @@ class GitlabKeys
cmd = "sed '/#{@key}/d' #{auth_file}"
system(cmd)
end
-
- def rm_user
- cmd = "sed -i '/gitlab-shell #{@username},/d' #{auth_file}"
- system(cmd)
- end
end
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index dd56e3d..0223ded 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -4,7 +4,7 @@ require 'net/http'
require_relative 'gitlab_config'
class GitlabShell
- attr_accessor :username, :repo_name, :git_cmd, :repos_path
+ attr_accessor :username, :repo_name, :git_cmd, :repos_path, :repo_name
def initialize
@username = ARGV.shift
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index 1132e81..fa46fb5 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -5,7 +5,7 @@ describe GitlabShell do
describe :initialize do
before do
- ENV['SSH_ORIGINAL_COMMAND'] = 'git-receive-pack'
+ ssh_cmd 'git-receive-pack'
ARGV[0] = 'dzaporozhets'
@shell = GitlabShell.new
end
@@ -13,4 +13,59 @@ describe GitlabShell do
it { @shell.username.should == 'dzaporozhets' }
it { @shell.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
+ end
+
+ it { @shell.repo_name.should == 'gitlab-ci.git' }
+ it { @shell.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
+ end
+
+ it { @shell.repo_name.should == 'dmitriy.zaporozhets/gitlab-ci.git' }
+ it { @shell.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
+
+ it { @shell.exec.should be_true }
+ end
+
+ context 'git-receive-pack' do
+ before do
+ ssh_cmd 'git-receive-pack gitlab-ci.git'
+ stubbed_shell
+ end
+
+ it { @shell.exec.should be_true }
+ end
+ end
+
+ def ssh_cmd(cmd)
+ ENV['SSH_ORIGINAL_COMMAND'] = cmd
+ end
+
+ def stubbed_shell
+ ARGV[0] = 'dzaporozhets'
+ @shell = GitlabShell.new
+ @shell.stub(validate_access: true)
+ @shell.stub(process_cmd: true)
+ end
end