From 59c140ab82e093566edf8a8cdefdd3e30361a905 Mon Sep 17 00:00:00 2001 From: Shawn Neal Date: Wed, 23 Apr 2014 16:12:27 -0700 Subject: [PATCH 1/2] Fixed Windows test code style to use more elegant tap method --- test/unit/plugins/communicators/winrm/communicator_test.rb | 6 +++--- test/unit/plugins/communicators/winrm/shell_test.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/plugins/communicators/winrm/communicator_test.rb b/test/unit/plugins/communicators/winrm/communicator_test.rb index 0a884008b..c3dd52884 100644 --- a/test/unit/plugins/communicators/winrm/communicator_test.rb +++ b/test/unit/plugins/communicators/winrm/communicator_test.rb @@ -12,9 +12,9 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do let(:shell) { double("shell") } subject do - comm = described_class.new(machine) - allow(comm).to receive(:create_shell).and_return(shell) - comm + described_class.new(machine).tap do |comm| + allow(comm).to receive(:create_shell).and_return(shell) + end end describe ".ready?" do diff --git a/test/unit/plugins/communicators/winrm/shell_test.rb b/test/unit/plugins/communicators/winrm/shell_test.rb index e3ef7a18f..480902df0 100644 --- a/test/unit/plugins/communicators/winrm/shell_test.rb +++ b/test/unit/plugins/communicators/winrm/shell_test.rb @@ -8,9 +8,9 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do let(:session) { double("winrm_session") } subject do - comm = described_class.new('localhost', 'username', 'password') - allow(comm).to receive(:new_session).and_return(session) - comm + described_class.new('localhost', 'username', 'password').tap do |comm| + allow(comm).to receive(:new_session).and_return(session) + end end describe ".powershell" do From fdb6461af4bb67452c51eb5fcff4e650414322af Mon Sep 17 00:00:00 2001 From: Shawn Neal Date: Wed, 23 Apr 2014 16:16:08 -0700 Subject: [PATCH 2/2] Fixed Windows tests to use modern Ruby hash style --- .../communicators/winrm/communicator_test.rb | 14 +++++++------- .../unit/plugins/communicators/winrm/shell_test.rb | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/unit/plugins/communicators/winrm/communicator_test.rb b/test/unit/plugins/communicators/winrm/communicator_test.rb index c3dd52884..84a4e8bd2 100644 --- a/test/unit/plugins/communicators/winrm/communicator_test.rb +++ b/test/unit/plugins/communicators/winrm/communicator_test.rb @@ -19,7 +19,7 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do describe ".ready?" do it "returns true if hostname command executes without error" do - expect(shell).to receive(:powershell).with("hostname").and_return({ :exitcode => 0 }) + expect(shell).to receive(:powershell).with("hostname").and_return({ exitcode: 0 }) expect(subject.ready?).to be_true end @@ -38,35 +38,35 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do describe ".execute" do it "defaults to running in powershell" do - expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 0 }) + expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 0 }) expect(subject.execute("dir")).to eq(0) end it "can use cmd shell" do - expect(shell).to receive(:cmd).with(kind_of(String)).and_return({ :exitcode => 0 }) + expect(shell).to receive(:cmd).with(kind_of(String)).and_return({ exitcode: 0 }) expect(subject.execute("dir", { :shell => :cmd })).to eq(0) end it "raises error when error_check is true and exit code is non-zero" do - expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 1 }) + expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 1 }) expect { subject.execute("dir") }.to raise_error( VagrantPlugins::CommunicatorWinRM::Errors::ExecutionError) end it "does not raise error when error_check is false and exit code is non-zero" do - expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 1 }) + expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 1 }) expect(subject.execute("dir", { :error_check => false })).to eq(1) end end describe ".test" do it "returns true when exit code is zero" do - expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 0 }) + expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 0 }) expect(subject.test("test -d c:/windows")).to be_true end it "returns false when exit code is non-zero" do - expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 1 }) + expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 1 }) expect(subject.test("test -d /tmp/foobar")).to be_false end diff --git a/test/unit/plugins/communicators/winrm/shell_test.rb b/test/unit/plugins/communicators/winrm/shell_test.rb index 480902df0..79d6970d8 100644 --- a/test/unit/plugins/communicators/winrm/shell_test.rb +++ b/test/unit/plugins/communicators/winrm/shell_test.rb @@ -15,7 +15,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do describe ".powershell" do it "should call winrm powershell" do - expect(session).to receive(:powershell).with("dir").and_return({ :exitcode => 0 }) + expect(session).to receive(:powershell).with("dir").and_return({ exitcode: 0 }) expect(subject.powershell("dir")[:exitcode]).to eq(0) end @@ -36,7 +36,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do describe ".cmd" do it "should call winrm cmd" do - expect(session).to receive(:cmd).with("dir").and_return({ :exitcode => 0 }) + expect(session).to receive(:cmd).with("dir").and_return({ exitcode: 0 }) expect(subject.cmd("dir")[:exitcode]).to eq(0) end end @@ -50,8 +50,8 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do describe ".endpoint_options" do it "should create endpoint options" do expect(subject.send(:endpoint_options)).to eq( - { :user => "username", :pass => "password", :host => "localhost", :port => 5985, - :operation_timeout => 60, :basic_auth_only => true }) + { user: "username", pass: "password", host: "localhost", port: 5985, + operation_timeout: 60, basic_auth_only: true }) end end