diff --git a/lib/vagrant/actions/package.rb b/lib/vagrant/actions/package.rb index a5b89af8b..72644d566 100644 --- a/lib/vagrant/actions/package.rb +++ b/lib/vagrant/actions/package.rb @@ -14,11 +14,15 @@ module Vagrant compress logger.info "Removing working directory ..." - FileUtils.rm_r(working_dir) + clean tar_path end + def clean + FileUtils.rm_r(working_dir) + end + def working_dir FileUtils.mkpath(File.join(@to, @name)) end diff --git a/test/vagrant/actions/package_test.rb b/test/vagrant/actions/package_test.rb index 01c0d16ad..879c0e414 100644 --- a/test/vagrant/actions/package_test.rb +++ b/test/vagrant/actions/package_test.rb @@ -6,21 +6,53 @@ class PackageActionTest < Test::Unit::TestCase @action.to = '/foo/bar/baz' @action.name = 'bing' mock_config - end - - should "setup and correct working directory and export to it" do - working_dir = File.join(@action.to, @action.name) - FileUtils.expects(:rm_r).with(working_dir) - @action.expects(:compress) - assert_equal @action.execute!, "#{working_dir}.box" end - should "return the target file and the proper extension for tar_path" do - assert_equal File.join(@action.to, @action.name + Vagrant.config.package.extension), @action.tar_path + context "executing" do + setup do + @tar_path = "foo" + + @action.stubs(:compress) + @action.stubs(:clean) + @action.stubs(:tar_path).returns(@tar_path) + end + + should "compress and remove the working directory" do + package_seq = sequence("package_seq") + @action.expects(:compress).in_sequence(package_seq) + @action.expects(:clean).in_sequence(package_seq) + @action.execute! + end + + should "return the tar path" do + assert_equal @tar_path, @action.execute! + end end - should "return the target working dir" do - assert_equal File.join(@action.to, @action.name), @action.working_dir + context "cleaning up" do + setup do + @working_dir = "foo" + @action.stubs(:working_dir).returns(@working_dir) + end + + should "remove the working directory" do + FileUtils.expects(:rm_r).with(@working_dir).once + @action.clean + end + end + + context "working directory" do + should "create the directory" do + FileUtils.expects(:mkpath).with(File.join(@action.to, @action.name)) + @action.working_dir + end + end + + context "tar path" do + should "be the working directory with the extension attached" do + @action.expects(:working_dir).returns("foo") + assert_equal "foo#{Vagrant.config.package.extension}", @action.tar_path + end end # TODO test compression once its finished