Remove method calls to "Box.find" and remove method

This commit is contained in:
Mitchell Hashimoto 2010-09-11 10:21:35 -07:00
parent 0ee21998f6
commit 761da0de63
5 changed files with 5 additions and 79 deletions

View File

@ -10,7 +10,7 @@ module Vagrant
box_name = env["config"].vm.box
raise Errors::BoxNotSpecified.new if !box_name
if !Vagrant::Box.find(env.env , box_name)
if !env.env.boxes.find(box_name)
box_url = env["config"].vm.box_url
raise Errors::BoxSpecifiedDoesntExist.new(:name => box_name) if !box_url

View File

@ -5,41 +5,6 @@ module Vagrant
# and may contain additional files if specified by the creator. This
# class serves to help manage these boxes, although most of the logic
# is kicked out to actions.
#
# What can the {Box} class do?
#
# * Find boxes
# * Add existing boxes (from some URI)
# * Delete existing boxes
#
# # Finding Boxes
#
# Using the {Box.find} method, you can search for existing boxes. This
# method will return `nil` if none is found or an instance of {Box}
# otherwise.
#
# box = Vagrant::Box.find("base")
# if box.nil?
# puts "Box not found!"
# else
# puts "Box exists at #{box.directory}"
# end
#
# # Adding a Box
#
# Boxes can be added from any URI. Some schemas aren't supported; if this
# is the case, the error will output to the logger.
#
# Vagrant::Box.add("foo", "http://myfiles.com/foo.box")
#
# # Destroying a box
#
# Boxes can be deleted as well. This method is _final_ and there is no way
# to undo this action once it is completed.
#
# box = Vagrant::Box.find("foo")
# box.destroy
#
class Box
# The name of the box.
attr_accessor :name
@ -69,17 +34,6 @@ module Vagrant
results
end
# Finds a box with the given name. This method searches for a box
# with the given name, returning `nil` if none is found or returning
# a {Box} instance otherwise.
#
# @param [String] name The name of the box
# @return [Box] Instance of {Box} representing the box found
def find(env, name)
return nil unless File.directory?(directory(env, name))
new(env, name)
end
# Adds a new box with given name from the given URI. This method
# begins the process of adding a box from a given URI by setting up
# the {Box} instance and calling {#add}.

View File

@ -10,14 +10,14 @@ module Vagrant
desc "remove NAME", "Remove a box from the system"
def remove(name)
b = Box.find(env, name)
b = env.boxes.find(env, name)
raise BoxNotFound.new(:name => name) if !b
b.destroy
end
desc "repackage NAME", "Repackage an installed box into a `.box` file."
def repackage(name)
b = Box.find(env, name)
b = env.boxes.find(env, name)
raise BoxNotFound.new(:name => name) if !b
b.repackage
end

View File

@ -7,7 +7,6 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
context "calling" do
setup do
Vagrant::Box.stubs(:find)
end
should "raise error if box not specified" do
@ -31,7 +30,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
instance = @klass.new(app, env)
app.expects(:call).never
Vagrant::Box.expects(:find).with(env.env, env["config"].vm.box).returns(nil)
env.env.boxes.expects(:find).with(env["config"].vm.box).returns(nil)
assert_raises(Vagrant::Errors::BoxSpecifiedDoesntExist) {
instance.call(env)
@ -46,7 +45,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
instance = @klass.new(app, env)
seq = sequence("seq")
Vagrant::Box.expects(:find).returns(nil)
env.env.boxes.expects(:find).returns(nil)
Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq)
env.env.expects(:load_box!).in_sequence(seq)
app.expects(:call).with(env).once.in_sequence(seq)

View File

@ -53,33 +53,6 @@ class BoxTest < Test::Unit::TestCase
end
end
context "finding" do
setup do
@dir = "foo"
@name = "bar"
Vagrant::Box.stubs(:directory).with(@env, @name).returns(@dir)
end
should "return nil if the box doesn't exist" do
File.expects(:directory?).with(@dir).once.returns(false)
assert_nil Vagrant::Box.find(@env, @name)
end
should "return a box object with the proper name set" do
File.expects(:directory?).with(@dir).once.returns(true)
result = Vagrant::Box.find(@env, @name)
assert result
assert_equal @name, result.name
end
should "return a box object with the proper env set" do
File.expects(:directory?).with(@dir).once.returns(true)
result = Vagrant::Box.find(@env, @name)
assert result
assert_equal @env, result.env
end
end
context "adding" do
setup do
@name = "foo"