Stricter test coverage on env.rb

This commit is contained in:
Mitchell Hashimoto 2010-01-22 01:47:28 -08:00
parent 62f7682f9b
commit 148cd091bb
2 changed files with 25 additions and 13 deletions

View File

@ -15,7 +15,7 @@ module Hobo
def ensure_files
ENSURE[:files].each do |target, default|
File.copy(PROJECT_ROOT + default, target) unless File.exists?(target)
File.copy(File.join(PROJECT_ROOT, default), target) unless File.exists?(target)
end
end

View File

@ -20,9 +20,31 @@ class EnvTest < Test::Unit::TestCase
@handler.ensure_files
end
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
test "should load configuration" do
dir_expectations
file_expectations
@handler.expects(:ensure_directories).once
@handler.expects(:ensure_files).once
@handler.load_config do |file|
assert_equal file, Hobo::Env::CONFIG.keys.first
{ :setting => 1 }
@ -31,14 +53,4 @@ class EnvTest < Test::Unit::TestCase
assert_equal Hobo.config.setting, 1
end
end
def dir_expectations
File.expects(:exists?).times(@ensure[:dirs].length).returns(false)
Dir.expects(:mkdir).times(@ensure[:dirs].length).returns nil
end
def file_expectations
File.expects(:exists?).times(@ensure[:files].length).returns(false)
File.expects(:copy).times(@ensure[:files].length)
end
end