Remove stub methods and replace with allows for rpsec 3

This commit is contained in:
Brian Cain 2017-08-04 10:10:58 -07:00
parent 1a62743bc5
commit 8b1043c199
67 changed files with 350 additions and 335 deletions

View File

@ -19,7 +19,7 @@ describe VagrantPlugins::CommandListCommands::Command do
subject { described_class.new(argv, iso_env) }
before do
Vagrant.plugin("2").manager.stub(commands: commands)
allow(Vagrant.plugin("2").manager).to receive(:commands).and_return(commands)
end
describe "execute" do

View File

@ -25,7 +25,7 @@ describe VagrantPlugins::CommandPackage::Command do
let(:action_runner) { double("action_runner") }
before do
iso_env.stub(action_runner: action_runner)
allow(iso_env).to receive(:action_runner).and_return(action_runner)
end
describe "#execute" do

View File

@ -27,7 +27,7 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do
subject { described_class.new(app, env) }
before do
Vagrant::Plugin::Manager.stub(instance: manager)
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
end
describe "#call" do

View File

@ -11,7 +11,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do
subject { described_class.new(app, env) }
before do
Vagrant::Plugin::Manager.stub(instance: manager)
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
end
describe "#call" do
@ -75,7 +75,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do
before do
spec = Gem::Specification.new
spec.name = "foo"
manager.stub(install_plugin: spec)
allow(manager).to receive(:install_plugin).and_return(spec)
env[:plugin_name] = "foo"
subject.call(env)

View File

@ -9,11 +9,11 @@ describe VagrantPlugins::CommandPlugin::Action::PluginExistsCheck do
subject { described_class.new(app, env) }
before do
Vagrant::Plugin::Manager.stub(instance: manager)
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
end
it "should raise an exception if the plugin doesn't exist" do
manager.stub(installed_plugins: { "foo" => {} })
allow(manager).to receive(:installed_plugins).and_return({ "foo" => {} })
expect(app).not_to receive(:call)
env[:plugin_name] = "bar"
@ -22,7 +22,7 @@ describe VagrantPlugins::CommandPlugin::Action::PluginExistsCheck do
end
it "should call the app if the plugin is installed" do
manager.stub(installed_plugins: { "bar" => {} })
allow(manager).to receive(:installed_plugins).and_return({ "bar" => {} })
expect(app).to receive(:call).once.with(env)
env[:plugin_name] = "bar"

View File

@ -11,7 +11,7 @@ describe VagrantPlugins::CommandPlugin::Action::UninstallPlugin do
subject { described_class.new(app, env) }
before do
Vagrant::Plugin::Manager.stub(instance: manager)
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
end
it "uninstalls the specified plugin" do

View File

@ -11,8 +11,8 @@ describe VagrantPlugins::CommandPlugin::Action::UpdateGems do
subject { described_class.new(app, env) }
before do
Vagrant::Plugin::Manager.stub(instance: manager)
manager.stub(installed_specs: [])
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager)
allow(manager).to receive(:installed_specs).and_return([])
end
describe "#call" do

View File

@ -22,7 +22,7 @@ describe VagrantPlugins::CommandPush::Command do
subject { described_class.new(argv, env) }
before do
Vagrant.plugin("2").manager.stub(pushes: pushes)
allow(Vagrant.plugin("2").manager).to receive(:pushes).and_return(pushes)
end
describe "#execute" do

View File

@ -32,7 +32,7 @@ describe VagrantPlugins::CommandSSHConfig::Command do
subject { described_class.new(argv, iso_env) }
before do
machine.stub(ssh_info: ssh_info)
allow(machine).to receive(:ssh_info).and_return(ssh_info)
allow(subject).to receive(:with_target_vms) { |&block| block.call machine }
end

View File

@ -18,7 +18,7 @@ describe VagrantPlugins::CommandUp::Command do
let(:action_runner) { double("action_runner") }
before do
iso_env.stub(action_runner: action_runner)
allow(iso_env).to receive(:action_runner).and_return(action_runner)
end
context "with no argument" do

View File

@ -27,24 +27,24 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
end
it "returns the SSH info host if available" do
machine.stub(ssh_info: { host: "bar" })
allow(machine).to receive(:ssh_info).and_return({ host: "bar" })
expect(subject.winrm_address(machine)).to eq("bar")
end
it "raise an exception if it can't detect a host" do
machine.stub(ssh_info: nil)
allow(machine).to receive(:ssh_info).and_return(nil)
expect { subject.winrm_address(machine) }.
to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady)
end
it "raise an exception if it detects an empty host ip" do
machine.stub(ssh_info: { host: "" })
allow(machine).to receive(:ssh_info).and_return({ host: "" })
expect { subject.winrm_address(machine) }.
to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady)
end
it "raise a WinRMNotReady exception if it detects an unset host ip" do
machine.stub(ssh_info: { host: nil })
allow(machine).to receive(:ssh_info).and_return({ host: nil })
expect { subject.winrm_address(machine) }.
to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady)
end
@ -52,15 +52,15 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
describe ".winrm_info" do
before do
machine.provider.stub(:capability?).
with(:winrm_info).and_return(false)
subject.stub(winrm_address: nil)
subject.stub(winrm_port: nil)
allow(machine.provider).to receive(:capability?)
.with(:winrm_info).and_return(false)
allow(subject).to receive(:winrm_address).and_return(nil)
allow(subject).to receive(:winrm_port).and_return(nil)
end
it "returns default info if no capability" do
subject.stub(winrm_address: "bar")
subject.stub(winrm_port: 45)
allow(subject).to receive(:winrm_address).and_return("bar")
allow(subject).to receive(:winrm_port).and_return(45)
result = subject.winrm_info(machine)
expect(result[:host]).to eq("bar")
@ -68,18 +68,19 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
end
it "raises an exception if capability returns nil" do
machine.provider.stub(:capability?).
with(:winrm_info).and_return(true)
machine.provider.stub(:capability).with(:winrm_info).and_return(nil)
allow(machine.provider).to receive(:capability?)
.with(:winrm_info).and_return(true)
allow(machine.provider).to receive(:capability)
.with(:winrm_info).and_return(nil)
expect { subject.winrm_info(machine) }.
to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady)
end
it "returns the proper information if set" do
machine.provider.stub(:capability?).
with(:winrm_info).and_return(true)
machine.provider.stub(:capability).with(:winrm_info).and_return({
allow(machine.provider).to receive(:capability?)
.with(:winrm_info).and_return(true)
allow(machine.provider).to receive(:capability).with(:winrm_info).and_return({
host: "foo",
port: 12,
})
@ -90,12 +91,12 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
end
it "defaults information if capability doesn't set it" do
machine.provider.stub(:capability?).
with(:winrm_info).and_return(true)
machine.provider.stub(:capability).with(:winrm_info).and_return({})
allow(machine.provider).to receive(:capability?)
.with(:winrm_info).and_return(true)
allow(machine.provider).to receive(:capability).with(:winrm_info).and_return({})
subject.stub(winrm_address: "bar")
subject.stub(winrm_port: 45)
allow(subject).to receive(:winrm_address).and_return("bar")
allow(subject).to receive(:winrm_port).and_return(45)
result = subject.winrm_info(machine)
expect(result[:host]).to eq("bar")
@ -132,8 +133,8 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
machine.config.winrm.guest_port = 2222
machine.config.vm.network "forwarded_port", host: 1234, guest: 2222
machine.provider.stub(:capability?).with(:forwarded_ports).and_return(true)
machine.provider.stub(:capability).with(:forwarded_ports).and_return({
allow(machine.provider).to receive(:capability?).with(:forwarded_ports).and_return(true)
allow(machine.provider).to receive(:capability).with(:forwarded_ports).and_return({
1234 => 4567,
2456 => 2222,
})

View File

@ -12,8 +12,8 @@ describe "VagrantPlugins::GuestSmartos::Cap::ChangeHostName" do
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
before do
machine.stub(:communicate).and_return(comm)
machine.stub(:config).and_return(config)
allow(machine).to receive(:communicate).and_return(comm)
allow(machine).to receive(:config).and_return(config)
end
after do

View File

@ -7,8 +7,8 @@ describe "VagrantPlugins::VagrantPlugins::Cap::ConfigureNetworks" do
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
machine.stub(:communicate).and_return(communicator)
machine.stub(:config).and_return(config)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:config).and_return(config)
end
after do

View File

@ -8,8 +8,8 @@ describe "VagrantPlugins::GuestSmartos::Cap::Halt" do
let(:shutdown_command){ "pfexec /usr/sbin/poweroff" }
before do
machine.stub(:communicate).and_return(communicator)
machine.stub(:config).and_return(config)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:config).and_return(config)
end
after do

View File

@ -11,7 +11,7 @@ describe "VagrantPlugins::GuestSmartos::Cap::InsertPublicKey" do
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
machine.stub(:communicate).and_return(comm)
allow(machine).to receive(:communicate).and_return(comm)
end
after do

View File

@ -13,8 +13,8 @@ describe "VagrantPlugins::GuestSmartos::Cap::MountNFS" do
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
before do
machine.stub(:communicate).and_return(comm)
machine.stub(:config).and_return(config)
allow(machine).to receive(:communicate).and_return(comm)
allow(machine).to receive(:config).and_return(config)
end
after do

View File

@ -7,8 +7,8 @@ describe "VagrantPlugins::VagrantPlugins::Cap::Rsync" do
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
machine.stub(:communicate).and_return(communicator)
machine.stub(:config).and_return(config)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:config).and_return(config)
end
after do

View File

@ -32,10 +32,10 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
before do
env = double("env")
env.stub(root_path: nil)
machine.stub(env: env)
machine.stub(provider_config: nil)
machine.stub(provider_options: {})
allow(env).to receive(:root_path).and_return(nil)
allow(machine).to receive(:env).and_return(env)
allow(machine).to receive(:provider_config).and_return(nil)
allow(machine).to receive(:provider_options).and_return({})
subject.box = "foo"
end

View File

@ -15,7 +15,7 @@ describe VagrantPlugins::DockerProvider::Action::Create do
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :virtualbox).tap do |m|
m.provider.stub(driver: driver)
allow(m.provider).to receive(:driver).and_return(driver)
end
end

