From 3fb5f5b0d9a6ad8c0f765acbc044c059ba85ea3e Mon Sep 17 00:00:00 2001 From: Joshua Nichols Date: Wed, 10 Mar 2010 08:31:44 -0500 Subject: [PATCH] Use construct for stubbing user_dir. --- lib/homesick.rb | 7 ++++++- spec/spec_helper.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index ec31a49..57225a7 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -46,10 +46,15 @@ class Homesick < Thor protected - def user_dir + # class method, so it's convenient to stub out during tests + def self.user_dir @user_dir ||= Pathname.new('~').expand_path end + def user_dir + self.class.user_dir + end + def homes_dir @homes_dir ||= Pathname.new('~/.homesick/repos').expand_path end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2cf79bb..821d9ba 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,4 +7,13 @@ require 'construct' Spec::Runner.configure do |config| config.include Construct::Helpers + + config.before do + @user_dir = create_construct + Homesick.stub!(:user_dir).and_return(@user_dir) + end + + config.after do + @user_dir.destroy! + end end