diff --git a/plugins/communicators/winrm/helper.rb b/plugins/communicators/winrm/helper.rb index dd266969e..f1fe8a4d0 100644 --- a/plugins/communicators/winrm/helper.rb +++ b/plugins/communicators/winrm/helper.rb @@ -58,7 +58,7 @@ module VagrantPlugins # ports. port = nil if machine.provider.capability?(:forwarded_ports) - machine.provider.capability(:forwarded_ports).each do |host, guest| + Array(machine.provider.capability(:forwarded_ports)).each do |host, guest| if guest == machine.config.winrm.guest_port port = host break diff --git a/test/unit/plugins/communicators/winrm/helper_test.rb b/test/unit/plugins/communicators/winrm/helper_test.rb index 1bf5beebb..1b942ac80 100644 --- a/test/unit/plugins/communicators/winrm/helper_test.rb +++ b/test/unit/plugins/communicators/winrm/helper_test.rb @@ -147,6 +147,15 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do expect(subject.winrm_port(machine)).to eq(2456) end + + it "does not error when the provider capability returns nil result" do + machine.config.winrm.port = 22 + machine.config.winrm.guest_port = 2222 + machine.config.vm.network "forwarded_port", host: 1234, guest: 2222 + allow(machine.provider).to receive(:capability).with(:forwarded_ports).and_return(nil) + + expect(subject.winrm_port(machine)).to eq(1234) + end end describe ".winrm_info_invalid?" do