View File

@ -22,7 +22,7 @@ describe VagrantPlugins::DockerProvider::Command::Exec do
end
before do
Vagrant.plugin("2").manager.stub(commands: {})
allow(Vagrant.plugin("2").manager).to receive(:commands).and_return({})
allow(subject).to receive(:exec_command)
end

View File

@ -63,8 +63,8 @@ describe VagrantPlugins::DockerProvider::Config do
before do
# By default lets be Linux for validations
Vagrant::Util::Platform.stub(linux: true)
Vagrant::Util::Platform.stub(linux?: true)
allow(Vagrant::Util::Platform).to receive(:linux).and_return(true)
allow(Vagrant::Util::Platform).to receive(:linux?).and_return(true)
end
it "should be invalid if both build dir and image are set" do

View File

@ -7,7 +7,7 @@ describe VagrantPlugins::DockerProvider::Driver do
let(:cid) { 'side-1-song-10' }
before do
subject.stub(:execute) { |*args| @cmd = args.join(' ') }
allow(subject).to receive(:execute) { |*args| @cmd = args.join(' ') }
end
describe '#create' do
@ -74,19 +74,19 @@ describe VagrantPlugins::DockerProvider::Driver do
end
context 'when container exists' do
before { subject.stub(execute: "foo\n#{cid}\nbar") }
before { allow(subject).to receive(:execute).and_return("foo\n#{cid}\nbar") }
it { expect(result).to be_truthy }
end
context 'when container does not exist' do
before { subject.stub(execute: "foo\n#{cid}extra\nbar") }
before { allow(subject).to receive(:execute).and_return("foo\n#{cid}extra\nbar") }
it { expect(result).to be_falsey }
end
end
describe '#pull' do
it 'should pull images' do
subject.should_receive(:execute).with('docker', 'pull', 'foo')
expect(subject).to receive(:execute).with('docker', 'pull', 'foo')
subject.pull('foo')
end
end
@ -101,43 +101,43 @@ describe VagrantPlugins::DockerProvider::Driver do
end
context 'when container exists' do
before { subject.stub(execute: "foo\n#{cid}\nbar") }
before { allow(subject).to receive(:execute).and_return("foo\n#{cid}\nbar") }
it { expect(result).to be_truthy }
end
context 'when container does not exist' do
before { subject.stub(execute: "foo\n#{cid}extra\nbar") }
before { allow(subject).to receive(:execute).and_return("foo\n#{cid}extra\nbar") }
it { expect(result).to be_falsey }
end
end
describe '#privileged?' do
it 'identifies privileged containers' do
subject.stub(inspect_container: {'HostConfig' => {"Privileged" => true}})
allow(subject).to receive(:inspect_container).and_return({'HostConfig' => {"Privileged" => true}})
expect(subject).to be_privileged(cid)
end
it 'identifies unprivileged containers' do
subject.stub(inspect_container: {'HostConfig' => {"Privileged" => false}})
allow(subject).to receive(:inspect_container).and_return({'HostConfig' => {"Privileged" => false}})
expect(subject).to_not be_privileged(cid)
end
end
describe '#start' do
context 'when container is running' do
before { subject.stub(running?: true) }
before { allow(subject).to receive(:running?).and_return(true) }
it 'does not start the container' do
subject.should_not_receive(:execute).with('docker', 'start', cid)
expect(subject).to_not receive(:execute).with('docker', 'start', cid)
subject.start(cid)
end
end
context 'when container is not running' do
before { subject.stub(running?: false) }
before { allow(subject).to receive(:running?).and_return(false) }
it 'starts the container' do
subject.should_receive(:execute).with('docker', 'start', cid)
expect(subject).to receive(:execute).with('docker', 'start', cid)
subject.start(cid)
end
end
@ -145,24 +145,24 @@ describe VagrantPlugins::DockerProvider::Driver do
describe '#stop' do
context 'when container is running' do
before { subject.stub(running?: true) }
before { allow(subject).to receive(:running?).and_return(true) }
it 'stops the container' do
subject.should_receive(:execute).with('docker', 'stop', '-t', '1', cid)
expect(subject).to receive(:execute).with('docker', 'stop', '-t', '1', cid)
subject.stop(cid, 1)
end
it "stops the container with the set timeout" do
subject.should_receive(:execute).with('docker', 'stop', '-t', '5', cid)
expect(subject).to receive(:execute).with('docker', 'stop', '-t', '5', cid)
subject.stop(cid, 5)
end
end
context 'when container is not running' do
before { subject.stub(running?: false) }
before { allow(subject).to receive(:running?).and_return(false) }
it 'does not stop container' do
subject.should_not_receive(:execute).with('docker', 'stop', '-t', '1', cid)
expect(subject).to_not receive(:execute).with('docker', 'stop', '-t', '1', cid)
subject.stop(cid, 1)
end
end
@ -170,19 +170,19 @@ describe VagrantPlugins::DockerProvider::Driver do
describe '#rm' do
context 'when container has been created' do
before { subject.stub(created?: true) }
before { allow(subject).to receive(:created?).and_return(true) }
it 'removes the container' do
subject.should_receive(:execute).with('docker', 'rm', '-f', '-v', cid)
expect(subject).to receive(:execute).with('docker', 'rm', '-f', '-v', cid)
subject.rm(cid)
end
end
context 'when container has not been created' do
before { subject.stub(created?: false) }
before { allow(subject).to receive(:created?).and_return(false) }
it 'does not attempt to remove the container' do
subject.should_not_receive(:execute).with('docker', 'rm', '-f', '-v', cid)
expect(subject).to_not receive(:execute).with('docker', 'rm', '-f', '-v', cid)
subject.rm(cid)
end
end
@ -191,10 +191,10 @@ describe VagrantPlugins::DockerProvider::Driver do
describe '#inspect_container' do
let(:data) { '[{"json": "value"}]' }
before { subject.stub(execute: data) }
before { allow(subject).to receive(:execute).and_return(data) }
it 'inspects the container' do
subject.should_receive(:execute).with('docker', 'inspect', cid)
expect(subject).to receive(:execute).with('docker', 'inspect', cid)
subject.inspect_container(cid)
end
@ -206,10 +206,10 @@ describe VagrantPlugins::DockerProvider::Driver do
describe '#all_containers' do
let(:containers) { "container1\ncontainer2" }
before { subject.stub(execute: containers) }
before { allow(subject).to receive(:execute).and_return(containers) }
it 'returns an array of all known containers' do
subject.should_receive(:execute).with('docker', 'ps', '-a', '-q', '--no-trunc')
expect(subject).to receive(:execute).with('docker', 'ps', '-a', '-q', '--no-trunc')
expect(subject.all_containers).to eq(['container1', 'container2'])
end
end
@ -217,10 +217,10 @@ describe VagrantPlugins::DockerProvider::Driver do
describe '#docker_bridge_ip' do
let(:containers) { " inet 123.456.789.012/16 " }
before { subject.stub(execute: containers) }
before { allow(subject).to receive(:execute).and_return(containers) }
it 'returns an array of all known containers' do
subject.should_receive(:execute).with('/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'docker0')
expect(subject).to receive(:execute).with('/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'docker0')
expect(subject.docker_bridge_ip).to eq('123.456.789.012')
end
end

View File

@ -9,7 +9,7 @@ describe VagrantPlugins::DockerProvider::SyncedFolder do
let(:machine) { double("machine") }
before do
machine.stub(provider_name: :docker)
allow(machine).to receive(:provider_name).and_return(:docker)
end
it "is usable" do
@ -17,12 +17,12 @@ describe VagrantPlugins::DockerProvider::SyncedFolder do
end
it "is not usable if provider isn't docker" do
machine.stub(provider_name: :virtualbox)
allow(machine).to receive(:provider_name).and_return(:virtualbox)
expect(subject).to_not be_usable(machine)
end
it "raises an error if bad provider if specified" do
machine.stub(provider_name: :virtualbox)
allow(machine).to receive(:provider_name).and_return(:virtualbox)
expect { subject.usable?(machine, true) }.
to raise_error(VagrantPlugins::DockerProvider::Errors::SyncedFolderNonDocker)
end

View File

@ -12,63 +12,63 @@ describe VagrantPlugins::HyperV::Provider do
before do
stub_const("Vagrant::Util::Platform", platform)
stub_const("Vagrant::Util::PowerShell", powershell)
machine.stub(id: "foo")
platform.stub(windows?: true)
platform.stub(windows_admin?: true)
platform.stub(windows_hyperv_admin?: true)
powershell.stub(available?: true)
allow(machine).to receive(:id).and_return("foo")
allow(platform).to receive(:windows?).and_return(true)
allow(platform).to receive(:windows_admin?).and_return(true)
allow(platform).to receive(:windows_hyperv_admin?).and_return(true)
allow(powershell).to receive(:available?).and_return(true)
end
describe ".usable?" do
subject { described_class }
it "returns false if not windows" do
platform.stub(windows?: false)
allow(platform).to receive(:windows?).and_return(false)
expect(subject).to_not be_usable
end
it "returns false if neither an admin nor a hyper-v admin" do
platform.stub(windows_admin?: false)
platform.stub(windows_hyperv_admin?: false)
allow(platform).to receive(:windows_admin?).and_return(false)
allow(platform).to receive(:windows_hyperv_admin?).and_return(false)
expect(subject).to_not be_usable
end
it "returns true if not an admin but is a hyper-v admin" do
platform.stub(windows_admin?: false)
platform.stub(windows_hyperv_admin?: true)
allow(platform).to receive(:windows_admin?).and_return(false)
allow(platform).to receive(:windows_hyperv_admin?).and_return(true)
expect(subject).to be_usable
end
it "returns false if powershell is not available" do
powershell.stub(available?: false)
allow(powershell).to receive(:available?).and_return(false)
expect(subject).to_not be_usable
end
it "raises an exception if not windows" do
platform.stub(windows?: false)
allow(platform).to receive(:windows?).and_return(false)
expect { subject.usable?(true) }.
to raise_error(VagrantPlugins::HyperV::Errors::WindowsRequired)
end
it "raises an exception if neither an admin nor a hyper-v admin" do
platform.stub(windows_admin?: false)
platform.stub(windows_hyperv_admin?: false)
allow(platform).to receive(:windows_admin?).and_return(false)
allow(platform).to receive(:windows_hyperv_admin?).and_return(false)
expect { subject.usable?(true) }.
to raise_error(VagrantPlugins::HyperV::Errors::AdminRequired)
end
it "raises an exception if neither an admin nor a hyper-v admin" do
platform.stub(windows_admin?: false)
platform.stub(windows_hyperv_admin?: false)
allow(platform).to receive(:windows_admin?).and_return(false)
allow(platform).to receive(:windows_hyperv_admin?).and_return(false)
expect { subject.usable?(true) }.
to raise_error(VagrantPlugins::HyperV::Errors::AdminRequired)
end
it "raises an exception if powershell is not available" do
powershell.stub(available?: false)
allow(powershell).to receive(:available?).and_return(false)
expect { subject.usable?(true) }.
to raise_error(VagrantPlugins::HyperV::Errors::PowerShellRequired)
@ -83,13 +83,13 @@ describe VagrantPlugins::HyperV::Provider do
describe "#state" do
it "returns not_created if no ID" do
machine.stub(id: nil)
allow(machine).to receive(:id).and_return(nil)
expect(subject.state.id).to eq(:not_created)
end
it "calls an action to determine the ID" do
machine.stub(id: "foo")
allow(machine).to receive(:id).and_return("foo")
expect(machine).to receive(:action).with(:read_state).
and_return({ machine_state_id: :bar })

View File

@ -13,7 +13,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::NetworkFixIPv6 do
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :dummy).tap do |m|
m.provider.stub(driver: driver)
allow(m.provider).to receive(:driver).and_return(driver)
end
end
@ -45,7 +45,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::NetworkFixIPv6 do
.and_return(private_network: { ip: 'fe:80::' })
allow(UDPSocket).to receive(:new).with(Socket::AF_INET6)
.and_return(socket)
socket.stub(:connect)
allow(socket).to receive(:connect)
end
it "only checks the interfaces associated with the VM" do

View File

@ -15,7 +15,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :virtualbox).tap do |m|
m.provider.stub(driver: driver)
allow(m.provider).to receive(:driver).and_return(driver)
end
end

