check if a box exists before beginning add action
This commit is contained in:
parent
025cede012
commit
c952fdaa24
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue