box remove subcommand

This commit is contained in:
Mitchell Hashimoto 2010-04-13 17:18:59 -07:00
parent f097ee3111
commit 797112cf84
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,31 @@
module Vagrant
class Commands
# Removes a box permanently from the hard drive.
module Box
class Remove < BoxCommand
BoxCommand.subcommand "remove", self
description "Remove an installed box permanently."
def execute(args=[])
if args.length != 1
show_help
return
end
box = Vagrant::Box.find(env, args[0])
if box.nil?
error_and_exit(:box_remove_doesnt_exist)
return # for tests
end
box.destroy
end
def options_spec(opts)
opts.banner = "Usage: vagrant box remove NAME"
end
end
end
end
end

View File

@ -0,0 +1,41 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class CommandsBoxRemoveTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::Box::Remove
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
@env = mock_environment
@env.stubs(:require_persisted_vm)
@env.stubs(:vm).returns(@persisted_vm)
@instance = @klass.new(@env)
end
context "executing" do
setup do
@name = "foo"
end
should "show help if not enough arguments" do
Vagrant::Box.expects(:find).never
@instance.expects(:show_help).once
@instance.execute([])
end
should "error and exit if the box doesn't exist" do
Vagrant::Box.expects(:find).returns(nil)
@instance.expects(:error_and_exit).with(:box_remove_doesnt_exist).once
@instance.execute([@name])
end
should "call destroy on the box if it exists" do
@box = mock("box")
Vagrant::Box.expects(:find).with(@env, @name).returns(@box)
@box.expects(:destroy).once
@instance.execute([@name])
end
end
end