View File

@ -15,7 +15,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :dummy).tap do |m|
m.provider.stub(driver: driver)
allow(m.provider).to receive(:driver).and_return(driver)
end
end
@ -33,8 +33,8 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
end
it "calls the next action in the chain" do
driver.stub(read_network_interfaces: {2 => {type: :hostonly, hostonly: "vmnet2"}})
driver.stub(read_host_only_interfaces: [{name: "vmnet2", ip: "1.2.3.4"}])
allow(driver).to receive(:read_network_interfaces).and_return({2 => {type: :hostonly, hostonly: "vmnet2"}})
allow(driver).to receive(:read_host_only_interfaces).and_return([{name: "vmnet2", ip: "1.2.3.4"}])
allow(driver).to receive(:read_guest_ip).with(1).and_return("2.3.4.5")
called = false
@ -53,16 +53,16 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
before do
# We can't be on Windows, because NFS gets disabled on Windows
Vagrant::Util::Platform.stub(windows?: false)
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false)
env[:machine].config.vm.synced_folder("/host/path", "/guest/path", type: "nfs")
env[:machine].config.finalize!
# Stub out the stuff so it just works by default
driver.stub(read_network_interfaces: {
allow(driver).to receive(:read_network_interfaces).and_return({
2 => {type: :hostonly, hostonly: "vmnet2"},
})
driver.stub(read_host_only_interfaces: host_only_interfaces)
allow(driver).to receive(:read_host_only_interfaces).and_return(host_only_interfaces)
allow(driver).to receive(:read_guest_ip).with(1).and_return("2.3.4.5")
# override sleep to 0 so test does not take seconds

View File

@ -13,7 +13,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :dummy).tap do |m|
m.provider.stub(driver: driver)
allow(m.provider).to receive(:driver).and_return(driver)
end
end
@ -24,7 +24,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do
subject { described_class.new(app, env) }
before do
driver.stub(read_vms: {})
allow(driver).to receive(:read_vms).and_return({})
end
it "calls the next action in the chain" do
@ -39,7 +39,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do
it "sets nfs_valid_ids" do
hash = {"foo" => "1", "bar" => "4"}
driver.stub(read_vms: hash)
allow(driver).to receive(:read_vms).and_return(hash)
subject.call(env)

View File

@ -14,8 +14,8 @@ describe VagrantPlugins::ProviderVirtualBox::Cap do
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :dummy).tap do |m|
m.provider.stub(driver: driver)
m.stub(state: state)
allow(m.provider).to receive(:driver).and_return(driver)
allow(m).to receive(:state).and_return(state)
end
end

View File

@ -25,10 +25,10 @@ describe VagrantPlugins::ProviderVirtualBox::Config do
before do
vm_config = double("vm_config")
vm_config.stub(networks: [])
allow(vm_config).to receive(:networks).and_return([])
config = double("config")
config.stub(vm: vm_config)
machine.stub(config: config)
allow(config).to receive(:vm).and_return(vm_config)
allow(machine).to receive(:config).and_return(config)
end
its "valid by default" do

View File

@ -7,8 +7,8 @@ require Vagrant.source_root.join("plugins/providers/virtualbox/synced_folder")
describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
let(:machine) do
double("machine").tap do |m|
m.stub(provider_config: VagrantPlugins::ProviderVirtualBox::Config.new)
m.stub(provider_name: :virtualbox)
allow(m).to receive(:provider_config).and_return(VagrantPlugins::ProviderVirtualBox::Config.new)
allow(m).to receive(:provider_name).and_return(:virtualbox)
end
end
@ -20,12 +20,12 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
describe "usable" do
it "should be with virtualbox provider" do
machine.stub(provider_name: :virtualbox)
allow(machine).to receive(:provider_name).and_return(:virtualbox)
expect(subject).to be_usable(machine)
end
it "should not be with another provider" do
machine.stub(provider_name: :vmware_fusion)
allow(machine).to receive(:provider_name).and_return(:vmware_fusion)
expect(subject).not_to be_usable(machine)
end
@ -39,7 +39,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
let(:driver) { double("driver") }
before do
machine.stub(driver: driver)
allow(machine).to receive(:driver).and_return(driver)
end
it "should share the folders"

View File

