vagrant/test/hobo/env_test.rb

45 lines
1.2 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
@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
test "should load configuration" do
dir_expectations
file_expectations
@handler.load_config do |file|
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
assert_equal Hobo.config.setting, 1
2010-01-22 07:38:23 +00:00
end
end
def dir_expectations
2010-01-22 08:56:27 +00:00
File.expects(:exists?).times(@ensure[:dirs].length).returns(false)
Dir.expects(:mkdir).times(@ensure[:dirs].length).returns nil
2010-01-22 07:38:23 +00:00
end
def file_expectations
2010-01-22 08:56:27 +00:00
File.expects(:exists?).times(@ensure[:files].length).returns(false)
File.expects(:copy).times(@ensure[:files].length)
2010-01-22 07:38:23 +00:00
end
end