Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test git-about

  • Loading branch information...
commit 0f00d4b88de1311297d6de947f28cec81a08f0b8 1 parent 273032a
Michael Grosser authored
View
1  .gitignore
@@ -1,3 +1,4 @@
pkg/*
*.gem
.bundle
+spec/tmp
View
1  .rspec
@@ -0,0 +1 @@
+--color
View
2  Gemfile
@@ -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
5 bin/git-about
@@ -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
65 spec/cli_spec.rb
@@ -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.
Something went wrong with that request. Please try again.