@ -22,21 +22,21 @@ describe VagrantPlugins::DockerProvisioner::Provisioner do
let(:hook) { double("hook") }
before do
machine.stub(communicate: communicator)
machine.stub(guest: guest)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:guest).and_return(guest)
communicator.stub(execute: true)
communicator.stub(upload: true)
allow(communicator).to receive(:execute).and_return(true)
allow(communicator).to receive(:upload).and_return(true)
guest.stub(capability?: false)
guest.stub(capability: false)
allow(guest).to receive(:capability?).and_return(false)
allow(guest).to receive(:capability).and_return(false)
client.stub(start_service: true)
client.stub(daemon_running?: true)
allow(client).to receive(:start_service).and_return(true)
allow(client).to receive(:daemon_running?).and_return(true)
config.stub(images: Set.new)
config.stub(build_images: Set.new)
config.stub(containers: Hash.new)
allow(config).to receive(:images).and_return(Set.new)
allow(config).to receive(:build_images).and_return(Set.new)
allow(config).to receive(:containers).and_return(Hash.new)
end
describe "#provision" do
@ -47,7 +47,7 @@ describe VagrantPlugins::DockerProvisioner::Provisioner do
end
it "invokes a post_install_provisioner if defined and docker is installed" do
installer.stub(ensure_installed: true)
allow(installer).to receive(:ensure_installed).and_return(true)
allow(config).to receive(:post_install_provisioner).and_return(provisioner)
allow(machine).to receive(:env).and_return(iso_env)
allow(machine.env).to receive(:hook).and_return(true)
@ -57,7 +57,7 @@ describe VagrantPlugins::DockerProvisioner::Provisioner do
end
it "does not invoke post_install_provisioner if not defined" do
installer.stub(ensure_installed: true)
allow(installer).to receive(:ensure_installed).and_return(true)
allow(config).to receive(:post_install_provisioner).and_return(nil)
allow(machine).to receive(:env).and_return(iso_env)
allow(machine.env).to receive(:hook).and_return(true)

View File

@ -20,19 +20,19 @@ describe VagrantPlugins::FileUpload::Provisioner do
let(:guest) { double("guest") }
before do
machine.stub(communicate: communicator)
machine.stub(guest: guest)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:guest).and_return(guest)
communicator.stub(execute: true)
communicator.stub(upload: true)
allow(communicator).to receive(:execute).and_return(true)
allow(communicator).to receive(:upload).and_return(true)
guest.stub(capability?: false)
allow(guest).to receive(:capability?).and_return(false)
end
describe "#provision" do
it "creates the destination directory" do
config.stub(source: "/source")
config.stub(destination: "/foo/bar")
allow(config).to receive(:source).and_return("/source")
allow(config).to receive(:destination).and_return("/foo/bar")
expect(communicator).to receive(:execute).with("mkdir -p /foo")
@ -40,8 +40,8 @@ describe VagrantPlugins::FileUpload::Provisioner do
end
it "uploads the file" do
config.stub(source: "/source")
config.stub(destination: "/foo/bar")
allow(config).to receive(:source).and_return("/source")
allow(config).to receive(:destination).and_return("/foo/bar")
expect(communicator).to receive(:upload).with("/source", "/foo/bar")
@ -49,8 +49,8 @@ describe VagrantPlugins::FileUpload::Provisioner do
end
it "expands the source file path" do
config.stub(source: "source")
config.stub(destination: "/foo/bar")
allow(config).to receive(:source).and_return("source")
allow(config).to receive(:destination).and_return("/foo/bar")
expect(communicator).to receive(:upload).with(
File.expand_path("source"), "/foo/bar")
@ -59,8 +59,8 @@ describe VagrantPlugins::FileUpload::Provisioner do
end
it "expands the destination file path if capable" do
config.stub(source: "/source")
config.stub(destination: "$HOME/foo")
allow(config).to receive(:source).and_return("/source")
allow(config).to receive(:destination).and_return("$HOME/foo")
expect(guest).to receive(:capability?).
with(:shell_expand_guest_path).and_return(true)

View File

@ -20,13 +20,13 @@ describe VagrantPlugins::Salt::Provisioner do
let(:guest) { double("guest") }
before do
machine.stub(communicate: communicator)
machine.stub(guest: guest)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:guest).and_return(guest)
communicator.stub(execute: true)
communicator.stub(upload: true)
allow(communicator).to receive(:execute).and_return(true)
allow(communicator).to receive(:upload).and_return(true)
guest.stub(capability?: false)
allow(guest).to receive(:capability?).and_return(false)
end
describe "#provision" do

View File

@ -7,8 +7,8 @@ describe "Vagrant::Shell::Provisioner" do
let(:env){ isolated_environment }
let(:machine) {
double(:machine, env: env, id: "ID").tap { |machine|
machine.stub_chain(:config, :vm, :communicator).and_return(:not_winrm)
machine.stub_chain(:communicate, :tap) {}
allow(machine).to receive_message_chain(:config, :vm, :communicator).and_return(:not_winrm)
allow(machine).to receive_message_chain(:communicate, :tap) {}
}
}
@ -62,7 +62,7 @@ describe "Vagrant::Shell::Provisioner" do
let(:digest){ double("digest") }
before do
Vagrant::Util::Downloader.any_instance.should_receive(:execute_curl).and_return(true)
allow_any_instance_of(Vagrant::Util::Downloader).to receive(:execute_curl).and_return(true)
allow(digest).to receive(:file).and_return(digest)
expect(Digest::SHA1).to receive(:new).and_return(digest)
expect(digest).to receive(:hexdigest).and_return('INVALID_VALUE')
@ -92,7 +92,7 @@ describe "Vagrant::Shell::Provisioner" do
let(:digest){ double("digest") }
before do
Vagrant::Util::Downloader.any_instance.should_receive(:execute_curl).and_return(true)
allow_any_instance_of(Vagrant::Util::Downloader).to receive(:execute_curl).and_return(true)
allow(digest).to receive(:file).and_return(digest)
expect(Digest::MD5).to receive(:new).and_return(digest)
expect(digest).to receive(:hexdigest).and_return('INVALID_VALUE')

View File

@ -23,7 +23,7 @@ describe VagrantPlugins::SyncedFolderNFS::ActionCleanup do
subject { described_class.new(app, env) }
before do
machine.env.stub(host: host)
allow(machine.env).to receive(:host).and_return(host)
end
it "does nothing if there are no valid IDs" do

View File

@ -34,17 +34,17 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
def machine_stub(name)
double(name).tap do |m|
m.stub(id: "foo")
m.stub(reload: nil)
m.stub(ssh_info: ssh_info)
m.stub(ui: iso_env.ui)
m.stub(provider: double("provider"))
m.stub(state: double("state", id: :not_created))
m.stub(env: iso_env)
m.stub(config: double("config"))
allow(m).to receive(:id).and_return("foo")
allow(m).to receive(:reload).and_return(nil)
allow(m).to receive(:ssh_info).and_return(ssh_info)
allow(m).to receive(:ui).and_return(iso_env.ui)
allow(m).to receive(:provider).and_return(double("provider"))
allow(m).to receive(:state).and_return(double("state", id: :not_created))
allow(m).to receive(:env).and_return(iso_env)
allow(m).to receive(:config).and_return(double("config"))
m.ui.stub(error: nil)
allow(m.ui).to receive(:error).and_return(nil)
end
end
@ -111,7 +111,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
subject do
described_class.new(argv, iso_env).tap do |s|
s.stub(synced_folders: synced_folders_empty)
allow(s).to receive(:synced_folders).and_return(synced_folders_empty)
end
end
@ -207,7 +207,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
]
paths["/foo"].each do |data|
data[:machine].stub(id: nil)
allow(data[:machine]).to receive(:id).and_return(nil)
expect(helper_class).to_not receive(:rsync_single)
end

View File

