Moved the destroy logic out to a re-usable box action.

This commit is contained in:
Mitchell Hashimoto 2010-02-22 21:32:15 -08:00
parent 546db294ca
commit c7e21a0c94
4 changed files with 33 additions and 8 deletions

View File

@ -0,0 +1,12 @@
module Vagrant
module Actions
module Box
class Destroy < Base
def execute!
logger.info "Deleting box directory..."
FileUtils.rm_rf(@runner.directory)
end
end
end
end
end

View File

@ -32,7 +32,7 @@ module Vagrant
end
def destroy
FileUtils.rm_rf(directory)
execute!(Actions::Box::Destroy)
end
def directory

View File

@ -0,0 +1,18 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class DestroyBoxActionTest < Test::Unit::TestCase
setup do
@name = "foo"
@dir = "foo"
@runner, @vm, @action = mock_action(Vagrant::Actions::Box::Destroy)
@runner.stubs(:directory).returns(@dir)
mock_config
end
context "executing" do
should "rm_rf the directory" do
FileUtils.expects(:rm_rf).with(@dir).once
@action.execute!
end
end
end

View File

@ -73,13 +73,8 @@ class BoxTest < Test::Unit::TestCase
end
context "destroying" do
setup do
@dir = mock("directory")
@box.stubs(:directory).returns(@dir)
end
should "rm_rf the directory" do
FileUtils.expects(:rm_rf).with(@dir).once
should "execute the destroy action" do
@box.expects(:execute!).with(Vagrant::Actions::Box::Destroy).once
@box.destroy
end
end