diff --git a/lib/vagrant/capability_host.rb b/lib/vagrant/capability_host.rb index 4c77930fa..c75f3c980 100644 --- a/lib/vagrant/capability_host.rb +++ b/lib/vagrant/capability_host.rb @@ -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 diff --git a/test/unit/base.rb b/test/unit/base.rb index 4218abcbf..db530c2e4 100644 --- a/test/unit/base.rb +++ b/test/unit/base.rb @@ -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 diff --git a/test/unit/support/shared/capability_helpers_context.rb b/test/unit/support/shared/capability_helpers_context.rb new file mode 100644 index 000000000..f336cc7c3 --- /dev/null +++ b/test/unit/support/shared/capability_helpers_context.rb @@ -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 diff --git a/test/unit/vagrant/capability_host_test.rb b/test/unit/vagrant/capability_host_test.rb index d35e81afb..d460a649b 100644 --- a/test/unit/vagrant/capability_host_test.rb +++ b/test/unit/vagrant/capability_host_test.rb @@ -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],