core: pass extra args to detect? when detecting capability host
This commit is contained in:
parent
b15cb22e3e
commit
1f760b2c48
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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],
|
||||
|
|
Loading…
Reference in New Issue