diff --git a/lib/vagrant/action/box/download.rb b/lib/vagrant/action/box/download.rb index 32b008bc9..a8f46c8ad 100644 --- a/lib/vagrant/action/box/download.rb +++ b/lib/vagrant/action/box/download.rb @@ -26,13 +26,24 @@ module Vagrant end def instantiate_downloader - @env["download.classes"].each do |klass| - if klass.match?(@env["box"].uri) + # Assign to a temporary variable since this is easier to type out, + # since it is used so many times. + classes = @env["download.classes"] + + # Find the class to use. + classes.each_index do |i| + klass = classes[i] + + # Use the class if it matches the given URI or if this + # is the last class... + if classes.length == (i + 1) || klass.match?(@env["box"].uri) @env.ui.info I18n.t("vagrant.actions.box.download.with", :class => klass.to_s) @downloader = klass.new(@env) end end + # This line should never be reached, but we'll keep this here + # just in case for now. raise Errors::BoxDownloadUnknownType if !@downloader @downloader.prepare(@env["box"].uri) diff --git a/test/acceptance/box_test.rb b/test/acceptance/box_test.rb index 0164a250b..023f41768 100644 --- a/test/acceptance/box_test.rb +++ b/test/acceptance/box_test.rb @@ -19,4 +19,17 @@ class BoxTest < AcceptanceTest results = execute("vagrant", "box", "list") assert(results.stdout.read =~ /^foo$/, "Box should exist after it is added") end + + should "give a helpful error message if the file doesn't exist" do + # Add a box which doesn't exist + results = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box") + assert(!results.success?, "Box add should fail.") + assert(results.stdout.read =~ /^The specified path to a file doesn't exist.$/, + "This should show an error message about the file not existing.") + end + + should "add a box from an HTTP server" do + # TODO: Spin up an HTTP server to serve a file, add and test. + skip("Need to setup HTTP server functionality") + end end