diff --git a/plugins/guests/freebsd/cap/halt.rb b/plugins/guests/freebsd/cap/halt.rb index 4408fb051..237c942bb 100644 --- a/plugins/guests/freebsd/cap/halt.rb +++ b/plugins/guests/freebsd/cap/halt.rb @@ -4,7 +4,7 @@ module VagrantPlugins class Halt def self.halt(machine) begin - machine.communicate.sudo("shutdown -p now", {shell: "sh"}) + machine.communicate.sudo("shutdown -p now", { shell: "sh" }) rescue IOError # Do nothing because SSH connection closed and it probably # means the VM just shut down really fast. diff --git a/test/unit/plugins/guests/freebsd/cap/halt_test.rb b/test/unit/plugins/guests/freebsd/cap/halt_test.rb new file mode 100644 index 000000000..e44de83d6 --- /dev/null +++ b/test/unit/plugins/guests/freebsd/cap/halt_test.rb @@ -0,0 +1,35 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestFreeBSD::Cap::Halt" do + let(:described_class) do + VagrantPlugins::GuestFreeBSD::Plugin + .components + .guest_capabilities[:freebsd] + .get(:halt) + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + after do + comm.verify_expectations! + end + + describe ".halt" do + it "runs the shutdown command" do + comm.expect_command("shutdown -p now") + described_class.halt(machine) + end + + it "does not raise an IOError" do + comm.stub_command("shutdown -p now", raise: IOError) + expect { + described_class.halt(machine) + }.to_not raise_error + end + end +end