From 0579f944304e1b452214c886339fd48be476c6aa Mon Sep 17 00:00:00 2001 From: Joshua Nichols Date: Thu, 1 Apr 2010 20:59:24 -0400 Subject: [PATCH] Moving towards testing list more. --- lib/homesick.rb | 12 +++++------- spec/homesick_spec.rb | 20 ++++++++++++++++++++ spec/spec_helper.rb | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index 6e9da4f..a0fa207 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -54,11 +54,9 @@ class Homesick < Thor desc "list", "List cloned castles" def list - inside repos_dir do - Pathname.glob('*') do |home| - inside home do - say_status home, `git config remote.origin.url`, :cyan - end + Pathname.glob(repos_dir + "*") do |castle| + Dir.chdir castle do # so we can call git config from the right contxt + say_status castle.basename.to_s, `git config remote.origin.url`.chomp, :cyan end end end @@ -67,11 +65,11 @@ class Homesick < Thor no_tasks do # class method, so it's convenient to stub out during tests def self.user_dir - @user_dir ||= Pathname.new('~').expand_path + @user_dir ||= Pathname.new(ENV['HOME'] || '~').expand_path end def self.repos_dir - @repos_dir ||= Pathname.new('~/.homesick/repos').expand_path + @repos_dir ||= user_dir.join('.homesick', 'repos').expand_path end def repos_dir diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 9cdba4d..39247e3 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -30,4 +30,24 @@ describe Homesick do @homesick.clone "wfarr/dotfiles" end end + + describe "list" do + + # FIXME only passes in isolation. need to setup data a bit better + xit "should say each castle in the castle directory" do + @user_dir.directory '.homesick/repos' do |repos_dir| + repos_dir.directory 'zomg' do |zomg| + Dir.chdir do + system "git init >/dev/null 2>&1" + system "git remote add origin git://github.com/technicalpickles/zomg.git >/dev/null 2>&1" + end + end + end + + @homesick.should_receive(:say_status).with("zomg", "git://github.com/technicalpickles/zomg.git", :cyan) + + @homesick.list + end + + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 821d9ba..57ef7c8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,7 @@ Spec::Runner.configure do |config| config.before do @user_dir = create_construct - Homesick.stub!(:user_dir).and_return(@user_dir) + ENV['HOME'] = @user_dir.to_s end config.after do