From e37a3531aba0c7627877bc293b98267d63d8d645 Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Mon, 13 Feb 2017 22:48:13 +0900 Subject: [PATCH 1/2] Instance can be nil, this condition should be cared --- spec/kitchen/driver/vagrant_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/kitchen/driver/vagrant_spec.rb b/spec/kitchen/driver/vagrant_spec.rb index 46699842..44f8cd43 100644 --- a/spec/kitchen/driver/vagrant_spec.rb +++ b/spec/kitchen/driver/vagrant_spec.rb @@ -48,6 +48,10 @@ d end + let(:driver_with_no_instance) do + driver_object + end + let(:instance) do Kitchen::Instance.new( :verifier => verifier, @@ -540,6 +544,12 @@ def run_command(_cmd, options = {}) driver.verify_dependencies end + it "passes for supported versions of Vagrant when it has no instances" do + with_modern_vagrant + + driver_with_no_instance.verify_dependencies + end + it "raises a UserError for unsupported versions of Vagrant" do with_unsupported_vagrant From 3a60651ecc6d3bb94650e6e1b366b2f369f7fdf7 Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Mon, 13 Feb 2017 22:59:26 +0900 Subject: [PATCH 2/2] Avoid to access `instance.name` when the instance is a nil --- lib/kitchen/driver/vagrant.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 297bef9e..69c13489 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -469,10 +469,13 @@ def local_kitchen_cache # instance's Vagrantfile # @api private def vagrant_root - root = File.join(config[:kitchen_root], %w{.kitchen kitchen-vagrant}, - "kitchen-#{File.basename(config[:kitchen_root])}-#{instance.name}" - ) - @vagrant_root ||= instance.nil? ? nil : root + if !@vagrant_root && !instance.nil? + @vagrant_root = File.join( + config[:kitchen_root], %w{.kitchen kitchen-vagrant}, + "kitchen-#{File.basename(config[:kitchen_root])}-#{instance.name}" + ) + end + @vagrant_root end # @param type [Symbol] either `:ssh` or `:winrm`