core: pass extra args to detect? when detecting capability host

This commit is contained in:
Mitchell Hashimoto 2014-01-07 16:26:58 -08:00
parent b15cb22e3e
commit 1f760b2c48
4 changed files with 40 additions and 21 deletions

View File

@ -32,7 +32,7 @@ module Vagrant
end
if !host
host = autodetect_capability_host(hosts) if !host
host = autodetect_capability_host(hosts, *args) if !host
raise Errors::CapabilityHostNotDetected if !host
end

View File

@ -14,6 +14,7 @@ require "unit/support/dummy_communicator"
require "unit/support/dummy_provider"
require "unit/support/shared/base_context"
require "unit/support/shared/action_synced_folders_context"
require "unit/support/shared/capability_helpers_context"
require "unit/support/shared/virtualbox_context"
# Do not buffer output

View File

@ -0,0 +1,21 @@
shared_context "capability_helpers" do
def detect_class(result)
Class.new do
define_method(:detect?) do
result
end
end
end
def cap_instance(name, options=nil)
options ||= {}
Class.new do
if !options[:corrupt]
define_method(name) do |*args|
raise "cap: #{name} #{args.inspect}"
end
end
end.new
end
end

View File

@ -3,32 +3,14 @@ require File.expand_path("../../base", __FILE__)
require "vagrant/capability_host"
describe Vagrant::CapabilityHost do
include_context "capability_helpers"
subject do
Class.new do
extend Vagrant::CapabilityHost
end
end
def detect_class(result)
Class.new do
define_method(:detect?) do
result
end
end
end
def cap_instance(name, options=nil)
options ||= {}
Class.new do
if !options[:corrupt]
define_method(name) do |*args|
raise "cap: #{name} #{args.inspect}"
end
end
end.new
end
describe "#initialize_capabilities! and #capability_host_chain" do
it "raises an error if an explicit host is not found" do
expect { subject.initialize_capabilities!(:foo, {}, {}) }.
@ -45,6 +27,21 @@ describe Vagrant::CapabilityHost do
to raise_error(Vagrant::Errors::CapabilityHostNotDetected)
end
it "passes on extra args to the detect method" do
klass = Class.new do
def detect?(*args)
raise "detect: #{args.inspect}"
end
end
hosts = {
foo: [klass, nil],
}
expect { subject.initialize_capabilities!(nil, hosts, {}, 1, 2) }.
to raise_error(RuntimeError, "detect: [1, 2]")
end
it "detects a basic child" do
hosts = {
foo: [detect_class(false), nil],