From 5c6ca57409c0eb93b7abde13068a385dbf28f0c4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 10 Dec 2011 13:09:03 -0800 Subject: [PATCH] Throw an error if a box already exists when calling box.add --- BRANCH_TODO | 1 - lib/vagrant/box_collection.rb | 2 ++ test/unit/vagrant/box_collection_test.rb | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index 96c0732d0..a9886b3c1 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -4,5 +4,4 @@ This is a TODO file for only this branch (config-overhaul) * Only allow one kind of vagrantfile to be loaded (i.e. if both Vagrantfile and vagrantfile exist, throw an error) * Nicer error if can't setup home directory -* vagrant box add should error if box already exists * Default name to folder name + timestamp \ No newline at end of file diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 18b40803d..682085bc2 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -33,6 +33,8 @@ module Vagrant # Adds a box to this collection with the given name and located # at the given URL. def add(name, url) + raise Errors::BoxAlreadyExists, :name => name if find(name) + @action_runner.run(:box_add, :box_name => name, :box_url => url, diff --git a/test/unit/vagrant/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index adb3fa818..3644f6182 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -31,6 +31,11 @@ describe Vagrant::BoxCollection do end end + it "should throw an error if the box already exists when adding" do + environment.box("foo") + expect { instance.add("foo", "bar") }.to raise_error(Vagrant::Errors::BoxAlreadyExists) + end + it "should add the box" do name = "foo" url = "bar"