From f48b0796a5f32dcca2d0063a3ccd0e3c36ff5793 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 3 Apr 2013 22:20:45 -0700 Subject: [PATCH] Forward arguments down to capability --- lib/vagrant/guest.rb | 4 ++-- test/unit/vagrant/guest_test.rb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/guest.rb b/lib/vagrant/guest.rb index f13dc4885..be63ff3df 100644 --- a/lib/vagrant/guest.rb +++ b/lib/vagrant/guest.rb @@ -109,7 +109,7 @@ module Vagrant # Executes the capability with the given name, optionally passing # more arguments onwards to the capability. - def capability(cap_name) + def capability(cap_name, *args) @logger.info("Execute capability: #{cap_name} (#{@chain[0][0]})") cap_mod = capability_module(cap_name) if !cap_mod @@ -127,7 +127,7 @@ module Vagrant :guest => @chain[0][0].to_s end - cap_method.call + cap_method.call(*args) end # This returns whether the guest is ready to work. If this returns diff --git a/test/unit/vagrant/guest_test.rb b/test/unit/vagrant/guest_test.rb index f530e7046..454dce84e 100644 --- a/test/unit/vagrant/guest_test.rb +++ b/test/unit/vagrant/guest_test.rb @@ -17,8 +17,8 @@ describe Vagrant::Guest do cap = Class.new do if !options[:corrupt] - define_method(capability) do - raise "cap: #{capability}" + define_method(capability) do |*args| + raise "cap: #{capability} #{args.inspect}" end end end @@ -58,7 +58,14 @@ describe Vagrant::Guest do register_capability(:bar, :test) expect { subject.capability(:test) }. - to raise_error(RuntimeError, "cap: test") + to raise_error(RuntimeError, "cap: test []") + end + + it "executes the capability with arguments" do + register_capability(:bar, :test) + + expect { subject.capability(:test, 1) }. + to raise_error(RuntimeError, "cap: test [1]") end it "raises an exception if the capability doesn't exist" do