Moved the destroy logic out to a re-usable box action.
This commit is contained in:
parent
546db294ca
commit
c7e21a0c94
|
@ -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
|
|
@ -32,7 +32,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def destroy
|
||||
FileUtils.rm_rf(directory)
|
||||
execute!(Actions::Box::Destroy)
|
||||
end
|
||||
|
||||
def directory
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue