Throw an error if a box already exists when calling box.add

This commit is contained in:
Mitchell Hashimoto 2011-12-10 13:09:03 -08:00
parent 21acff0e79
commit 5c6ca57409
3 changed files with 7 additions and 1 deletions

View File

@ -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 * Only allow one kind of vagrantfile to be loaded (i.e. if both
Vagrantfile and vagrantfile exist, throw an error) Vagrantfile and vagrantfile exist, throw an error)
* Nicer error if can't setup home directory * Nicer error if can't setup home directory
* vagrant box add should error if box already exists
* Default name to folder name + timestamp * Default name to folder name + timestamp

View File

@ -33,6 +33,8 @@ module Vagrant
# Adds a box to this collection with the given name and located # Adds a box to this collection with the given name and located
# at the given URL. # at the given URL.
def add(name, url) def add(name, url)
raise Errors::BoxAlreadyExists, :name => name if find(name)
@action_runner.run(:box_add, @action_runner.run(:box_add,
:box_name => name, :box_name => name,
:box_url => url, :box_url => url,

View File

@ -31,6 +31,11 @@ describe Vagrant::BoxCollection do
end end
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 it "should add the box" do
name = "foo" name = "foo"
url = "bar" url = "bar"