2010-01-22 07:38:23 +00:00
|
|
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
|
|
|
|
|
|
class EnvTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
context "Hobo environment handler" do
|
|
|
|
setup do
|
|
|
|
@handler = Hobo::Env.new
|
2010-01-22 08:56:27 +00:00
|
|
|
@ensure = Hobo::Env::ENSURE
|
2010-01-22 07:38:23 +00:00
|
|
|
end
|
|
|
|
|
2010-01-22 08:56:27 +00:00
|
|
|
test "should not create any directories if they exist" do
|
|
|
|
File.expects(:exists?).times(@ensure[:dirs].length).returns(true)
|
|
|
|
Dir.expects(:mkdir).never
|
2010-01-22 07:38:23 +00:00
|
|
|
@handler.ensure_directories
|
|
|
|
end
|
|
|
|
|
2010-01-22 08:56:27 +00:00
|
|
|
test "should not copy any files if they exist" do
|
|
|
|
File.expects(:exists?).times(@ensure[:files].length).returns(true)
|
|
|
|
File.expects(:copy).never
|
2010-01-22 07:38:23 +00:00
|
|
|
@handler.ensure_files
|
|
|
|
end
|
2010-01-22 09:47:28 +00:00
|
|
|
|
|
|
|
test "should create the ensured directories if they don't exist" do
|
|
|
|
file_seq = sequence("file_seq")
|
|
|
|
|
|
|
|
@ensure[:dirs].each do |dir|
|
|
|
|
File.expects(:exists?).returns(false).in_sequence(file_seq)
|
|
|
|
Dir.expects(:mkdir).with(dir).in_sequence(file_seq)
|
|
|
|
end
|
|
|
|
|
|
|
|
@handler.ensure_directories
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should create the ensured files if they don't exist" do
|
|
|
|
file_seq = sequence("file_seq")
|
|
|
|
|
|
|
|
@ensure[:files].each do |target, default|
|
|
|
|
File.expects(:exists?).with(target).returns(false).in_sequence(file_seq)
|
|
|
|
File.expects(:copy).with(File.join(PROJECT_ROOT, default), target).in_sequence(file_seq)
|
|
|
|
end
|
|
|
|
|
|
|
|
@handler.ensure_files
|
|
|
|
end
|
2010-01-22 07:38:23 +00:00
|
|
|
|
|
|
|
test "should load configuration" do
|
2010-01-22 09:47:28 +00:00
|
|
|
@handler.expects(:ensure_directories).once
|
|
|
|
@handler.expects(:ensure_files).once
|
2010-01-22 07:38:23 +00:00
|
|
|
@handler.load_config do |file|
|
2010-01-22 07:57:43 +00:00
|
|
|
assert_equal file, Hobo::Env::CONFIG.keys.first
|
2010-01-22 07:38:23 +00:00
|
|
|
{ :setting => 1 }
|
|
|
|
end
|
2010-01-22 08:37:50 +00:00
|
|
|
|
2010-01-24 07:38:31 +00:00
|
|
|
assert_equal Hobo.config[:setting], 1
|
2010-01-22 07:38:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|