vaguerent/test/unit/support/shared/virtualbox_context.rb
Anders Kaseorg 5b4dcf9443
providers/docker: Fix usability check
In commit 7980178d194bb21bde2e21858fbc969e4cc7eb3f (#10879) I added a
`usable?` class method to `VagrantPlugins::DockerProvider::Provider`.
However, commit 34e53a5a4b208edcc3e25c1f0e3aa0ef56e8d8d9 (#10890)
incorrectly changed it to an instance method.  This rendered it
ineffective because it’s called on the class, not an instance.  Change
it back to a class method.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-09-10 15:10:43 -07:00

45 lines
1.7 KiB
Ruby

shared_context "virtualbox" do
include_context "unit"
let(:vbox_context) { true }
let(:uuid) { "1234-abcd-5678-efgh" }
let(:vbox_version) { "4.3.4" }
let(:subprocess) { double("Vagrant::Util::Subprocess") }
# this is a helper that returns a duck type suitable from a system command
# execution; allows setting exit_code, stdout, and stderr in stubs.
def subprocess_result(options={})
defaults = {exit_code: 0, stdout: "", stderr: ""}
double("subprocess_result", defaults.merge(options))
end
before do
# we don't want unit tests to ever run commands on the system; so we wire
# in a double to ensure any unexpected messages raise exceptions
stub_const("Vagrant::Util::Subprocess", subprocess)
# drivers will blow up on instantiation if they cannot determine the
# virtualbox version, so wire this stub in automatically
allow(subprocess).to receive(:execute).
with("VBoxManage", "--version", an_instance_of(Hash)).
and_return(subprocess_result(stdout: vbox_version))
# drivers also call vm_exists? during init;
allow(subprocess).to receive(:execute).
with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)).
and_return(subprocess_result(exit_code: 0))
# apparently this is also used in docker tests
allow(subprocess).to receive(:execute).
with("docker", "version", an_instance_of(Hash)).
and_return(subprocess_result(exit_code: 0))
end
around do |example|
# On Windows, we don't want to accidentally call the actual VirtualBox
with_temp_env("VBOX_INSTALL_PATH" => nil) do
example.run
end
end
end