@ -21,14 +21,14 @@ describe VagrantPlugins::SyncedFolderRSync::Command::Rsync do
subject do
described_class.new(argv, iso_env).tap do |s|
s.stub(synced_folders: synced_folders)
allow(s).to receive(:synced_folders).and_return(synced_folders)
end
end
before do
iso_env.machine_names.each do |name|
m = iso_env.machine(name, iso_env.default_provider)
m.stub(communicate: communicator)
allow(m).to receive(:communicate).and_return(communicator)
end
end
@ -41,8 +41,8 @@ describe VagrantPlugins::SyncedFolderRSync::Command::Rsync do
let(:machine) { iso_env.machine(iso_env.machine_names[0], iso_env.default_provider) }
before do
communicator.stub(ready?: true)
machine.stub(ssh_info: ssh_info)
allow(communicator).to receive(:ready?).and_return(true)
allow(machine).to receive(:ssh_info).and_return(ssh_info)
synced_folders[:rsync] = [
[:one, {}],
@ -51,7 +51,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::Rsync do
end
it "doesn't sync if communicator isn't ready and exits with 1" do
communicator.stub(ready?: false)
allow(communicator).to receive(:ready?).and_return(false)
expect(helper_class).to receive(:rsync_single).never

View File

@ -20,7 +20,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
subject { described_class }
before do
machine.stub(guest: guest)
allow(machine).to receive(:guest).and_return(guest)
# Don't do all the crazy Cygwin stuff
allow(Vagrant::Util::Platform).to receive(:cygwin_path) do |path, **opts|
@ -64,9 +64,9 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
let(:ui) { machine.ui }
before do
Vagrant::Util::Subprocess.stub(:execute){ result }
allow(Vagrant::Util::Subprocess).to receive(:execute){ result }
guest.stub(:capability?){ false }
allow(guest).to receive(:capability?){ false }
end
it "doesn't raise an error if it succeeds" do
@ -74,13 +74,13 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
end
it "doesn't call cygwin_path on non-Windows" do
Vagrant::Util::Platform.stub(windows?: false)
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false)
expect(Vagrant::Util::Platform).not_to receive(:cygwin_path)
subject.rsync_single(machine, ssh_info, opts)
end
it "calls cygwin_path on Windows" do
Vagrant::Util::Platform.stub(windows?: true)
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true)
expect(Vagrant::Util::Platform).to receive(:cygwin_path).and_return("foo")
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
@ -91,8 +91,8 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
end
it "raises an error if the exit code is non-zero" do
Vagrant::Util::Subprocess.stub(
execute: Vagrant::Util::Subprocess::Result.new(1, "", ""))
allow(Vagrant::Util::Subprocess).to receive(:execute)
.and_return(Vagrant::Util::Subprocess::Result.new(1, "", ""))
expect {subject.rsync_single(machine, ssh_info, opts) }.
to raise_error(Vagrant::Errors::RSyncError)
@ -228,9 +228,9 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
let(:ui) { machine.ui }
before do
Vagrant::Util::Subprocess.stub(:execute){ result }
allow(Vagrant::Util::Subprocess).to receive(:execute){ result }
guest.stub(:capability?){ false }
allow(guest).to receive(:capability?){ false }
end
it "includes IdentitiesOnly, StrictHostKeyChecking, and UserKnownHostsFile with defaults" do
@ -248,7 +248,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
it "omits IdentitiesOnly with keys_only = false" do
ssh_info[:keys_only] = false
Vagrant::Util::Subprocess.should_receive(:execute) do |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute) do |*args|
expect(args[9]).not_to include('IdentitiesOnly')
result
end
@ -259,7 +259,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
it "omits StrictHostKeyChecking and UserKnownHostsFile with paranoid = true" do
ssh_info[:keys_only] = false
Vagrant::Util::Subprocess.should_receive(:execute) do |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute) do |*args|
expect(args[9]).not_to include('StrictHostKeyChecking ')
expect(args[9]).not_to include('UserKnownHostsFile ')
result

View File

@ -19,8 +19,8 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do
let(:helper_class) { VagrantPlugins::SyncedFolderRSync::RsyncHelper }
before do
machine.env.stub(host: host)
machine.stub(guest: guest)
allow(machine.env).to receive(:host).and_return(host)
allow(machine).to receive(:guest).and_return(guest)
end
describe "#usable?" do
@ -47,7 +47,7 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do
}}
before do
machine.stub(ssh_info: ssh_info)
allow(machine).to receive(:ssh_info).and_return(ssh_info)
allow(guest).to receive(:capability?).with(:rsync_installed)
end

View File

@ -81,7 +81,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
end
before do
box_collection.stub(find: nil)
allow(box_collection).to receive(:find).and_return(nil)
end
context "with box file directly" do
@ -267,7 +267,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = box_path.to_s
env[:box_provider] = "virtualbox"
box_collection.stub(find: box)
allow(box_collection).to receive(:find).and_return(box)
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo")
@ -691,7 +691,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
expect(box_collection).to receive(:add).never
expect(app).to receive(:call).never
Vagrant.stub(server_url: nil)
allow(Vagrant).to receive(:server_url).and_return(nil)
expect { subject.call(env) }.
to raise_error(Vagrant::Errors::BoxServerNotSet)
@ -1225,7 +1225,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_force] = true
env[:box_url] = tf.path
box_collection.stub(find: box)
allow(box_collection).to receive(:find).and_return(box)
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")

View File

@ -24,7 +24,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
let(:box) do
box_dir = iso_env.box3("foo", "1.0", :virtualbox)
Vagrant::Box.new("foo", :virtualbox, "1.0", box_dir).tap do |b|
b.stub(has_update?: nil)
allow(b).to receive(:has_update?).and_return(nil)
end
end
@ -35,7 +35,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
end
before do
machine.stub(box: box)
allow(machine).to receive(:box).and_return(box)
end
context "disabling outdated checking" do
@ -63,7 +63,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
context "no box" do
it "raises an exception if the machine doesn't have a box yet" do
machine.stub(box: nil)
allow(machine).to receive(:box).and_return(nil)
expect(app).to receive(:call).with(env).once
@ -75,8 +75,8 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
context "with a non-versioned box" do
it "does nothing" do
box.stub(metadata_url: nil)
box.stub(version: "0")
allow(box).to receive(:metadata_url).and_return(nil)
allow(box).to receive(:version).and_return("0")
expect(app).to receive(:call).once
expect(box).to receive(:has_update?).never

View File

