Permalink
Browse files

check if a box exists before beginning add action

  • Loading branch information...
johnbender committed Mar 4, 2010
1 parent 025cede commit c952fdaa2407acbd4cbfd7b689332bdd393a81b8
Showing with 18 additions and 1 deletion.
  1. +5 −1 lib/vagrant/actions/box/add.rb
  2. +13 −0 test/vagrant/actions/box/add_test.rb
@@ -3,10 +3,14 @@ module Actions
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
end
end
end
-end
+end
@@ -3,6 +3,8 @@
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 @@ def setup_action_expectations
@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

0 comments on commit c952fda

Please sign in to comment.