diff --git a/lib/hobo.rb b/lib/hobo.rb index c5d135310..3b83ce490 100644 --- a/lib/hobo.rb +++ b/lib/hobo.rb @@ -2,8 +2,8 @@ libdir = File.dirname(__FILE__) $:.unshift(libdir) PROJECT_ROOT = File.join(libdir, '..') -require 'ostruct' require 'ftools' +require 'pathname' require 'logger' require 'virtualbox' require 'hobo/config' diff --git a/lib/hobo/env.rb b/lib/hobo/env.rb index 85eeddeff..af44cb5bc 100644 --- a/lib/hobo/env.rb +++ b/lib/hobo/env.rb @@ -8,7 +8,7 @@ module Hobo :files => CONFIG.merge({}), #additional files go mhia! :dirs => [HOME] #additional dirs go mhia! } - PATH_CHUNK_REGEX = /\/[^\/]+$/ + class << self def load! @@ -41,16 +41,16 @@ module Hobo @@persisted_uuid = load_dotfile end - def load_dotfile(dir=Dir.pwd) - return nil if dir.empty? + def load_dotfile(path=Pathname.new(Dir.pwd)) + return nil if path.to_s == '/' - file = "#{dir}/#{Hobo.config[:dotfile_name]}" + file = "#{path}/#{Hobo.config[:dotfile_name]}" if File.exists?(file) # TODO check multiple lines after the first for information return File.open(file, 'r').first end - load_dotfile(dir.sub(PATH_CHUNK_REGEX, '')) + load_dotfile(path.parent) end def persisted_uuid diff --git a/test/hobo/env_test.rb b/test/hobo/env_test.rb index 02e23230f..df4b8014c 100644 --- a/test/hobo/env_test.rb +++ b/test/hobo/env_test.rb @@ -73,9 +73,10 @@ class EnvTest < Test::Unit::TestCase test "should walk the parent directories looking for the dotfile" do Hobo.config! hobo_mock_config + #Expects exists with the current directory and .hobo File.expects(:exists?).with(dotfile).returns(false) - File.expects(:exists?).with(dotfile(Dir.pwd.sub(Hobo::Env::PATH_CHUNK_REGEX, ''))).returns(true) + File.expects(:exists?).with(dotfile(Dir.pwd.split('/')[0..-2].join('/'))).returns(true) File.expects(:open).returns(['foo']) Hobo::Env.load_uuid! assert_equal Hobo::Env.persisted_uuid, 'foo'