check if a box exists before beginning add action

This commit is contained in:
John Bender 2010-03-03 23:47:16 -08:00
parent 025cede012
commit c952fdaa24
2 changed files with 18 additions and 1 deletions

View File

@ -3,6 +3,10 @@ module Vagrant
module Box
class Add < Base
def prepare
if File.exists?(@runner.directory)
raise ActionException.new("A box with the name '#{@runner.name}' already exists, please use another name or use `vagrant box remove #{@runner.name}`")
end
@runner.add_action(Download)
@runner.add_action(Unpackage)
end

View File

@ -3,6 +3,8 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class AddBoxActionTest < Test::Unit::TestCase
setup do
@runner, @vm, @action = mock_action(Vagrant::Actions::Box::Add)
@runner.stubs(:directory).returns("foo")
File.stubs(:exists?).returns(false)
mock_config
end
@ -23,4 +25,15 @@ class AddBoxActionTest < Test::Unit::TestCase
@action.prepare
end
end
context "providing a name for a base that exists" do
should "result in an action exception" do
File.expects(:exists?).once.returns(true)
@runner.expects(:name).twice.returns('foo')
@runner.expects(:add_action).never
assert_raise Vagrant::Actions::ActionException do
@action.prepare
end
end
end
end