vagrant/test/hobo/env_test.rb

56 lines
1.7 KiB
Ruby
Raw Normal View History

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
2010-01-26 08:01:17 +00:00
@handler = Hobo::Env
2010-01-22 08:56:27 +00:00
@ensure = Hobo::Env::ENSURE
2010-01-30 06:39:45 +00:00
Hobo.config! nil
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
2010-01-30 06:39:45 +00:00
test "should load of the default" do
YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config)
2010-01-26 08:01:17 +00:00
@handler.load_config
assert_equal Hobo.config[:ssh], hobo_mock_config[:ssh]
2010-01-22 07:38:23 +00:00
end
2010-01-30 06:39:45 +00:00
test "Hobo.config should be nil unless loaded" do
assert_equal Hobo.config, nil
end
2010-01-22 07:38:23 +00:00
end
end