Permalink
Browse files

test git-about

  • Loading branch information...
1 parent 273032a commit 0f00d4b88de1311297d6de947f28cec81a08f0b8 Michael Grosser committed Mar 14, 2012
Showing with 70 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .rspec
  3. +1 −1 Gemfile
  4. +2 −3 bin/git-about
  5. +65 −0 spec/cli_spec.rb
View
@@ -1,3 +1,4 @@
pkg/*
*.gem
.bundle
+spec/tmp
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
@@ -3,6 +3,6 @@ source "http://rubygems.org"
# Specify your gem's dependencies in pivotal_git_scripts.gemspec
gemspec
-
gem "rake"
gem "bundler"
+gem "rspec"
View
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
-
config = `git config -l`
user_name = `git config --get user.name`
-user_name = "NONE" if user_name.length == 0
+user_name = "NONE" if user_name.strip.length == 0
user_email = `git config --get user.email`
-user_email = "NONE" if user_email.length == 0
+user_email = "NONE" if user_email.strip.length == 0
begin
keyfile = File.readlink(File.expand_path("~/.ssh/id_github_current"))
View
@@ -0,0 +1,65 @@
+describe "CLI" do
+ before :all do
+ # use local scripts
+ ENV["PATH"] = "#{File.join(File.dirname(__FILE__),"..","bin")}:#{ENV["PATH"]}"
+ end
+
+ def run(command)
+ result = `#{command}`
+ raise "FAILED #{command} : #{result}" unless $?.success?
+ result
+ end
+
+ around do |example|
+ dir = "spec/tmp"
+ run "rm -rf #{dir}"
+ run "mkdir #{dir}"
+
+ # use fake home for .ssh hacks
+ run "mkdir #{dir}/home"
+ ENV["HOME"] = File.expand_path("#{dir}/home")
+
+ Dir.chdir dir do
+ run "touch a && git init && git add . && git commit -am 'initial'"
+ example.run
+ end
+ end
+
+ describe "about" do
+ it "lists the user" do
+ run "git config user.name NAME"
+ run("git about").should =~ /git user:\s+NAME/
+ end
+
+ it "lists the user as NONE if there is none" do
+ run "git config user.name ''"
+ run("git about").should =~ /git user:\s+NONE/
+ end
+
+ it "lists the email" do
+ run "git config user.email EMAIL"
+ run("git about").should =~ /git email:\s+EMAIL/
+ end
+
+ it "lists the email as NONE if there is none" do
+ run "git config user.email ''"
+ run("git about").should =~ /git email:\s+NONE/
+ end
+
+ it "does not find a project" do
+ run("git about").should =~ /GitHub project:\s+NONE/
+ end
+
+ context "with github project" do
+ before do
+ run "mkdir home/.ssh"
+ run "touch home/.ssh/id_github_foo"
+ run "ln -s home/.ssh/id_github_foo home/.ssh/id_github_current"
+ end
+
+ it "finds a project" do
+ run("git about").should =~ /GitHub project:\s+foo/
+ end
+ end
+ end
+end

0 comments on commit 0f00d4b

Please sign in to comment.