diff --git a/lib/hobo.rb b/lib/hobo.rb index 8d1c9e15c..c5d135310 100644 --- a/lib/hobo.rb +++ b/lib/hobo.rb @@ -14,4 +14,4 @@ require 'hobo/vm' # TODO: Make this configurable log_output = ENV['HOBO_ENV'] == 'test' ? nil : STDOUT HOBO_LOGGER = Logger.new(log_output) -Hobo::Env.load_config +Hobo::Env.load! unless ENV['HOBO_ENV'] == 'test' diff --git a/lib/hobo/env.rb b/lib/hobo/env.rb index 970c88757..7540fc315 100644 --- a/lib/hobo/env.rb +++ b/lib/hobo/env.rb @@ -10,6 +10,11 @@ module Hobo } class << self + def load! + load_config! + load_uuid! + end + def ensure_directories ENSURE[:dirs].each do |name| Dir.mkdir(name) unless File.exists?(name) @@ -22,7 +27,7 @@ module Hobo end end - def load_config + def load_config! ensure_directories ensure_files @@ -30,6 +35,15 @@ module Hobo parsed = YAML.load_file(CONFIG.keys.first) Hobo.config!(parsed) end + + def load_uuid! + # TODO check multiple lines after the first for information + @@persisted_uuid = File.open(Hobo.config[:dotfile_name], 'r').first + end + + def persisted_uuid + @@persisted_uuid + end end end end diff --git a/test/hobo/env_test.rb b/test/hobo/env_test.rb index 1285ecf03..7d613efeb 100644 --- a/test/hobo/env_test.rb +++ b/test/hobo/env_test.rb @@ -43,13 +43,34 @@ class EnvTest < Test::Unit::TestCase end test "should load of the default" do - YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config) - @handler.load_config + config_file_expectation + @handler.load_config! assert_equal Hobo.config[:ssh], hobo_mock_config[:ssh] end test "Hobo.config should be nil unless loaded" do assert_equal Hobo.config, nil end + + test "loading of the uuid from the dotfile" do + dot_file_expectation + Hobo.config! hobo_mock_config + Hobo::Env.load_uuid! + assert_equal Hobo::Env.persisted_uuid, 'foo' + end + + test "load! should load the config and set the persisted_uid" do + dot_file_expectation + config_file_expectation + Hobo::Env.load! + end + + def dot_file_expectation + File.expects(:open).with('.hobo', 'r').returns(['foo']) + end + + def config_file_expectation + YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config) + end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 67149c797..9d4f33cef 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ -begin + begin require File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment') rescue LoadError puts <<-ENVERR @@ -21,6 +21,7 @@ begin require 'ruby-debug' rescue LoadError; end + require File.join(File.dirname(__FILE__), '..', 'lib', 'hobo') require 'contest' require 'mocha' @@ -33,7 +34,8 @@ class Test::Unit::TestCase :pass => 'bar', :host => 'baz', :port => 'bak' - } + }, + :dotfile_name => '.hobo' } end -end \ No newline at end of file +end