Added directory_with_contents() to DRY up test code and ensure folders exist in TestCommand.

This commit is contained in:
Parker Moore 2013-03-16 14:09:53 +01:00
parent d93faac3b8
commit 52efb71aa2
2 changed files with 11 additions and 2 deletions

View File

@ -43,6 +43,12 @@ class Test::Unit::TestCase
File.join(File.dirname(__FILE__), *subdirs)
end
def directory_with_contents(path)
FileUtils.rm_rf(path)
FileUtils.mkdir(path)
File.open("#{path}/index.html", "w"){ |f| f.write("I was previously generated.") }
end
def capture_stdout
$old_stdout = $stdout
$stdout = StringIO.new

View File

@ -6,19 +6,22 @@ class TestCommand < Test::Unit::TestCase
setup do
@source = source_dir
@dest = dest_dir
directory_with_contents(@dest)
@globs = Command.globs(@source, @dest)
end
should "return an array without the destination dir" do
assert @globs.is_a?(Array)
assert !@globs.include?(@dest)
end
teardown do
clear_dest
end
end
context "when using default dest dir" do
setup do
@source = test_dir
@dest = test_dir('_site')
FileUtils.mkdir(@dest)
File.open("#{@dest}/index.html", "w"){ |f| f.write("I was previously generated.") }
directory_with_contents(@dest)
@globs = Command.globs(@source, @dest)
end
should "return an array without the destination dir" do