@ -24,7 +24,7 @@ describe Vagrant::Action::Builtin::BoxRemove do
end
it "deletes the box if it is the only option" do
box_collection.stub(all: [["foo", "1.0", :virtualbox]])
allow(box_collection).to receive(:all).and_return([["foo", "1.0", :virtualbox]])
env[:box_name] = "foo"
@ -41,8 +41,8 @@ describe Vagrant::Action::Builtin::BoxRemove do
end
it "deletes the box with the specified provider if given" do
box_collection.stub(
all: [
allow(box_collection).to receive(:all)
.and_return([
["foo", "1.0", :virtualbox],
["foo", "1.0", :vmware],
])
@ -63,8 +63,8 @@ describe Vagrant::Action::Builtin::BoxRemove do
end
it "deletes the box with the specified version if given" do
box_collection.stub(
all: [
allow(box_collection).to receive(:all)
.and_return([
["foo", "1.0", :virtualbox],
["foo", "1.1", :virtualbox],
])
@ -93,7 +93,7 @@ describe Vagrant::Action::Builtin::BoxRemove do
"version" => "1.0",
}
entry.stub(valid?: valid)
allow(entry).to receive(:valid?).and_return(valid)
end
end
@ -102,8 +102,8 @@ describe Vagrant::Action::Builtin::BoxRemove do
before do
env[:action_runner] = action_runner
box_collection.stub(
all: [
allow(box_collection).to receive(:all)
.and_return([
["foo", "1.0", :virtualbox],
["foo", "1.1", :virtualbox],
])
@ -154,7 +154,7 @@ describe Vagrant::Action::Builtin::BoxRemove do
end
it "errors if the box doesn't exist" do
box_collection.stub(all: [])
allow(box_collection).to receive(:all).and_return([])
expect(app).to receive(:call).never
@ -166,7 +166,7 @@ describe Vagrant::Action::Builtin::BoxRemove do
env[:box_name] = "foo"
env[:box_provider] = "bar"
box_collection.stub(all: [["foo", "1.0", :virtualbox]])
allow(box_collection).to receive(:all).and_return([["foo", "1.0", :virtualbox]])
expect(app).to receive(:call).never
@ -177,8 +177,8 @@ describe Vagrant::Action::Builtin::BoxRemove do
it "errors if there are multiple providers" do
env[:box_name] = "foo"
box_collection.stub(
all: [
allow(box_collection).to receive(:all)
.and_return([
["foo", "1.0", :virtualbox],
["foo", "1.0", :vmware],
])
@ -193,8 +193,8 @@ describe Vagrant::Action::Builtin::BoxRemove do
env[:box_name] = "foo"
env[:box_provider] = "virtualbox"
box_collection.stub(
all: [
allow(box_collection).to receive(:all)
.and_return([
["foo", "1.0", :virtualbox],
["foo", "1.1", :virtualbox],
])
@ -209,7 +209,7 @@ describe Vagrant::Action::Builtin::BoxRemove do
env[:box_name] = "foo"
env[:box_version] = "1.1"
box_collection.stub(all: [["foo", "1.0", :virtualbox]])
allow(box_collection).to receive(:all).and_return([["foo", "1.0", :virtualbox]])
expect(app).to receive(:call).never

View File

@ -13,8 +13,8 @@ describe Vagrant::Action::Builtin::GracefulHalt do
let(:machine_config) do
double("machine_config").tap do |top_config|
vm_config = double("machien_vm_config")
vm_config.stub(graceful_halt_timeout: 10)
top_config.stub(vm: vm_config)
allow(vm_config).to receive(:graceful_halt_timeout).and_return(10)
allow(top_config).to receive(:vm).and_return(vm_config)
end
end
let(:machine_guest) { double("machine_guest") }

View File

@ -38,7 +38,7 @@ describe Vagrant::Action::Builtin::HandleBox do
end
it "doesn't do anything if a box exists" do
machine.stub(box: box)
allow(machine).to receive(:box).and_return(box)
expect(action_runner).to receive(:run).never
expect(app).to receive(:call).with(env)
@ -48,7 +48,7 @@ describe Vagrant::Action::Builtin::HandleBox do
context "with a box set and no box_url" do
before do
machine.stub(box: nil)
allow(machine).to receive(:box).and_return(nil)
machine.config.vm.box = "foo"
end
@ -86,7 +86,7 @@ describe Vagrant::Action::Builtin::HandleBox do
context "with a box and box_url set" do
before do
machine.stub(box: nil)
allow(machine).to receive(:box).and_return(nil)
machine.config.vm.box = "foo"
machine.config.vm.box_url = "bar"
@ -109,7 +109,7 @@ describe Vagrant::Action::Builtin::HandleBox do
context "with a box with a checksum set" do
before do
machine.stub(box: nil)
allow(machine).to receive(:box).and_return(nil)
machine.config.vm.box = "foo"
machine.config.vm.box_url = "bar"

View File

@ -26,7 +26,7 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do
let(:machine_config) do
double("machine_config").tap do |config|
config.stub(vm: vm_config)
allow(config).to receive(:vm).and_return(vm_config)
end
end

View File

@ -16,7 +16,7 @@ describe Vagrant::Action::Builtin::IsState do
describe "#call" do
it "sets result to false if is proper state" do
state.stub(id: :foo)
allow(state).to receive(:id).and_return(:foo)
subject = described_class.new(app, env, :bar)
@ -27,7 +27,7 @@ describe Vagrant::Action::Builtin::IsState do
end
it "sets result to true if is proper state" do
state.stub(id: :foo)
allow(state).to receive(:id).and_return(:foo)
subject = described_class.new(app, env, :foo)
@ -38,7 +38,7 @@ describe Vagrant::Action::Builtin::IsState do
end
it "inverts the result if specified" do
state.stub(id: :foo)
allow(state).to receive(:id).and_return(:foo)
subject = described_class.new(app, env, :foo, invert: true)

View File

@ -24,7 +24,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
let(:machine_config) do
double("machine_config").tap do |top_config|
top_config.stub(vm: vm_config)
allow(top_config).to receive(:vm).and_return(vm_config)
end
end
@ -98,8 +98,8 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
plugins[:default] = [impl(true, "default"), 10]
plugins[:nfs] = [impl(true, "nfs"), 5]
subject.stub(plugins: plugins)
vm_config.stub(synced_folders: folders)
allow(subject).to receive(:plugins).and_return(plugins)
allow(vm_config).to receive(:synced_folders).and_return(folders)
end
it "should raise exception if bad type is given" do
@ -133,7 +133,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
other_folders = { "bar" => {} }
other = double("config")
other.stub(synced_folders: other_folders)
allow(other).to receive(:synced_folders).and_return(other_folders)
result = subject.synced_folders(machine, config: other)
expect(result.length).to eq(1)
@ -201,7 +201,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
it "should be able to save and retrieve cached versions" do
other_folders = {}
other = double("config")
other.stub(synced_folders: other_folders)
allow(other).to receive(:synced_folders).and_return(other_folders)
other_folders["foo"] = { type: "default" }
result = subject.synced_folders(machine, config: other)

View File

@ -22,7 +22,7 @@ describe Vagrant::Action::Builtin::Provision do
let(:machine_config) do
double("machine_config").tap do |config|
config.stub(vm: vm_config)
allow(config).to receive(:vm).and_return(vm_config)
end
end

View File

@ -15,7 +15,7 @@ describe Vagrant::Action::Builtin::ProvisionerCleanup do
let(:machine_config) do
double("machine_config").tap do |config|
config.stub(vm: vm_config)
allow(config).to receive(:vm).and_return(vm_config)
end
end

View File

@ -16,7 +16,7 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do
let(:machine_config) do
double("machine_config").tap do |top_config|
top_config.stub(vm: vm_config)
allow(top_config).to receive(:vm).and_return(vm_config)
end
end
@ -55,8 +55,8 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do
env[:machine] = Object.new
env[:root_path] = Pathname.new(Dir.mktmpdir("vagrant-test-synced-folder-cleanup-call"))
subject.stub(plugins: plugins)
subject.stub(synced_folders: synced_folders)
allow(subject).to receive(:plugins).and_return(plugins)
allow(subject).to receive(:synced_folders).and_return(synced_folders)
end
after do

View File

@ -19,7 +19,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do
let(:machine_config) do
double("machine_config").tap do |top_config|
top_config.stub(vm: vm_config)
allow(top_config).to receive(:vm).and_return(vm_config)
end
end
@ -42,8 +42,8 @@ describe Vagrant::Action::Builtin::SyncedFolders do
plugins[:nfs] = [impl(true, "nfs"), 5]
env[:root_path] = Pathname.new(Dir.mktmpdir("vagrant-test-synced-folders-call"))
subject.stub(plugins: plugins)
subject.stub(synced_folders: synced_folders)
allow(subject).to receive(:plugins).and_return(plugins)
allow(subject).to receive(:synced_folders).and_return(synced_folders)
allow(subject).to receive(:save_synced_folders)
end

View File

@ -11,8 +11,8 @@ describe Vagrant::BatchAction do
def new_machine(options)
double("machine").tap do |m|
m.stub(provider_name: provider_name)
m.stub(provider_options: options)
allow(m).to receive(:provider_name).and_return(provider_name)
allow(m).to receive(:provider_options).and_return(options)
allow(m).to receive(:action) do |action, opts|
lock.synchronize do
called_actions << [m, action, opts]

View File

@ -110,7 +110,7 @@ describe Vagrant::Box, :skip_windows do
}
RAW
subject.stub(load_metadata: metadata)
allow(subject).to receive(:load_metadata).and_return(metadata)
expect(subject.has_update?).to be_nil
end
@ -136,7 +136,7 @@ describe Vagrant::Box, :skip_windows do
}
RAW
subject.stub(load_metadata: metadata)
allow(subject).to receive(:load_metadata).and_return(metadata)
result = subject.has_update?
expect(result).to_not be_nil
@ -180,7 +180,7 @@ describe Vagrant::Box, :skip_windows do
}
RAW
subject.stub(load_metadata: metadata)
allow(subject).to receive(:load_metadata).and_return(metadata)
result = subject.has_update?(">= 1.1, < 1.4")
expect(result).to_not be_nil
@ -256,8 +256,8 @@ describe Vagrant::Box, :skip_windows do
it "raises an error if the download failed" do
dl = double("downloader")
Vagrant::Util::Downloader.stub(new: dl)
dl.should_receive(:download!).and_raise(
allow(Vagrant::Util::Downloader).to receive(:new).and_return(dl)
expect(dl).to receive(:download!).and_raise(
Vagrant::Errors::DownloaderError.new(message: "foo"))
expect { subject.load_metadata }.

View File

@ -11,7 +11,7 @@ describe Vagrant::CLI do
let(:env) { iso_env.create_vagrant_env }
before do
Vagrant.plugin("2").manager.stub(commands: commands)
allow(Vagrant.plugin("2").manager).to receive(:commands).and_return(commands)
end
describe "#execute" do

View File

@ -31,8 +31,8 @@ describe Vagrant::Environment do
before do
m = Vagrant.plugin("2").manager
m.stub(hosts: plugin_hosts)
m.stub(host_capabilities: plugin_host_caps)
allow(m).to receive(:hosts).and_return(plugin_hosts)
allow(m).to receive(:host_capabilities).and_return(plugin_host_caps)
# Detect the host
env.vagrantfile <<-VF
@ -160,7 +160,8 @@ describe Vagrant::Environment do
it "moves the boxes into the new directory structure" do
# Kind of hacky but avoids two instantiations of BoxCollection
Vagrant::Environment.any_instance.stub(boxes: double("boxes"))
allow(Vagrant::Environment).to receive(:boxes)
.and_return(double("boxes"))
collection = double("collection")
expect(Vagrant::BoxCollection).to receive(:new).with(
@ -177,8 +178,8 @@ describe Vagrant::Environment do
before do
m = Vagrant.plugin("2").manager
m.stub(hosts: plugin_hosts)
m.stub(host_capabilities: plugin_host_caps)
allow(m).to receive(:hosts).and_return(plugin_hosts)
allow(m).to receive(:host_capabilities).and_return(plugin_host_caps)
end
it "should default to some host even if there are none" do
@ -641,7 +642,7 @@ VF
klass = double("machine_index")
stub_const("Vagrant::MachineIndex", klass)
klass.should_receive(:new).with(any_args) do |path|
expect(klass).to receive(:new).with(any_args) do |path|
expect(path.to_s.start_with?(subject.home_path.to_s)).to be(true)
true
end
@ -759,7 +760,7 @@ VF
before do
m = Vagrant.plugin("2").manager
m.stub(providers: plugin_providers)
allow(m).to receive(:providers).and_return(plugin_providers)
end
it "is the highest matching usable provider" do

View File

@ -9,10 +9,10 @@ describe Vagrant::Guest do
let(:guests) { {} }
let(:machine) do
double("machine").tap do |m|
m.stub(inspect: "machine")
m.stub(config: double("config"))
m.config.stub(vm: double("vm_config"))
m.config.vm.stub(guest: nil)
allow(m).to receive(:inspect).and_return("machine")
allow(m).to receive(:config).and_return(double("config"))
allow(m.config).to receive(:vm).and_return(double("vm_config"))
allow(m.config.vm).to receive(:guest).and_return(nil)
end
end
@ -47,7 +47,7 @@ describe Vagrant::Guest do
describe "#detect!" do
it "auto-detects if no explicit guest name given" do
machine.config.vm.stub(guest: nil)
allow(machine.config.vm).to receive(:guest).and_return(nil)
expect(subject).to receive(:initialize_capabilities!).
with(nil, guests, capabilities, machine)
@ -55,7 +55,7 @@ describe Vagrant::Guest do
end
it "uses the explicit guest name if specified" do
machine.config.vm.stub(guest: :foo)
allow(machine.config.vm).to receive(:guest).and_return(:foo)
expect(subject).to receive(:initialize_capabilities!).
with(:foo, guests, capabilities, machine)
@ -63,7 +63,7 @@ describe Vagrant::Guest do
end
it "raises a user-friendly error if specified guest doesn't exist" do
machine.config.vm.stub(guest: :foo)
allow(machine.config.vm).to receive(:guest).and_return(:foo)
expect { subject.detect! }.
to raise_error(Vagrant::Errors::GuestExplicitNotDetected)

View File

@ -12,7 +12,7 @@ describe Vagrant::Machine do
let(:provider) { new_provider_mock }
let(:provider_cls) do
obj = double("provider_cls")
obj.stub(new: provider)
allow(obj).to receive(:new).and_return(provider)
obj
end
let(:provider_config) { Object.new }
@ -21,9 +21,9 @@ describe Vagrant::Machine do
let(:base) { false }
let(:box) do
double("box").tap do |b|
b.stub(name: "foo")
b.stub(provider: :dummy)
b.stub(version: "1.0")
allow(b).to receive(:name).and_return("foo")
allow(b).to receive(:provider).and_return(:dummy)
allow(b).to receive(:version).and_return("1.0")
end
end
@ -50,8 +50,8 @@ describe Vagrant::Machine do
def new_provider_mock
double("provider").tap do |obj|
obj.stub(_initialize: nil)
obj.stub(machine_id_changed: nil)
allow(obj).to receive(:_initialize).and_return(nil)
allow(obj).to receive(:machine_id_changed).and_return(nil)
allow(obj).to receive(:state).and_return(Vagrant::MachineState.new(
:created, "", ""))
end
@ -533,9 +533,9 @@ describe Vagrant::Machine do
# Setup the box information
box = double("box")
box.stub(name: "foo")
box.stub(provider: :bar)
box.stub(version: "1.2.3")
allow(box).to receive(:name).and_return("foo")
allow(box).to receive(:provider).and_return(:bar)
allow(box).to receive(:version).and_return("1.2.3")
subject.box = box
subject.id = "foo"

View File

@ -21,7 +21,7 @@ describe Vagrant::Plugin::Manager do
end
before do
Vagrant::Bundler.stub(instance: bundler)
allow(Vagrant::Bundler).to receive(:instance).and_return(bundler)
end
subject { described_class.new(path) }
@ -152,7 +152,7 @@ describe Vagrant::Plugin::Manager do
before do
systems_path.unlink
described_class.stub(system_plugins_file: systems_path)
allow(described_class).to receive(:system_plugins_file).and_return(systems_path)
sf = Vagrant::Plugin::StateFile.new(systems_path)
sf.add_plugin("foo", version: "0.2.0")
@ -230,7 +230,7 @@ describe Vagrant::Plugin::Manager do
before do
systems_path.unlink
described_class.stub(system_plugins_file: systems_path)
allow(described_class).to receive(:system_plugins_file).and_return(systems_path)
sf = Vagrant::Plugin::StateFile.new(systems_path)
sf.add_plugin("foo", version: "0.2.0")

View File

@ -55,14 +55,14 @@ describe Vagrant::Plugin::V1::Command do
let(:environment) do
env = double("environment")
env.stub(root_path: "foo")
allow(env).to receive(:root_path).and_return("foo")
env
end
let(:instance) { klass.new([], environment) }
it "should raise an exception if a root_path is not available" do
environment.stub(root_path: nil)
allow(environment).to receive(:root_path).and_return(nil)
expect { instance.with_target_vms }.
to raise_error(Vagrant::Errors::NoEnvironmentError)
@ -75,9 +75,9 @@ describe Vagrant::Plugin::V1::Command do
bar_vm = double("bar")
allow(bar_vm).to receive(:name).and_return("bar")
environment.stub(multivm?: true,
vms: { "foo" => foo_vm, "bar" => bar_vm },
vms_ordered: [foo_vm, bar_vm])
allow(environment).to receive(:multivm?).and_return(true)
allow(environment).to receive(:vms).and_return({ "foo" => foo_vm, "bar" => bar_vm })
allow(environment).to receive(:vms_ordered).and_return([foo_vm, bar_vm])
vms = []
instance.with_target_vms do |vm|
@ -88,7 +88,8 @@ describe Vagrant::Plugin::V1::Command do
end
it "raises an exception if the named VM doesn't exist" do
environment.stub(multivm?: true, vms: {})
allow(environment).to receive(:multivm?).and_return(true)
allow(environment).to receive(:vms).and_return({})
expect { instance.with_target_vms("foo") }.
to raise_error(Vagrant::Errors::VMNotFoundError)
@ -98,8 +99,8 @@ describe Vagrant::Plugin::V1::Command do
foo_vm = double("foo")
allow(foo_vm).to receive(:name).and_return(:foo)
environment.stub(multivm?: true,
vms: { foo: foo_vm, bar: nil })
allow(environment).to receive(:multivm?).and_return(true)
allow(environment).to receive(:vms).and_return({ foo: foo_vm, bar: nil })
vms = []
instance.with_target_vms("foo") { |vm| vms << vm }

View File

@ -78,7 +78,7 @@ describe Vagrant::Plugin::V2::Command do
subject { instance }
it "should raise an exception if a root_path is not available" do
environment.stub(root_path: nil)
allow(environment).to receive(:root_path).and_return(nil)
expect { instance.with_target_vms }.
to raise_error(Vagrant::Errors::NoEnvironmentError)
@ -86,16 +86,18 @@ describe Vagrant::Plugin::V2::Command do
it "should yield every VM in order if no name is given" do
foo_vm = double("foo")
foo_vm.stub(name: "foo", provider: :foobarbaz)
foo_vm.stub(ui: Vagrant::UI::Silent.new)
foo_vm.stub(state: nil)
allow(foo_vm).to receive(:name).and_return("foo")
allow(foo_vm).to receive(:provider).and_return(:foobarbaz)
allow(foo_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(foo_vm).to receive(:state).and_return(nil)
bar_vm = double("bar")
bar_vm.stub(name: "bar", provider: :foobarbaz)
bar_vm.stub(ui: Vagrant::UI::Silent.new)
bar_vm.stub(state: nil)
allow(bar_vm).to receive(:name).and_return("bar")
allow(bar_vm).to receive(:provider).and_return(:foobarbaz)
allow(bar_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(bar_vm).to receive(:state).and_return(nil)
environment.stub(machine_names: [:foo, :bar])
allow(environment).to receive(:machine_names).and_return([:foo, :bar])
allow(environment).to receive(:machine).with(:foo, environment.default_provider).and_return(foo_vm)
allow(environment).to receive(:machine).with(:bar, environment.default_provider).and_return(bar_vm)
@ -108,7 +110,7 @@ describe Vagrant::Plugin::V2::Command do
end
it "raises an exception if the named VM doesn't exist" do
environment.stub(machine_names: [:default])
allow(environment).to receive(:machine_names).and_return([:default])
allow(environment).to receive(:machine).with(:foo, anything).and_return(nil)
expect { instance.with_target_vms("foo") }.
@ -117,9 +119,10 @@ describe Vagrant::Plugin::V2::Command do
it "yields the given VM if a name is given" do
foo_vm = double("foo")
foo_vm.stub(name: "foo", provider: :foobarbaz)
foo_vm.stub(ui: Vagrant::UI::Silent.new)
foo_vm.stub(state: nil)
allow(foo_vm).to receive(:name).and_return("foo")
allow(foo_vm).to receive(:provider).and_return(:foobarbaz)
allow(foo_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(foo_vm).to receive(:state).and_return(nil)
allow(environment).to receive(:machine).with(:foo, environment.default_provider).and_return(foo_vm)
@ -130,9 +133,10 @@ describe Vagrant::Plugin::V2::Command do
it "calls state after yielding the vm to update the machine index" do
foo_vm = double("foo")
foo_vm.stub(name: "foo", provider: :foobarbaz)
foo_vm.stub(ui: Vagrant::UI::Silent.new)
foo_vm.stub(state: nil)
allow(foo_vm).to receive(:name).and_return("foo")
allow(foo_vm).to receive(:provider).and_return(:foobarbaz)
allow(foo_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(foo_vm).to receive(:state).and_return(nil)
allow(environment).to receive(:machine).with(:foo, environment.default_provider).and_return(foo_vm)
@ -145,9 +149,10 @@ describe Vagrant::Plugin::V2::Command do
foo_vm = double("foo")
provider = :foobarbaz
foo_vm.stub(name: "foo", provider: provider)
foo_vm.stub(ui: Vagrant::UI::Silent.new)
foo_vm.stub(state: nil)
allow(foo_vm).to receive(:name).and_return("foo")
allow(foo_vm).to receive(:provider).and_return(provider)
allow(foo_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(foo_vm).to receive(:state).and_return(nil)
allow(environment).to receive(:machine).with(:foo, provider).and_return(foo_vm)
vms = []
@ -158,7 +163,7 @@ describe Vagrant::Plugin::V2::Command do
it "should raise an exception if an active machine exists with a different provider" do
name = :foo
environment.stub(active_machines: [[name, :vmware]])
allow(environment).to receive(:active_machines).and_return([[name, :vmware]])
expect { instance.with_target_vms(name.to_s, provider: :foo) }.
to raise_error Vagrant::Errors::ActiveMachineWithDifferentProvider
end
@ -168,11 +173,12 @@ describe Vagrant::Plugin::V2::Command do
provider = :vmware
vmware_vm = double("vmware_vm")
environment.stub(active_machines: [[name, provider]])
allow(environment).to receive(:active_machines).and_return([[name, provider]])
allow(environment).to receive(:machine).with(name, provider).and_return(vmware_vm)
vmware_vm.stub(name: name, provider: provider)
vmware_vm.stub(ui: Vagrant::UI::Silent.new)
vmware_vm.stub(state: nil)
allow(vmware_vm).to receive(:name).and_return(name)
allow(vmware_vm).to receive(:provider).and_return(provider)
allow(vmware_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(vmware_vm).to receive(:state).and_return(nil)
vms = []
instance.with_target_vms(name.to_s) { |vm| vms << vm }
@ -184,10 +190,12 @@ describe Vagrant::Plugin::V2::Command do
provider = :vmware
vmware_vm = double("vmware_vm")
environment.stub(active_machines: [[name, provider]])
allow(environment).to receive(:active_machines).and_return([[name, provider]])
allow(environment).to receive(:machine).with(name, provider).and_return(vmware_vm)
vmware_vm.stub(name: name, provider: provider, ui: Vagrant::UI::Silent.new)
vmware_vm.stub(state: nil)
allow(vmware_vm).to receive(:name).and_return(name)
allow(vmware_vm).to receive(:provider).and_return(provider)
allow(vmware_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(vmware_vm).to receive(:state).and_return(nil)
vms = []
instance.with_target_vms(name.to_s, provider: provider) { |vm| vms << vm }
@ -199,9 +207,10 @@ describe Vagrant::Plugin::V2::Command do
machine = double("machine")
allow(environment).to receive(:machine).with(name, environment.default_provider).and_return(machine)
machine.stub(name: name, provider: environment.default_provider)
machine.stub(ui: Vagrant::UI::Silent.new)
machine.stub(state: nil)
allow(machine).to receive(:name).and_return(name)
allow(machine).to receive(:provider).and_return(environment.default_provider)
allow(machine).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(machine).to receive(:state).and_return(nil)
results = []
instance.with_target_vms(name.to_s) { |m| results << m }
@ -213,13 +222,14 @@ describe Vagrant::Plugin::V2::Command do
provider = :vmware
vmware_vm = double("vmware_vm")
environment.stub(active_machines: [[name, provider]])
allow(environment).to receive(:active_machines).and_return([[name, provider]])
allow(environment).to receive(:machine).with(name, provider).and_return(vmware_vm)
environment.stub(machine_names: [])
environment.stub(primary_machine_name: name)
vmware_vm.stub(name: name, provider: provider)
vmware_vm.stub(ui: Vagrant::UI::Silent.new)
vmware_vm.stub(state: nil)
allow(environment).to receive(:machine_names).and_return([])
allow(environment).to receive(:primary_machine_name).and_return(name)
allow(vmware_vm).to receive(:name).and_return(name)
allow(vmware_vm).to receive(:provider).and_return(provider)
allow(vmware_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(vmware_vm).to receive(:state).and_return(nil)
vms = []
instance.with_target_vms(nil, single_target: true) { |vm| vms << vm }
@ -230,13 +240,14 @@ describe Vagrant::Plugin::V2::Command do
name = :foo
machine = double("machine")
environment.stub(active_machines: [])
allow(environment).to receive(:active_machines).and_return([])
allow(environment).to receive(:machine).with(name, environment.default_provider).and_return(machine)
environment.stub(machine_names: [])
environment.stub(primary_machine_name: name)
machine.stub(name: name, provider: environment.default_provider)
machine.stub(ui: Vagrant::UI::Silent.new)
machine.stub(state: nil)
allow(environment).to receive(:machine_names).and_return([])
allow(environment).to receive(:primary_machine_name).and_return(name)
allow(machine).to receive(:name).and_return(name)
allow(machine).to receive(:provider).and_return(environment.default_provider)
allow(machine).to receive(:ui).and_return(Vagrant::UI::Silent.new)
allow(machine).to receive(:state).and_return(nil)
vms = []
instance.with_target_vms(nil, single_target: true) { |vm| vms << machine }
@ -255,7 +266,7 @@ describe Vagrant::Plugin::V2::Command do
other_machine.id = "foo"
# Make sure we don't have a root path, to test
environment.stub(root_path: nil)
allow(environment).to receive(:root_path).and_return(nil)
results = []
subject.with_target_vms(other_machine.index_uuid) { |m| results << m }
@ -282,7 +293,7 @@ describe Vagrant::Plugin::V2::Command do
FileUtils.rm_rf(iso_env.workdir)
# Make sure we don't have a root path, to test
environment.stub(root_path: nil)
allow(environment).to receive(:root_path).and_return(nil)
# Run the command
expect {

View File

@ -2,7 +2,8 @@ require File.expand_path("../../../../base", __FILE__)
describe Vagrant::Plugin::V2::Plugin do
before do
described_class.stub(manager: Vagrant::Plugin::V2::Manager.new)
allow(described_class).to receive(:manager)
.and_return(Vagrant::Plugin::V2::Manager.new)
end
it "should be able to set and get the name" do

View File

@ -42,7 +42,7 @@ describe Vagrant::Plugin::V2::Provider do
end
end
machine.stub(id: "YEAH")
allow(machine).to receive(:id).and_return("YEAH")
instance._initialize("foo", machine)
end

View File

@ -31,12 +31,12 @@ describe Vagrant do
describe "#installer_embedded_dir" do
it "returns nil if not in an installer" do
Vagrant.stub(in_installer?: false)
allow(Vagrant).to receive(:in_installer?).and_return(false)
expect(subject.installer_embedded_dir).to be_nil
end
it "returns the set directory" do
Vagrant.stub(in_installer?: true)
allow(Vagrant).to receive(:in_installer?).and_return(true)
with_temp_env("VAGRANT_INSTALLER_EMBEDDED_DIR" => "/foo") do
expect(subject.installer_embedded_dir).to eq("/foo")

View File

@ -350,7 +350,7 @@ describe Vagrant::UI::Prefixed do
describe "#opts" do
it "is the parent's opts" do
ui.stub(opts: Object.new)
allow(ui).to receive(:opts).and_return(Object.new)
expect(subject.opts).to be(ui.opts)
end
end

View File

@ -9,8 +9,8 @@ describe Vagrant::Util::Downloader do
let(:subprocess_result) do
double("subprocess_result").tap do |result|
result.stub(exit_code: exit_code)
result.stub(stderr: "")
allow(result).to receive(:exit_code).and_return(exit_code)
allow(result).to receive(:stderr).and_return("")
end
end
@ -199,7 +199,7 @@ describe Vagrant::Util::Downloader do
}
it "returns the output" do
subprocess_result.stub(stdout: "foo")
allow(subprocess_result).to receive(:stdout).and_return("foo")
options = curl_options.dup
options.unshift("-I")

View File

@ -69,7 +69,7 @@ describe Vagrant do
it "finds plugins by gem name" do
specs = [Gem::Specification.new]
specs[0].name = "foo"
Vagrant::Plugin::Manager.instance.stub(installed_specs: specs)
allow(Vagrant::Plugin::Manager.instance).to receive(:installed_specs).and_return(specs)
expect(described_class.has_plugin?("foo")).to be(true)
expect(described_class.has_plugin?("bar")).to be(false)
@ -79,7 +79,7 @@ describe Vagrant do
specs = [Gem::Specification.new]
specs[0].name = "foo"
specs[0].version = "1.2.3"
Vagrant::Plugin::Manager.instance.stub(installed_specs: specs)
allow(Vagrant::Plugin::Manager.instance).to receive(:installed_specs).and_return(specs)
expect(described_class.has_plugin?("foo", "~> 1.2.0")).to be(true)
expect(described_class.has_plugin?("foo", "~> 1.0.0")).to be(false)