Merge pull request #8850 from briancain/UPDATE-RSPEC

Update rspec to recent version and fix deprecations
This commit is contained in:
Brian Cain 2017-08-09 09:01:26 -07:00 committed by GitHub
commit 7cdff2556b
101 changed files with 759 additions and 748 deletions

View File

@ -3,8 +3,8 @@ require "rubygems"
# Gems
require "checkpoint"
require "rspec/autorun"
require "webmock/rspec"
require "rspec/its"
# Require Vagrant itself so we can reference the proper
# classes to test.
@ -33,8 +33,6 @@ VAGRANT_TEST_CWD = Dir.mktmpdir("vagrant-test-cwd")
# Configure RSpec
RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
if Vagrant::Util::Platform.windows?
c.filter_run_excluding :skip_windows
else

View File

@ -18,7 +18,7 @@ describe VagrantPlugins::CommandBox::Command::Add 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 arguments" do
@ -32,7 +32,7 @@ describe VagrantPlugins::CommandBox::Command::Add do
let(:argv) { ["foo"] }
it "executes the runner with the proper actions" do
expect(action_runner).to receive(:run).with { |action, **opts|
expect(action_runner).to receive(:run).with(any_args) { |action, **opts|
expect(opts[:box_name]).to be_nil
expect(opts[:box_url]).to eq("foo")
true
@ -46,7 +46,7 @@ describe VagrantPlugins::CommandBox::Command::Add do
let(:argv) { ["foo", "bar"] }
it "executes the runner with the proper actions" do
expect(action_runner).to receive(:run).with { |action, **opts|
expect(action_runner).to receive(:run).with(any_args) { |action, **opts|
expect(opts[:box_name]).to eq("foo")
expect(opts[:box_url]).to eq("bar")
true

View File

@ -18,7 +18,7 @@ describe VagrantPlugins::CommandBox::Command::Remove 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 arguments" do
@ -32,9 +32,9 @@ describe VagrantPlugins::CommandBox::Command::Remove do
let(:argv) { ["foo"] }
it "invokes the action runner" do
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq("foo")
expect(opts[:force_confirm_box_remove]).to be_false
expect(opts[:force_confirm_box_remove]).to be(false)
true
}
@ -45,9 +45,9 @@ describe VagrantPlugins::CommandBox::Command::Remove do
let(:argv) { super() + ["--force"] }
it "invokes the action runner with force option" do
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq("foo")
expect(opts[:force_confirm_box_remove]).to be_true
expect(opts[:force_confirm_box_remove]).to be(true)
true
}
@ -60,7 +60,7 @@ describe VagrantPlugins::CommandBox::Command::Remove do
let(:argv) { ["foo", "bar"] }
it "uses the 2nd arg as a provider" do
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq("foo")
expect(opts[:box_provider]).to eq("bar")
true

View File

@ -18,7 +18,7 @@ describe VagrantPlugins::CommandBox::Command::Repackage 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 arguments" do
@ -47,9 +47,7 @@ describe VagrantPlugins::CommandBox::Command::Repackage do
end
context "with three arguments" do
it "repackages the box with the given provider" do
pending
end
it "repackages the box with the given provider"
end
context "with more than three arguments" do

View File

@ -27,7 +27,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
subject { described_class.new(argv, iso_env) }
before do
iso_env.stub(action_runner: action_runner)
allow(iso_env).to receive(:action_runner).and_return(action_runner)
machine.config.vm.box = "foo"
end
@ -64,7 +64,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
subject.execute
expect(called).to be_false
expect(called).to be(false)
end
it "does update if there is an update" do
@ -108,7 +108,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
subject.execute
expect(action_called).to be_true
expect(action_called).to be(true)
end
it "raises an error if there are multiple providers" do
@ -162,7 +162,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
subject.execute
expect(action_called).to be_true
expect(action_called).to be(true)
end
it "raises an error if that provider doesn't exist" do
@ -206,14 +206,14 @@ describe VagrantPlugins::CommandBox::Command::Update do
expect(opts[:box_download_ca_cert]).to eq("foo")
expect(opts[:box_download_ca_path]).to eq("bar")
expect(opts[:box_client_cert]).to eq("baz")
expect(opts[:box_download_insecure]).to be_true
expect(opts[:box_download_insecure]).to be(true)
end
opts
end
subject.execute
expect(action_called).to be_true
expect(action_called).to be(true)
end
end
@ -238,7 +238,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
box_dir = test_iso_env.box3("foo", "1.0", :virtualbox)
box = Vagrant::Box.new(
"foo", :virtualbox, "1.0", box_dir, metadata_url: "foo")
box.stub(has_update?: nil)
allow(box).to receive(:has_update?).and_return(nil)
box
end
@ -249,7 +249,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
end
it "doesn't update boxes if they're up-to-date" do
machine.stub(box: box)
allow(machine).to receive(:box).and_return(box)
expect(box).to receive(:has_update?).
with(machine.config.vm.box_version,
{download_options:
@ -285,7 +285,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
RAW
}
before { machine.stub(box: box) }
before { allow(machine).to receive(:box).and_return(box) }
it "updates boxes" do
expect(box).to receive(:has_update?).
@ -295,7 +295,7 @@ describe VagrantPlugins::CommandBox::Command::Update do
insecure: false}}).
and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")])
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_url]).to eq(box.metadata_url)
expect(opts[:box_provider]).to eq("virtualbox")
expect(opts[:box_version]).to eq("1.1")
@ -322,11 +322,11 @@ describe VagrantPlugins::CommandBox::Command::Update do
insecure: false}}).
and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")])
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_download_ca_cert]).to eq("oof")
expect(opts[:box_download_ca_path]).to eq("rab")
expect(opts[:box_client_cert]).to eq("zab")
expect(opts[:box_download_insecure]).to be_false
expect(opts[:box_download_insecure]).to be(false)
true
}
@ -345,11 +345,11 @@ describe VagrantPlugins::CommandBox::Command::Update do
and_return([md, md.version("1.1"),
md.version("1.1").provider("virtualbox")])
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_download_ca_cert]).to eq("foo")
expect(opts[:box_download_ca_path]).to eq("bar")
expect(opts[:box_client_cert]).to eq("baz")
expect(opts[:box_download_insecure]).to be_true
expect(opts[:box_download_insecure]).to be(true)
true
}

View File

@ -16,7 +16,7 @@ describe VagrantPlugins::CommandInit::Command do
let(:vagrantfile_path) { File.join(env.cwd, "Vagrantfile") }
before do
Vagrant.plugin("2").manager.stub(commands: {})
allow(Vagrant.plugin("2").manager).to receive(:commands).and_return({})
end
after do

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
@ -28,7 +28,7 @@ describe VagrantPlugins::CommandListCommands::Command do
commands[:bar] = [command_lambda("bar", 0), { primary: true }]
commands[:baz] = [command_lambda("baz", 0), { primary: false }]
expect(iso_env.ui).to receive(:info).with { |message, opts|
expect(iso_env.ui).to receive(:info).with(any_args) { |message, opts|
expect(message).to include("foo")
expect(message).to include("bar")
expect(message).to include("baz")

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)
@ -84,7 +84,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do
end
it "should uninstall the plugin" do
expect(action_runner).to receive(:run).with { |action, newenv|
expect(action_runner).to receive(:run).with(any_args) { |action, newenv|
expect(newenv[:plugin_name]).to eql("foo")
}

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

@ -53,7 +53,7 @@ describe VagrantPlugins::CommandPort::Command do
it "ensures the vm is running" do
allow(state).to receive(:id).and_return(:stopped)
expect(env.ui).to receive(:error).with { |message, _|
expect(env.ui).to receive(:error).with(any_args) { |message, _|
expect(message).to include("does not support listing forwarded ports")
}
@ -62,7 +62,7 @@ describe VagrantPlugins::CommandPort::Command do
it "shows a friendly error when the capability is not supported" do
allow(machine.provider).to receive(:capability?).and_return(false)
expect(env.ui).to receive(:error).with { |message, _|
expect(env.ui).to receive(:error).with(any_args) { |message, _|
expect(message).to include("does not support listing forwarded ports")
}
@ -74,7 +74,7 @@ describe VagrantPlugins::CommandPort::Command do
allow(machine.provider).to receive(:capability).with(:forwarded_ports)
.and_return([])
expect(env.ui).to receive(:info).with { |message, _|
expect(env.ui).to receive(:info).with(any_args) { |message, _|
expect(message).to include("there are no forwarded ports")
}

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

@ -52,9 +52,8 @@ describe VagrantPlugins::CommandSnapshot::Command::List do
it "prints a message if the vm does not exist" do
machine.id = nil
expect(iso_env.ui).to receive(:info).with { |message, _|
expect(message).to include("VM not created")
}
expect(iso_env.ui).to receive(:info).with("==> default: VM not created. Moving on...", anything)
.and_return({})
expect(machine).to_not receive(:action)
expect(subject.execute).to eq(0)
end

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
@ -47,7 +47,7 @@ describe VagrantPlugins::CommandUp::Command do
end
it "should attempt to use dummy provider" do
expect{ subject.execute }.to raise_error
expect{ subject.execute }.to raise_error(Vagrant::Errors::ProviderNotFound)
end
context "with --provider set" do

View File

@ -30,7 +30,7 @@ describe VagrantPlugins::CommandValidate::Command do
end
EOH
expect(env.ui).to receive(:info).with { |message, _|
expect(env.ui).to receive(:info).with(any_args) { |message, _|
expect(message).to include("Vagrantfile validated successfully.")
}

View File

@ -109,7 +109,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
describe ".ready?" do
before(&connection_setup)
it "returns true if shell test is successful" do
expect(communicator.ready?).to be_true
expect(communicator.ready?).to be(true)
end
context "with an invalid shell test" do
@ -268,7 +268,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
before(&connection_setup)
context "with exit code as zero" do
it "returns true" do
expect(communicator.test("ls")).to be_true
expect(communicator.test("ls")).to be(true)
end
end
@ -278,7 +278,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
end
it "returns false" do
expect(communicator.test("/bin/false")).to be_false
expect(communicator.test("/bin/false")).to be(false)
end
end
end
@ -585,14 +585,14 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
describe ".generate_environment_export" do
it "should generate bourne shell compatible export" do
communicator.send(:generate_environment_export, "TEST", "value").should eq("export TEST=\"value\"\n")
expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("export TEST=\"value\"\n")
end
context "with custom template defined" do
let(:export_command_template){ "setenv %ENV_KEY% %ENV_VALUE%" }
it "should generate custom export based on template" do
communicator.send(:generate_environment_export, "TEST", "value").should eq("setenv TEST value\n")
expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("setenv TEST value\n")
end
end
end

View File

@ -60,12 +60,12 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
describe ".ready?" do
it "returns true if hostname command executes without error" do
expect(shell).to receive(:cmd).with("hostname").and_return({ exitcode: 0 })
expect(subject.ready?).to be_true
expect(subject.ready?).to be(true)
end
it "returns false if hostname command fails with a transient error" do
expect(shell).to receive(:cmd).with("hostname").and_raise(VagrantPlugins::CommunicatorWinRM::Errors::TransientError)
expect(subject.ready?).to be_false
expect(subject.ready?).to be(false)
end
it "raises an error if hostname command fails with an unknown error" do
@ -112,12 +112,12 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
describe ".test" do
it "returns true when exit code is zero" do
expect(shell).to receive(:powershell).with(kind_of(String)).and_return(good_output)
expect(subject.test("test -d c:/windows")).to be_true
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(bad_output)
expect(subject.test("test -d /tmp/foobar")).to be_false
expect(subject.test("test -d /tmp/foobar")).to be(false)
end
it "returns false when stderr contains output" do
@ -125,11 +125,11 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
output.exitcode = 1
output << { stderr: 'this is an error' }
expect(shell).to receive(:powershell).with(kind_of(String)).and_return(output)
expect(subject.test("[-x stuff] && foo")).to be_false
expect(subject.test("[-x stuff] && foo")).to be(false)
end
it "returns false when command is testing for linux OS" do
expect(subject.test("uname -s | grep Debian")).to be_false
expect(subject.test("uname -s | grep Debian")).to be(false)
end
end

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

@ -127,7 +127,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
describe ".ready?" do
before(&connection_setup)
it "returns true if shell test is successful" do
expect(communicator.ready?).to be_true
expect(communicator.ready?).to be_truthy
end
context "with an invalid shell test" do
@ -209,7 +209,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
before(&connection_setup)
context "with exit code as zero" do
it "returns true" do
expect(communicator.test("dir")).to be_true
expect(communicator.test("dir")).to be_truthy
end
end
@ -219,7 +219,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
end
it "returns false" do
expect(communicator.test("false.exe")).to be_false
expect(communicator.test("false.exe")).to be_falsey
end
end
end
@ -512,14 +512,14 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
describe ".generate_environment_export" do
it "should generate bourne shell compatible export" do
communicator.send(:generate_environment_export, "TEST", "value").should eq("export TEST=\"value\"\n")
expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("export TEST=\"value\"\n")
end
context "with custom template defined" do
let(:export_command_template){ "setenv %ENV_KEY% %ENV_VALUE%" }
it "should generate custom export based on template" do
communicator.send(:generate_environment_export, "TEST", "value").should eq("setenv TEST value\n")
expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("setenv TEST value\n")
end
end
end

View File

@ -40,8 +40,6 @@ describe "VagrantPlugins::GuestOmniOS::Cap:RSync" do
expect(comm.received_commands[0]).to match(/'1.2.3.4:#{hostpath}' '#{guestpath}'/)
end
it "mounts with options" do
pending "not yet implemented"
end
it "mounts with options"
end
end

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

@ -23,7 +23,7 @@ describe VagrantPlugins::GuestWindows::Config do
it "should not default #{attribute} if overridden" do
subject.send("#{attribute}=".to_sym, 10)
subject.finalize!
subject.send(attribute).should == 10
expect(subject.send(attribute)).to be(10)
end
it "should return error #{attribute} if nil" do

View File

@ -12,14 +12,14 @@ describe "VagrantPlugins::GuestWindows::GuestNetwork" do
expect(communicator).to receive(:test).with(
/.+Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=7 and DHCPEnabled=True"/).
and_return(true)
expect(subject.is_dhcp_enabled(7)).to be_true
expect(subject.is_dhcp_enabled(7)).to be(true)
end
it "should return false for non-DHCP NICs" do
expect(communicator).to receive(:test).with(
/.+Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=8 and DHCPEnabled=True"/).
and_return(false)
expect(subject.is_dhcp_enabled(8)).to be_false
expect(subject.is_dhcp_enabled(8)).to be(false)
end
end

View File

@ -147,10 +147,12 @@ EOH
it "should retain existing file owner and group IDs" do
pending("investigate using a simulated FS to test")
test_with_simulated_fs
end
it "should raise custom exception when chown fails" do
pending("investigate using a simulated FS to test")
test_with_simulated_fs
end
end
end

View File

@ -71,7 +71,7 @@ describe VagrantPlugins::Kernel_V2::PushConfig do
describe "#__compiled_pushes" do
it "raises an exception if not finalized" do
subject.instance_variable_set(:@__finalized, false)
expect { subject.__compiled_pushes }.to raise_error
expect { subject.__compiled_pushes }.to raise_error(RuntimeError)
end
it "returns a copy of the compiled pushes" 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
@ -356,7 +356,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
config = subject.get_provider_config(:virtualbox)
expect(config.name).to eq("foo")
expect(config.gui).to be_true
expect(config.gui).to be(true)
end
it "raises an exception if there is a problem loading" do
@ -543,7 +543,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
sf = subject.synced_folders
expect(sf.length).to eq(1)
expect(sf).to have_key("/vagrant")
expect(sf["/vagrant"][:disabled]).to be_true
expect(sf["/vagrant"][:disabled]).to be(true)
end
it "allows overriding previously set options" do
@ -553,7 +553,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
sf = subject.synced_folders
expect(sf.length).to eq(1)
expect(sf).to have_key("/vagrant")
expect(sf["/vagrant"][:disabled]).to be_false
expect(sf["/vagrant"][:disabled]).to be(false)
expect(sf["/vagrant"][:foo]).to eq(:bar)
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

@ -46,11 +46,11 @@ describe VagrantPlugins::DockerProvider::Config do
its(:expose) { should eq([]) }
its(:cmd) { should eq([]) }
its(:env) { should eq({}) }
its(:force_host_vm) { should be_false }
its(:force_host_vm) { should be(false) }
its(:host_vm_build_dir_options) { should be_nil }
its(:image) { should be_nil }
its(:name) { should be_nil }
its(:privileged) { should be_false }
its(:privileged) { should be(false) }
its(:stop_timeout) { should eq(1) }
its(:vagrant_machine) { should be_nil }
its(:vagrant_vagrantfile) { should be_nil }
@ -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

@ -47,7 +47,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do
allow(Tempfile).to receive(:new).with("vagrant-docker-compose").and_return(docker_yml)
allow(docker_yml).to receive(:write)
allow(docker_yml).to receive(:close)
subject.stub(:execute) do |*args|
allow(subject).to receive(:execute) do |*args|
args.delete_if{|i| i.is_a?(Hash) }
@cmd = args.join(' ')
end
@ -115,19 +115,21 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do
end
context 'when container exists' do
before { subject.stub(execute: "foo\n#{cid}\nbar") }
it { expect(result).to be_true }
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") }
it { expect(result).to be_false }
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
@ -142,43 +144,47 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do
end
context 'when container exists' do
before { subject.stub(execute: "foo\n#{cid}\nbar") }
it { expect(result).to be_true }
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") }
it { expect(result).to be_false }
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).not_to 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
@ -186,24 +192,24 @@ describe VagrantPlugins::DockerProvider::Driver::Compose 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).not_to receive(:execute).with('docker', 'stop', '-t', '1', cid)
subject.stop(cid, 1)
end
end
@ -211,7 +217,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose 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
expect(subject).to receive(:execute).with("docker-compose", "-f", "docker-compose.yml", "-p", "cwd", "rm", "-f", "docker_1", {})
@ -220,7 +226,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do
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
expect(subject).not_to receive(:execute).with("docker-compose", "-f", "docker-compose.yml", "-p", "cwd", "rm", "-f", "docker_1", {})
@ -232,10 +238,10 @@ describe VagrantPlugins::DockerProvider::Driver::Compose 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
@ -247,10 +253,10 @@ describe VagrantPlugins::DockerProvider::Driver::Compose 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
@ -258,10 +264,10 @@ describe VagrantPlugins::DockerProvider::Driver::Compose 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

@ -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") }
it { expect(result).to be_true }
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") }
it { expect(result).to be_false }
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") }
it { expect(result).to be_true }
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") }
it { expect(result).to be_false }
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
@ -39,10 +39,10 @@ describe VagrantPlugins::ProviderVirtualBox::Config do
context "defaults" do
before { subject.finalize! }
it { expect(subject.check_guest_additions).to be_true }
it { expect(subject.gui).to be_false }
it { expect(subject.check_guest_additions).to be(true) }
it { expect(subject.gui).to be(false) }
it { expect(subject.name).to be_nil }
it { expect(subject.functional_vboxsf).to be_true }
it { expect(subject.functional_vboxsf).to be(true) }
it "should have one NAT adapter" do
expect(subject.network_adapters).to eql({

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,11 +39,9 @@ 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" do
pending
end
it "should share the folders"
end
end

View File

@ -51,7 +51,7 @@ describe VagrantPlugins::Ansible::Config::Guest do
it "assigns default values to unset guest-specific options" do
subject.finalize!
expect(subject.install).to be_true
expect(subject.install).to be(true)
expect(subject.install_mode).to eql(:default)
expect(subject.provisioning_path).to eql("/vagrant")
expect(subject.tmp_path).to eql("/tmp/vagrant-ansible")

View File

@ -47,10 +47,10 @@ describe VagrantPlugins::Ansible::Config::Host, :skip_windows => true do
it "assigns default values to unset host-specific options" do
subject.finalize!
expect(subject.ask_sudo_pass).to be_false
expect(subject.ask_vault_pass).to be_false
expect(subject.force_remote_user).to be_true
expect(subject.host_key_checking).to be_false
expect(subject.ask_sudo_pass).to be(false)
expect(subject.ask_vault_pass).to be(false)
expect(subject.force_remote_user).to be(true)
expect(subject.host_key_checking).to be(false)
expect(subject.raw_ssh_args).to be_nil
end
end

View File

@ -17,11 +17,11 @@ shared_examples_for 'options shared by both Ansible provisioners' do
expect(subject.raw_arguments).to be_nil
expect(subject.skip_tags).to be_nil
expect(subject.start_at_task).to be_nil
expect(subject.sudo).to be_false
expect(subject.sudo).to be(false)
expect(subject.sudo_user).to be_nil
expect(subject.tags).to be_nil
expect(subject.vault_password_file).to be_nil
expect(subject.verbose).to be_false
expect(subject.verbose).to be(false)
end
end

View File

@ -45,20 +45,22 @@ VF
host: '127.0.0.1',
port: 2223
}}
let(:default_execute_result) { Vagrant::Util::Subprocess::Result.new(0, "", "") }
let(:existing_file) { File.expand_path(__FILE__) }
let(:generated_inventory_dir) { File.join(machine.env.local_data_path, %w(provisioners ansible inventory)) }
let(:generated_inventory_file) { File.join(generated_inventory_dir, 'vagrant_ansible_inventory') }
before do
Vagrant::Util::Platform.stub(solaris?: false)
allow(Vagrant::Util::Platform).to receive(:solaris?).and_return(false)
machine.stub(ssh_info: ssh_info)
machine.env.stub(active_machines: [[iso_env.machine_names[0], :dummy], [iso_env.machine_names[1], :dummy]])
allow(machine).to receive(:ssh_info).and_return(ssh_info)
allow(machine.env).to receive(:active_machines)
.and_return([[iso_env.machine_names[0], :dummy], [iso_env.machine_names[1], :dummy]])
stubbed_ui = Vagrant::UI::Colored.new
stubbed_ui.stub(detail: "")
machine.env.stub(ui: stubbed_ui)
allow(stubbed_ui).to receive(:detail).and_return("")
allow(machine.env).to receive(:ui).and_return(stubbed_ui)
config.playbook = 'playbook.yml'
end
@ -74,7 +76,7 @@ VF
expected_transport_mode = "ssh")
it "sets implicit arguments in a specific order" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[0]).to eq("ansible-playbook")
expect(args[1]).to eq("--connection=ssh")
@ -84,11 +86,11 @@ VF
expect(inventory_count).to be > 0
expect(args[args.length-2]).to eq("playbook.yml")
}
}.and_return(default_execute_result)
end
it "sets --limit argument" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
all_limits = args.select { |x| x =~ /^(--limit=|-l)/ }
if config.raw_arguments
raw_limits = config.raw_arguments.select { |x| x =~ /^(--limit=|-l)/ }
@ -102,11 +104,11 @@ VF
expect(all_limits.first).to eq("--limit=#{machine.name}")
end
end
}
}.and_return(default_execute_result)
end
it "exports environment variables" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
if expected_host_key_checking
@ -119,30 +121,30 @@ VF
expect(cmd_opts[:env]).to_not include("ANSIBLE_NOCOLOR")
expect(cmd_opts[:env]['ANSIBLE_HOST_KEY_CHECKING']).to eql(expected_host_key_checking.to_s)
expect(cmd_opts[:env]['PYTHONUNBUFFERED']).to eql(1)
}
}.and_return(default_execute_result)
end
# "roughly" verify that only expected args/vars have been defined by the provisioner
it "sets the expected number of arguments and environment variables" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args.length-2).to eq(expected_args_count)
expect(args.last[:env].length).to eq(expected_vars_count)
}
}.and_return(default_execute_result)
end
it "enables '#{expected_transport_mode}' as default transport mode" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
index = args.rindex("--connection=#{expected_transport_mode}")
expect(index).to be > 0
expect(find_last_argument_after(index, args, /--connection=\w+/)).to be_false
}
expect(find_last_argument_after(index, args, /--connection=\w+/)).to be(false)
}.and_return(default_execute_result)
end
end
def self.it_should_set_optional_arguments(arg_map)
it "sets optional arguments" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
arg_map.each_pair do |vagrant_option, ansible_argument|
index = args.index(ansible_argument)
if config.send(vagrant_option)
@ -151,25 +153,25 @@ VF
expect(index).to be_nil
end
end
}
}.and_return(default_execute_result)
end
end
def self.it_should_explicitly_enable_ansible_ssh_control_persist_defaults
it "configures ControlPersist (like Ansible defaults) via ANSIBLE_SSH_ARGS" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ControlMaster=auto")
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ControlPersist=60s")
}
}.and_return(default_execute_result)
end
end
def self.it_should_create_and_use_generated_inventory(with_ssh_user = true)
it "generates an inventory with all active machines" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(config.inventory_path).to be_nil
expect(File.exists?(generated_inventory_file)).to be_true
expect(File.exists?(generated_inventory_file)).to be(true)
inventory_content = File.read(generated_inventory_file)
if with_ssh_user
expect(inventory_content).to include("#{machine.name} ansible_ssh_host=#{machine.ssh_info[:host]} ansible_ssh_port=#{machine.ssh_info[:port]} ansible_ssh_user='#{machine.ssh_info[:username]}' ansible_ssh_private_key_file='#{machine.ssh_info[:private_key_path][0]}'\n")
@ -177,31 +179,32 @@ VF
expect(inventory_content).to include("#{machine.name} ansible_ssh_host=#{machine.ssh_info[:host]} ansible_ssh_port=#{machine.ssh_info[:port]} ansible_ssh_private_key_file='#{machine.ssh_info[:private_key_path][0]}'\n")
end
expect(inventory_content).to include("# MISSING: '#{iso_env.machine_names[1]}' machine was probably removed without using Vagrant. This machine should be recreated.\n")
}
}.and_return(default_execute_result)
end
it "sets as ansible inventory the directory containing the auto-generated inventory file" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_index = args.rindex("--inventory-file=#{generated_inventory_dir}")
expect(inventory_index).to be > 0
expect(find_last_argument_after(inventory_index, args, /--inventory-file=\w+/)).to be_false
}
expect(find_last_argument_after(inventory_index, args, /--inventory-file=\w+/)).to be(false)
}.and_return(default_execute_result)
end
end
describe "#provision" do
before do
unless example.metadata[:skip_before]
unless RSpec.current_example.metadata[:skip_before]
config.finalize!
Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(0, "", ""))
subject.stub(:check_path)
allow(Vagrant::Util::Subprocess).to receive(:execute)
.and_return(Vagrant::Util::Subprocess::Result.new(0, "", ""))
allow(subject).to receive(:check_path)
end
end
after do
unless example.metadata[:skip_after]
unless RSpec.current_example.metadata[:skip_after]
subject.provision
end
end
@ -211,7 +214,7 @@ VF
STUBBED_INVALID_PATH = "/test/239nfmd/invalid_path".freeze
it 'raises an error when the `playbook` file does not exist', skip_before: true, skip_after: true do
subject.stub(:check_path).and_raise(VagrantPlugins::Ansible::Errors::AnsibleError,
allow(subject).to receive(:check_path).and_raise(VagrantPlugins::Ansible::Errors::AnsibleError,
_key: :config_file_not_found,
config_option: "playbook",
path: STUBBED_INVALID_PATH,
@ -226,7 +229,8 @@ VF
%w(config_file extra_vars inventory_path galaxy_role_file vault_password_file).each do |option_name|
it "raises an error when the '#{option_name}' does not exist", skip_before: true, skip_after: true do
Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(0, "", ""))
allow(Vagrant::Util::Subprocess).to receive(:execute)
.and_return( Vagrant::Util::Subprocess::Result.new(0, "", ""))
config.playbook = existing_file
config.send(option_name + '=', STUBBED_INVALID_PATH)
@ -247,8 +251,8 @@ VF
it "raises an error", skip_before: true, skip_after: true do
config.finalize!
subject.stub(:check_path)
Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(1, "", ""))
allow(subject).to receive(:check_path)
allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(Vagrant::Util::Subprocess::Result.new(1, "", ""))
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCommandFailed)
end
@ -259,18 +263,14 @@ VF
it_should_create_and_use_generated_inventory
it "does not add any group section to the generated inventory" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to_not match(/^\s*\[^\\+\]\s*$/)
# Ending this block with a negative expectation (to_not / not_to)
# would lead to a failure of the above expectation.
true
}
}.and_return(default_execute_result)
end
it "doesn't show the ansible-playbook command" do
expect(machine.env.ui).not_to receive(:detail).with { |full_command|
expect(machine.env.ui).not_to receive(:detail).with(any_args) { |full_command|
expect(full_command).to include("ansible-playbook")
}
end
@ -282,9 +282,9 @@ VF
end
it "uses custom playbook_command to run playbooks" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[0]).to eq("custom-ansible-playbook")
}
}.and_return(default_execute_result)
end
end
@ -295,40 +295,40 @@ VF
config.host_vars = {
machine1: {"http_port" => 80, "comments" => "'some text with spaces'"}
}
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 comments='some text with spaces'$")
}
}.and_return(default_execute_result)
end
it "adds host variables (given in Array format) to the generated inventory" do
config.host_vars = {
machine1: ["http_port=80", "maxRequestsPerChild=808"]
}
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808")
}
}.and_return(default_execute_result)
end
it "adds host variables (given in String format) to the generated inventory " do
config.host_vars = {
:machine1 => "http_port=80 maxRequestsPerChild=808"
}
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808")
}
}.and_return(default_execute_result)
end
it "retrieves the host variables by machine name, also in String format" do
config.host_vars = {
"machine1" => "http_port=80 maxRequestsPerChild=808"
}
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808")
}
}.and_return(default_execute_result)
end
end
@ -347,7 +347,7 @@ VF
"bar:children" => ["group1", "group2", "group3", "group5"],
}
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
# Accept String instead of Array for group member list
@ -372,7 +372,7 @@ VF
# A group of groups only includes declared groups
expect(inventory_content).not_to include("group5")
expect(inventory_content).to match(Regexp.quote("[bar:children]\ngroup1\ngroup2\ngroup3\n") + "$")
}
}.and_return(default_execute_result)
end
it "adds group vars to the generated inventory" do
@ -385,7 +385,7 @@ VF
"group3:vars" => "stringvar1=stringvalue1 stringvar2=stringvalue2",
}
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
# Hash syntax
@ -396,7 +396,7 @@ VF
# Single string syntax
expect(inventory_content).to include("[group3:vars]\nstringvar1=stringvalue1\nstringvar2=stringvalue2\n")
}
}.and_return(default_execute_result)
end
end
@ -421,11 +421,11 @@ VF
it_should_set_optional_arguments({ "sudo_user" => "--sudo-user=root" })
it "it does not set boolean flag when corresponding option is set to false" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args.index("--sudo")).to be_nil
expect(args.index("--ask-sudo-pass")).to be_nil
expect(args.index("--ask-vault-pass")).to be_nil
}
}.and_return(default_execute_result)
end
end
@ -450,26 +450,26 @@ VF
it_should_set_arguments_and_environment_variables 17, 4, false, "paramiko"
it "sets all raw arguments" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
config.raw_arguments.each do |raw_arg|
expect(args).to include(raw_arg)
end
}
}.and_return(default_execute_result)
end
it "sets raw arguments after arguments related to supported options" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args.index("--user=lion")).to be > args.index("--user=testuser")
expect(args.index("--inventory-file=/forget/it/my/friend")).to be > args.index("--inventory-file=#{generated_inventory_dir}")
expect(args.index("--limit=bar")).to be > args.index("--limit=all")
expect(args.index("--skip-tags=ignored")).to be > args.index("--skip-tags=foo,bar")
}
}.and_return(default_execute_result)
end
it "sets boolean flag (e.g. --sudo) defined in raw_arguments, even if corresponding option is set to false" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).to include('--sudo')
}
}.and_return(default_execute_result)
end
end
@ -492,10 +492,10 @@ VF
it_should_set_arguments_and_environment_variables 6
it "uses a --user argument to set a default remote user" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).not_to include("--extra-vars=ansible_ssh_user='#{machine.ssh_info[:username]}'")
expect(args).to include("--user=#{machine.ssh_info[:username]}")
}
}.and_return(default_execute_result)
end
end
@ -524,13 +524,13 @@ VF
it "generates an inventory with winrm connection settings" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(config.inventory_path).to be_nil
expect(File.exists?(generated_inventory_file)).to be_true
expect(File.exists?(generated_inventory_file)).to be(true)
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to include("machine1 ansible_connection=winrm ansible_ssh_host=127.0.0.1 ansible_ssh_port=55986 ansible_ssh_user='winner' ansible_ssh_pass='winword'\n")
}
}.and_return(default_execute_result)
end
describe "with force_remote_user option disabled" do
@ -539,12 +539,12 @@ VF
end
it "doesn't set the ansible remote user in inventory and use '--user' argument with the vagrant ssh username" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
inventory_content = File.read(generated_inventory_file)
expect(inventory_content).to include("machine1 ansible_connection=winrm ansible_ssh_host=127.0.0.1 ansible_ssh_port=55986 ansible_ssh_pass='winword'\n")
expect(args).to include("--user=testuser")
}
}.and_return(default_execute_result)
end
end
end
@ -557,18 +557,18 @@ VF
it_should_set_arguments_and_environment_variables 6
it "does not generate the inventory and uses given inventory path instead" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).to include("--inventory-file=#{existing_file}")
expect(args).not_to include("--inventory-file=#{generated_inventory_file}")
expect(File.exists?(generated_inventory_file)).to be_false
}
expect(File.exists?(generated_inventory_file)).to be(false)
}.and_return(default_execute_result)
end
it "uses an --extra-vars argument to force ansible_ssh_user parameter" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).not_to include("--user=#{machine.ssh_info[:username]}")
expect(args).to include("--extra-vars=ansible_ssh_user='#{machine.ssh_info[:username]}'")
}
}.and_return(default_execute_result)
end
describe "with force_remote_user option disabled" do
@ -577,10 +577,10 @@ VF
end
it "uses a --user argument to set a default remote user" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).not_to include("--extra-vars=ansible_ssh_user='#{machine.ssh_info[:username]}'")
expect(args).to include("--user=#{machine.ssh_info[:username]}")
}
}.and_return(default_execute_result)
end
end
end
@ -591,11 +591,11 @@ VF
end
it "sets ANSIBLE_CONFIG environment variable" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]).to include("ANSIBLE_CONFIG")
expect(cmd_opts[:env]['ANSIBLE_CONFIG']).to eql(existing_file)
}
}.and_return(default_execute_result)
end
end
@ -607,9 +607,9 @@ VF
it_should_set_arguments_and_environment_variables 6
it "should ask the vault password" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).to include("--ask-vault-pass")
}
}.and_return(default_execute_result)
end
end
@ -621,9 +621,9 @@ VF
it_should_set_arguments_and_environment_variables 6
it "uses the given vault password file" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).to include("--vault-password-file=#{existing_file}")
}
}.and_return(default_execute_result)
end
end
@ -636,12 +636,12 @@ VF
it_should_explicitly_enable_ansible_ssh_control_persist_defaults
it "passes custom SSH options via ANSIBLE_SSH_ARGS with the highest priority" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
raw_opt_index = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ControlMaster=no")
default_opt_index = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ControlMaster=auto")
expect(raw_opt_index).to be < default_opt_index
}
}.and_return(default_execute_result)
end
describe "and with ssh forwarding enabled" do
@ -650,12 +650,12 @@ VF
end
it "sets '-o ForwardAgent=yes' via ANSIBLE_SSH_ARGS with higher priority than raw_ssh_args values" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
forwardAgentYes = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ForwardAgent=yes")
forwardAgentNo = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ForwardAgent=no")
expect(forwardAgentYes).to be < forwardAgentNo
}
}.and_return(default_execute_result)
end
end
@ -670,11 +670,11 @@ VF
it_should_explicitly_enable_ansible_ssh_control_persist_defaults
it "passes additional Identity Files via ANSIBLE_SSH_ARGS" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/an/other/identity")
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/yet/an/other/key")
}
}.and_return(default_execute_result)
end
end
@ -682,13 +682,13 @@ VF
before do
ssh_info[:private_key_path] = ['/foo%bar/key', '/bar%%buz/key']
end
it "replaces `%` with `%%`" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/foo%%bar/key")
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/bar%%%%buz/key")
}
}.and_return(default_execute_result)
end
end
@ -701,10 +701,10 @@ VF
it_should_explicitly_enable_ansible_ssh_control_persist_defaults
it "enables SSH-Forwarding via ANSIBLE_SSH_ARGS" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ForwardAgent=yes")
}
}.and_return(default_execute_result)
end
end
@ -714,10 +714,10 @@ VF
end
it "sets '-o ProxyCommand' via ANSIBLE_SSH_ARGS" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ProxyCommand='ssh -W %h:%p -q user@remote_libvirt_host'")
}
}.and_return(default_execute_result)
end
end
@ -733,7 +733,7 @@ VF
it_should_set_optional_arguments({ "verbose" => "-#{verbose_option}" })
it "shows the ansible-playbook command and set verbosity to '-#{verbose_option}' level" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command|
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -#{verbose_option} playbook.yml")
}
end
@ -748,7 +748,7 @@ VF
it_should_set_optional_arguments({ "verbose" => "-#{verbose_option}" })
it "shows the ansible-playbook command and set verbosity to '-#{verbose_option}' level" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command|
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -#{verbose_option} playbook.yml")
}
end
@ -764,7 +764,7 @@ VF
it_should_set_optional_arguments({ "verbose" => "-v" })
it "shows the ansible-playbook command and set verbosity to '-v' level" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command|
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -v playbook.yml")
}
end
@ -778,7 +778,7 @@ VF
it_should_set_arguments_and_environment_variables
it "doesn't show the ansible-playbook command" do
expect(machine.env.ui).not_to receive(:detail).with { |full_command|
expect(machine.env.ui).not_to receive(:detail).with(any_args) { |full_command|
expect(full_command).to include("ansible-playbook")
}
end
@ -788,15 +788,15 @@ VF
describe "without colorized output" do
before do
machine.env.stub(ui: Vagrant::UI::Basic.new)
allow(machine.env).to receive(:ui).and_return(Vagrant::UI::Basic.new)
end
it "disables ansible-playbook colored output" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]).to_not include("ANSIBLE_FORCE_COLOR")
expect(cmd_opts[:env]['ANSIBLE_NOCOLOR']).to eql("true")
}
}.and_return(default_execute_result)
end
end
@ -809,15 +809,21 @@ VF
it "raises an error when ansible-galaxy command fails", skip_before: true, skip_after: true do
config.finalize!
subject.stub(:check_path)
Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(1, "", ""))
allow(subject).to receive(:check_path)
allow(Vagrant::Util::Subprocess).to receive(:execute)
.and_return(Vagrant::Util::Subprocess::Result.new(1, "", ""))
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCommandFailed)
end
it "execute ansible-galaxy and ansible-playbook" do
# TODO: to be improved, but I'm currenty facing some issues, maybe only present in RSpec 2.14...
expect(Vagrant::Util::Subprocess).to receive(:execute).twice
it "execute ansible-galaxy, and then ansible-playbook" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |cmd, *args|
expect(cmd).to eq("ansible-galaxy")
}.and_return(default_execute_result)
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |cmd, *args|
expect(cmd).to eq("ansible-playbook")
}.and_return(default_execute_result)
end
describe "with verbose option enabled" do
@ -835,11 +841,11 @@ VF
end
it "sets ANSIBLE_ROLES_PATH with corresponding absolute path" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]).to include("ANSIBLE_ROLES_PATH")
expect(cmd_opts[:env]['ANSIBLE_ROLES_PATH']).to eql(File.join(machine.env.root_path, "my-roles"))
}
}.and_return(default_execute_result)
end
end
@ -906,17 +912,17 @@ VF
})
it "also includes given raw arguments" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args).to include("--why-not")
expect(args).to include("--su-user=foot")
expect(args).to include("--ask-su-pass")
expect(args).to include("--limit=all")
expect(args).to include("--private-key=./myself.key")
}
}.and_return(default_execute_result)
end
it "shows the ansible-playbook command, with additional quotes when required" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command|
expect(full_command).to eq(%Q(PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_ROLES_PATH='/up/to the stars' ANSIBLE_CONFIG='#{existing_file}' ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile=/my/key1 -o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --ask-sudo-pass --ask-vault-pass --limit="machine*:&vagrant:!that_one" --inventory-file=#{generated_inventory_dir} --extra-vars="{\\"var1\\":\\"string with 'apostrophes', \\\\\\\\, \\\\\\" and =\\",\\"var2\\":{\\"x\\":42}}" --sudo --sudo-user=deployer -vvv --vault-password-file=#{existing_file} --tags=db,www --skip-tags=foo,bar --start-at-task="joe's awesome task" --why-not --su-user=foot --ask-su-pass --limit=all --private-key=./myself.key --extra-vars='{\"var3\":\"foo\"}' playbook.yml))
}
end
@ -936,21 +942,21 @@ VF
}}
let(:fake_host_vm) {
double("host_vm").tap do |h|
h.stub(ssh_info: fake_host_ssh_info)
allow(h).to receive(:ssh_info).and_return(fake_host_ssh_info)
end
}
before do
machine.stub(provider_name: :docker)
machine.provider.stub(host_vm?: true)
machine.provider.stub(host_vm: fake_host_vm)
allow(machine).to receive(:provider_name).and_return(:docker)
allow(machine.provider).to receive(:host_vm?).and_return(true)
allow(machine.provider).to receive(:host_vm).and_return(fake_host_vm)
end
it "uses an SSH ProxyCommand to reach the VM" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ProxyCommand='ssh boot9docker@127.0.0.1 -p 2299 -i /path/to/docker/host/key -o Compression=yes -o ConnectTimeout=5 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no exec nc %h %p 2>/dev/null'")
}
}.and_return(default_execute_result)
end
end
@ -960,12 +966,12 @@ VF
context "on a Windows host" do
before do
Vagrant::Util::Platform.stub(windows?: true)
machine.ui.stub(:warn)
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true)
allow(machine.ui).to receive(:warn)
end
it "warns that Windows is not officially supported for the Ansible control machine" do
expect(machine.env.ui).to receive(:warn).with { |warning|
expect(machine.env.ui).to receive(:warn).with(any_args) { |warning|
expect(warning).to eq(I18n.t("vagrant.provisioners.ansible.windows_not_supported_for_control_machine"))
}
end
@ -973,32 +979,24 @@ VF
context "on a Solaris-like host" do
before do
Vagrant::Util::Platform.stub(solaris?: true)
allow(Vagrant::Util::Platform).to receive(:solaris?).and_return(true)
end
it "does not set IdentitiesOnly=yes in ANSIBLE_SSH_ARGS" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes")
# Ending this block with a negative expectation (to_not / not_to)
# would lead to a failure of the above expectation.
true
}
}.and_return(default_execute_result)
end
describe "and with host_key_checking option enabled" do
it "does not set ANSIBLE_SSH_ARGS environment variable" do
config.host_key_checking = true
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]).to_not include('ANSIBLE_SSH_ARGS')
# Ending this block with a negative expectation (to_not / not_to)
# would lead to a failure of the above expectation.
true
}
}.and_return(Vagrant::Util::Subprocess::Result.new(0, "", ""))
end
end
@ -1008,14 +1006,10 @@ VF
it 'does not set IdentitiesOnly=yes in ANSIBLE_SSH_ARGS' do
ssh_info[:keys_only] = false
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes")
# Ending this block with a negative expectation (to_not / not_to)
# would lead to a failure of the above expectation.
true
}
}.and_return(default_execute_result)
end
end
end

View File

@ -20,8 +20,8 @@ describe VagrantPlugins::Chef::CommandBuilder do
describe ".initialize" do
it "raises an error when chef type is not client or solo" do
expect { VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client_bad) }.
to raise_error
expect { VagrantPlugins::Chef::CommandBuilder.new(:client_bad, chef_config) }.
to raise_error(RuntimeError)
end
it "does not raise an error for :client" do

View File

@ -1,6 +1,7 @@
require File.expand_path("../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/provisioners/docker/config")
require Vagrant.source_root.join("plugins/provisioners/docker/provisioner")
require Vagrant.source_root.join("plugins/kernel_v2/config/vm")
describe VagrantPlugins::DockerProvisioner::Config do
@ -142,7 +143,7 @@ describe VagrantPlugins::DockerProvisioner::Config do
describe "#post_install_provision" do
it "raises an error if 'docker' provisioner was provided" do
expect {subject.post_install_provision("myprov", :type=>"docker", :inline=>"echo 'hello'")}
.to raise_error()
.to raise_error(VagrantPlugins::DockerProvisioner::DockerError)
end
it "setups a basic provisioner" do

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

@ -109,6 +109,7 @@ describe VagrantPlugins::FTPPush::SFTPAdapter do
describe "#upload" do
it "uploads the file" do
pending "a way to mock an SFTP server"
test_with_mock_sftp_server
end
end
end

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

@ -10,7 +10,7 @@ describe VagrantPlugins::SyncedFolderNFS::Config do
subject.finalize!
end
its(:functional) { should be_true }
its(:functional) { should be(true) }
its(:map_gid) { should eq(:auto) }
its(:map_uid) { should eq(:auto) }
end

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,25 +74,25 @@ 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 { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[args.length - 3]).to eql("foo/")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
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)
@ -103,11 +103,11 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
opts[:hostpath] = "/foo"
opts[:guestpath] = "/bar"
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s
expect(args[args.length - 3]).to eql("#{expected}/")
expect(args[args.length - 2]).to include("/bar")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -118,22 +118,22 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
hostpath_expanded = File.expand_path(opts[:hostpath], machine.env.root_path)
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[args.length - 3]).to eql("#{hostpath_expanded}/")
expect(args[args.length - 2]).to include("/bar")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
end
it "executes within the root path" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args.last).to be_kind_of(Hash)
opts = args.last
expect(opts[:workdir]).to eql(machine.env.root_path.to_s)
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -158,11 +158,11 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
it "excludes files if given as a string" do
opts[:exclude] = "foo"
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
index = args.find_index("foo")
expect(index).to be > 0
expect(args[index-1]).to eql("--exclude")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -170,7 +170,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
it "excludes multiple files" do
opts[:exclude] = ["foo", "bar"]
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
index = args.find_index("foo")
expect(index).to be > 0
expect(args[index-1]).to eql("--exclude")
@ -178,7 +178,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
index = args.find_index("bar")
expect(index).to be > 0
expect(args[index-1]).to eql("--exclude")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -186,14 +186,14 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
context "custom arguments" do
it "uses the default arguments if not given" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[1]).to eq("--verbose")
expect(args[2]).to eq("--archive")
expect(args[3]).to eq("--delete")
expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s
expect(args[args.length - 3]).to eql("#{expected}/")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -201,13 +201,13 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
it "uses the custom arguments if given" do
opts[:args] = ["--verbose", "-z"]
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[1]).to eq("--verbose")
expect(args[2]).to eq("-z")
expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s
expect(args[args.length - 3]).to eql("#{expected}/")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -228,19 +228,19 @@ 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
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[9]).to include('IdentitiesOnly')
expect(args[9]).to include('StrictHostKeyChecking')
expect(args[9]).to include('UserKnownHostsFile')
expect(args[9]).to include("-i '/path/to/key'")
}
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
@ -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,19 +19,19 @@ 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
it "is usable if rsync can be found" do
expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(true)
expect(subject.usable?(machine)).to be_true
expect(subject.usable?(machine)).to be(true)
end
it "is not usable if rsync cant be found" do
expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(false)
expect(subject.usable?(machine)).to be_false
expect(subject.usable?(machine)).to be(false)
end
it "raises an exception if asked to" 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
@ -91,7 +91,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_name] = "foo"
env[:box_url] = box_path.to_s
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0")
@ -113,7 +113,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
box_path.to_s,
]
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0")
@ -132,7 +132,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_name] = "foo"
env[:box_url] = "http://127.0.0.1:#{port}/#{box_path.basename}"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0")
@ -152,7 +152,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_name] = "foo"
env[:box_url] = "ftp://127.0.0.1:#{port}/#{box_path.basename}"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0")
@ -267,8 +267,8 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = box_path.to_s
env[:box_provider] = "virtualbox"
box_collection.stub(find: box)
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0")
@ -288,7 +288,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
box_url_name = "http://127.0.0.1:#{port}/#{box_path.basename}"
env[:box_name] = box_url_name
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq(box_url_name)
expect(version).to eq("0")
expect(opts[:metadata_url]).to be_nil
@ -313,7 +313,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
box_url_name = "box name with spaces"
env[:box_name] = box_url_name
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq(box_url_name)
expect(version).to eq("0")
expect(opts[:metadata_url]).to be_nil
@ -337,7 +337,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_name] = "foo"
env[:box_url] = "http://#{username}:#{password}@127.0.0.1:#{port}/#{box_path.basename}"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0")
@ -385,7 +385,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
with_web_server(md_path) do |port|
env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
@ -430,7 +430,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
with_web_server(md_path, **opts) do |port|
env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
@ -475,7 +475,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
url = "http://127.0.0.1:#{port}"
env[:box_url] = "mitchellh/precise64.json"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq("mitchellh/precise64")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
@ -526,7 +526,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = "mitchellh/precise64.json"
env[:box_server_url] = url
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq("mitchellh/precise64")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
@ -587,7 +587,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
end
end
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
@ -632,7 +632,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
with_web_server(md_path) do |port|
env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
@ -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)
@ -776,7 +776,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
end
env[:box_url] = tf.path
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.7")
@ -820,7 +820,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = tf.path
env[:box_provider] = "vmware"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.7")
@ -869,7 +869,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = tf.path
env[:box_provider] = "vmware"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.7")
@ -909,7 +909,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = tf.path
env[:box_version] = "~> 0.1"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.5")
@ -954,7 +954,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = tf.path
env[:box_provider] = "vmware"
env[:box_version] = "~> 0.1"
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.5")
@ -1002,7 +1002,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_url] = tf.path
env[:box_provider] = ["virtualbox", "vmware"]
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.7")
@ -1050,7 +1050,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
expect(env[:ui]).to receive(:ask).and_return("1")
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.7")
@ -1225,12 +1225,12 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
env[:box_force] = true
env[:box_url] = tf.path
box_collection.stub(find: box)
expect(box_collection).to receive(:add).with { |path, name, version, **opts|
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")
expect(version).to eq("0.7")
expect(opts[:force]).to be_true
expect(opts[:force]).to be(true)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
}.and_return(box)

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
@ -93,7 +93,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
subject.call(env)
expect(env[:box_outdated]).to be_false
expect(env[:box_outdated]).to be(false)
end
it "sets env if there is an update" do
@ -126,7 +126,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
subject.call(env)
expect(env[:box_outdated]).to be_true
expect(env[:box_outdated]).to be(true)
end
it "has an update if it is local" do
@ -138,7 +138,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
subject.call(env)
expect(env[:box_outdated]).to be_true
expect(env[:box_outdated]).to be(true)
end
it "does not have a local update if not within constraints" do
@ -152,7 +152,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
subject.call(env)
expect(env[:box_outdated]).to be_false
expect(env[:box_outdated]).to be(false)
end
it "does nothing if metadata download fails" do
@ -163,7 +163,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
subject.call(env)
expect(env[:box_outdated]).to be_false
expect(env[:box_outdated]).to be(false)
end
it "raises error if has_update? errors" do

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

@ -47,7 +47,7 @@ describe Vagrant::Action::Builtin::Confirm do
end
end
described_class.new(app, env, message, allowed: ["y", "N"]).call(env)
expect(env[:result]).to be_true
expect(env[:result]).to be(true)
expect(times).to eq(4)
end
end

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,13 +48,13 @@ 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
it "adds a box that doesn't exist" do
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq(machine.config.vm.box)
expect(opts[:box_url]).to eq(machine.config.vm.box)
expect(opts[:box_provider]).to eq(:dummy)
@ -70,7 +70,7 @@ describe Vagrant::Action::Builtin::HandleBox do
it "adds a box using any format the provider allows" do
machine.provider_options[:box_format] = [:foo, :bar]
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq(machine.config.vm.box)
expect(opts[:box_url]).to eq(machine.config.vm.box)
expect(opts[:box_provider]).to eq([:foo, :bar])
@ -86,14 +86,14 @@ 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"
end
it "adds a box that doesn't exist" do
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq(machine.config.vm.box)
expect(opts[:box_url]).to eq(machine.config.vm.box_url)
expect(opts[:box_provider]).to eq(:dummy)
@ -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"
@ -118,7 +118,7 @@ describe Vagrant::Action::Builtin::HandleBox do
end
it "adds a box that doesn't exist and maps checksum options correctly" do
expect(action_runner).to receive(:run).with { |action, opts|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
expect(opts[:box_name]).to eq(machine.config.vm.box)
expect(opts[:box_url]).to eq(machine.config.vm.box_url)
expect(opts[:box_provider]).to eq(:dummy)

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::IsEnvSet do
expect(app).to receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_true
expect(env[:result]).to be(true)
end
it "sets result to false if it isn't set" do
@ -25,7 +25,7 @@ describe Vagrant::Action::Builtin::IsEnvSet do
expect(app).to receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_false
expect(env[:result]).to be(false)
end
end
end

View File

@ -16,36 +16,36 @@ 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)
expect(app).to receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_false
expect(env[:result]).to be(false)
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)
expect(app).to receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_true
expect(env[:result]).to be(true)
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)
expect(app).to receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_false
expect(env[:result]).to be(false)
end
end
end

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)
@ -147,7 +147,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
folders["root"] = { type: "unusable" }
expect { subject.synced_folders(machine) }.
to raise_error
to raise_error(RuntimeError)
end
it "should ignore disabled folders" do
@ -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
@ -131,9 +131,9 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do
subject.call(env)
expect(trackers[0].clean).to be_true
expect(trackers[1].clean).to be_true
expect(trackers[2].clean).to be_true
expect(trackers[0].clean).to be(true)
expect(trackers[1].clean).to be(true)
expect(trackers[2].clean).to be(true)
end
end
end

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

@ -223,7 +223,7 @@ describe Vagrant::BoxCollection, :skip_windows do
environment.box3("foo", "0", :virtualbox,
metadata_url: "foourl")
expect(hook).to receive(:call).with { |name, env|
expect(hook).to receive(:call).with(any_args) { |name, env|
expect(name).to eq(:authenticate_box_url)
expect(env[:box_urls]).to eq(["foourl"])
true

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 }.
@ -308,7 +308,7 @@ describe Vagrant::Box, :skip_windows do
end
# Repackage our box to some temporary directory
expect(subject.repackage(box_output_path)).to be_true
expect(subject.repackage(box_output_path)).to be(true)
# Let's now add this box again under a different name, and then
# verify that we get the proper result back.

View File

@ -104,15 +104,15 @@ describe Vagrant::CapabilityHost do
end
it "does not have a non-existent capability" do
expect(subject.capability?(:foo)).to be_false
expect(subject.capability?(:foo)).to be(false)
end
it "has capabilities of itself" do
expect(subject.capability?(:self)).to be_true
expect(subject.capability?(:self)).to be(true)
end
it "has capabilities of parent" do
expect(subject.capability?(:parent)).to be_true
expect(subject.capability?(:parent)).to be(true)
end
end

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
@ -45,10 +45,10 @@ describe Vagrant::CLI do
commands[:bar] = [command_lambda("bar", 0), { primary: true }]
commands[:baz] = [command_lambda("baz", 0), { primary: false }]
expect(env.ui).to receive(:info).with { |message, opts|
expect(env.ui).to receive(:info).with(any_args) { |message, opts|
expect(message).to include("foo")
expect(message).to include("bar")
expect(message.include?("baz")).to be_false
expect(message.include?("baz")).to be(false)
}
subject.help

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
@ -48,8 +48,8 @@ describe Vagrant::Environment do
it "should return whether it can install or not" do
plugin_host_caps[:foo] = { provider_install_foo: Class }
expect(subject.can_install_provider?(:foo)).to be_true
expect(subject.can_install_provider?(:bar)).to be_false
expect(subject.can_install_provider?(:foo)).to be(true)
expect(subject.can_install_provider?(:bar)).to be(false)
end
end
@ -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
@ -202,7 +203,7 @@ describe Vagrant::Environment do
plugin_host_caps[:foo] = { bar: Class }
result = subject.host
expect(result.capability?(:bar)).to be_true
expect(result.capability?(:bar)).to be(true)
end
it "should attempt to detect a host if host is :detect" do
@ -216,7 +217,7 @@ describe Vagrant::Environment do
plugin_host_caps[:foo] = { bar: Class }
result = subject.host
expect(result.capability?(:bar)).to be_true
expect(result.capability?(:bar)).to be(true)
end
it "should use an exact host if specified" do
@ -231,7 +232,7 @@ describe Vagrant::Environment do
plugin_host_caps[:foo] = { bar: Class }
result = subject.host
expect(result.capability?(:bar)).to be_true
expect(result.capability?(:bar)).to be(true)
end
it "should raise an error if an exact match was specified but not found" do
@ -270,7 +271,7 @@ describe Vagrant::Environment do
end
end
expect(raised).to be_true
expect(raised).to be(true)
end
it "allows nested locks on the same environment" do
@ -282,7 +283,7 @@ describe Vagrant::Environment do
end
end
expect(success).to be_true
expect(success).to be(true)
end
it "cleans up all lock files" do
@ -641,8 +642,8 @@ VF
klass = double("machine_index")
stub_const("Vagrant::MachineIndex", klass)
klass.should_receive(:new).with do |path|
expect(path.to_s.start_with?(subject.home_path.to_s)).to be_true
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
@ -985,7 +986,7 @@ VF
Dir.chdir(temp_dir) do
instance = described_class.new(local_data_path: "foo")
expect(instance.local_data_path).to eq(instance.cwd.join("foo"))
expect(File.exist?(instance.local_data_path)).to be_false
expect(File.exist?(instance.local_data_path)).to be(false)
end
end
end
@ -1249,7 +1250,7 @@ VF
env = environment.create_vagrant_env
env.push("foo")
expect(push_class.pushed?).to be_true
expect(push_class.pushed?).to be(true)
end
end
@ -1257,7 +1258,7 @@ VF
it "should call the action runner with the proper hook" do
hook_name = :foo
expect(instance.action_runner).to receive(:run).with { |callable, env|
expect(instance.action_runner).to receive(:run).with(any_args) { |callable, env|
expect(env[:action_name]).to eq(hook_name)
}
@ -1279,7 +1280,7 @@ VF
end
it "should allow passing in custom data" do
expect(instance.action_runner).to receive(:run).with { |callable, env|
expect(instance.action_runner).to receive(:run).with(any_args) { |callable, env|
expect(env[:foo]).to eq(:bar)
}
@ -1287,7 +1288,7 @@ VF
end
it "should allow passing a custom callable" do
expect(instance.action_runner).to receive(:run).with { |callable, env|
expect(instance.action_runner).to receive(:run).with(any_args) { |callable, env|
expect(callable).to eq(:what)
}

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

@ -136,7 +136,7 @@ describe Vagrant::MachineIndex do
end
it "should include? by prefix" do
expect(subject.include?("b")).to be_true
expect(subject.include?("b")).to be(true)
end
it "locks the entry so subsequent gets fail" do
@ -159,7 +159,7 @@ describe Vagrant::MachineIndex do
describe "#include" do
it "should not include non-existent things" do
expect(subject.include?("foo")).to be_false
expect(subject.include?("foo")).to be(false)
end
it "should include created entries" do
@ -168,7 +168,7 @@ describe Vagrant::MachineIndex do
subject.release(result)
subject = described_class.new(data_dir)
expect(subject.include?(result.id)).to be_true
expect(subject.include?(result.id)).to be(true)
end
end
@ -204,7 +204,7 @@ describe Vagrant::MachineIndex do
it "can delete an entry that doesn't exist" do
e = entry_klass.new
expect(subject.delete(e)).to be_true
expect(subject.delete(e)).to be(true)
end
it "updates an existing entry" do

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
@ -81,7 +81,7 @@ describe Vagrant::Machine do
it "should not insert key" do
subject = new_instance
expect(subject.config.ssh.insert_key).to be_false
expect(subject.config.ssh.insert_key).to be(false)
end
end
@ -197,7 +197,7 @@ describe Vagrant::Machine do
it "should initialize the capabilities" do
instance = new_provider_mock
expect(instance).to receive(:_initialize).with { |p, m|
expect(instance).to receive(:_initialize).with(any_args) { |p, m|
expect(p).to eq(provider_name)
expect(m.name).to eq(name)
true
@ -383,7 +383,7 @@ describe Vagrant::Machine do
it "should run the callable with the proper env" do
subject.action_raw(:foo, callable)
expect(@env[:called]).to be_true
expect(@env[:called]).to be(true)
expect(@env[:action_name]).to eq(:machine_action_foo)
expect(@env[:machine]).to equal(subject)
expect(@env[:machine_action]).to eq(:foo)
@ -398,7 +398,7 @@ describe Vagrant::Machine do
it "should merge in any extra env" do
subject.action_raw(:bar, callable, foo: :bar)
expect(@env[:called]).to be_true
expect(@env[:called]).to be(true)
expect(@env[:foo]).to eq(:bar)
end
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"
@ -788,18 +788,18 @@ describe Vagrant::Machine do
context "with custom ssh_info" do
it "keys_only should be default" do
expect(instance.ssh_info[:keys_only]).to be_true
expect(instance.ssh_info[:keys_only]).to be(true)
end
it "paranoid should be default" do
expect(instance.ssh_info[:paranoid]).to be_false
expect(instance.ssh_info[:paranoid]).to be(false)
end
it "keys_only should be overridden" do
instance.config.ssh.keys_only = false
expect(instance.ssh_info[:keys_only]).to be_false
expect(instance.ssh_info[:keys_only]).to be(false)
end
it "paranoid should be overridden" do
instance.config.ssh.paranoid = true
expect(instance.ssh_info[:paranoid]).to be_true
expect(instance.ssh_info[:paranoid]).to be(true)
end
end
end

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) }
@ -30,9 +30,9 @@ describe Vagrant::Plugin::Manager do
it "installs the plugin and adds it to the state file" do
specs = Array.new(5) { Gem::Specification.new }
specs[3].name = "foo"
expect(bundler).to receive(:install).once.with { |plugins, local|
expect(bundler).to receive(:install).once.with(any_args) { |plugins, local|
expect(plugins).to have_key("foo")
expect(local).to be_false
expect(local).to be(false)
}.and_return(specs)
expect(bundler).to receive(:clean)
@ -92,10 +92,10 @@ describe Vagrant::Plugin::Manager do
end
it "installs a version with constraints" do
expect(bundler).to receive(:install).once.with { |plugins, local|
expect(bundler).to receive(:install).once.with(any_args) { |plugins, local|
expect(plugins).to have_key("foo")
expect(plugins["foo"]["gem_version"]).to eql(">= 0.1.0")
expect(local).to be_false
expect(local).to be(false)
}.and_return(specs)
expect(bundler).to receive(:clean)
@ -107,10 +107,10 @@ describe Vagrant::Plugin::Manager do
end
it "installs with an exact version but doesn't constrain" do
expect(bundler).to receive(:install).once.with { |plugins, local|
expect(bundler).to receive(:install).once.with(any_args) { |plugins, local|
expect(plugins).to have_key("foo")
expect(plugins["foo"]["gem_version"]).to eql("0.1.0")
expect(local).to be_false
expect(local).to be(false)
}.and_return(specs)
expect(bundler).to receive(:clean)
@ -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")
@ -170,7 +170,7 @@ describe Vagrant::Plugin::Manager do
subject.uninstall_plugin("bar")
plugins = subject.installed_plugins
expect(plugins["foo"]["system"]).to be_true
expect(plugins["foo"]["system"]).to be(true)
end
it "raises an error if uninstalling a system gem" do
@ -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")
@ -243,9 +243,9 @@ describe Vagrant::Plugin::Manager do
expect(plugins.length).to eql(2)
expect(plugins).to have_key("foo")
expect(plugins["foo"]["gem_version"]).to eq("0.1.0")
expect(plugins["foo"]["system"]).to be_true
expect(plugins["foo"]["system"]).to be_truthy
expect(plugins).to have_key("bar")
expect(plugins["bar"]["system"]).to be_true
expect(plugins["bar"]["system"]).to be(true)
end
end
end

View File

@ -36,9 +36,9 @@ describe Vagrant::Plugin::StateFile do
end
it "should check for plugins" do
expect(subject.has_plugin?("foo")).to be_false
expect(subject.has_plugin?("foo")).to be(false)
subject.add_plugin("foo")
expect(subject.has_plugin?("foo")).to be_true
expect(subject.has_plugin?("foo")).to be(true)
end
it "should remove plugins" do

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
@ -71,8 +72,8 @@ describe Vagrant::Plugin::V2::Plugin do
command("bar", primary: false) { "bar" }
end
expect(plugin.components.commands[:foo][1][:primary]).to be_true
expect(plugin.components.commands[:bar][1][:primary]).to be_false
expect(plugin.components.commands[:foo][1][:primary]).to be(true)
expect(plugin.components.commands[:bar][1][:primary]).to be(false)
end
["spaces bad", "sym^bols"].each do |bad|

View File

@ -42,14 +42,14 @@ 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
it "can execute capabilities" do
expect(subject.capability?(:foo)).to be_false
expect(subject.capability?(:bar)).to be_true
expect(subject.capability?(:foo)).to be(false)
expect(subject.capability?(:bar)).to be(true)
expect { subject.capability(:bar) }.
to raise_error("bar YEAH")

View File

@ -18,25 +18,25 @@ describe Vagrant do
describe "#in_installer?" do
it "is not if env is not set" do
with_temp_env("VAGRANT_INSTALLER_ENV" => nil) do
expect(subject.in_installer?).to be_false
expect(subject.in_installer?).to be(false)
end
end
it "is if env is set" do
with_temp_env("VAGRANT_INSTALLER_ENV" => "/foo") do
expect(subject.in_installer?).to be_true
expect(subject.in_installer?).to be(true)
end
end
end
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")
@ -47,13 +47,13 @@ describe Vagrant do
describe "#plugins_enabled?" do
it "returns true if the env is not set" do
with_temp_env("VAGRANT_NO_PLUGINS" => nil) do
expect(subject.plugins_enabled?).to be_true
expect(subject.plugins_enabled?).to be(true)
end
end
it "returns false if the env is set" do
with_temp_env("VAGRANT_NO_PLUGINS" => "1") do
expect(subject.plugins_enabled?).to be_false
expect(subject.plugins_enabled?).to be(false)
end
end
end

View File

@ -5,7 +5,7 @@ describe Vagrant::UI::Basic do
it "outputs within the a new thread" do
current = Thread.current.object_id
expect(subject).to receive(:safe_puts).with { |*args|
expect(subject).to receive(:safe_puts).with(any_args) { |*args|
expect(Thread.current.object_id).to_not eq(current)
true
}
@ -14,7 +14,7 @@ describe Vagrant::UI::Basic do
end
it "outputs using `puts` by default" do
expect(subject).to receive(:safe_puts).with { |message, **opts|
expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts|
expect(opts[:printer]).to eq(:puts)
true
}
@ -23,7 +23,7 @@ describe Vagrant::UI::Basic do
end
it "outputs using `print` if new_line is false" do
expect(subject).to receive(:safe_puts).with { |message, **opts|
expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts|
expect(opts[:printer]).to eq(:print)
true
}
@ -32,7 +32,7 @@ describe Vagrant::UI::Basic do
end
it "outputs using `print` if new_line is false" do
expect(subject).to receive(:safe_puts).with { |message, **opts|
expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts|
expect(opts[:printer]).to eq(:print)
true
}
@ -44,7 +44,7 @@ describe Vagrant::UI::Basic do
stdout = StringIO.new
subject.stdout = stdout
expect(subject).to receive(:safe_puts).with { |message, **opts|
expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts|
expect(opts[:io]).to be(stdout)
true
}
@ -60,7 +60,7 @@ describe Vagrant::UI::Basic do
stderr = StringIO.new
subject.stderr = stderr
expect(subject).to receive(:safe_puts).with { |message, **opts|
expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts|
expect(opts[:io]).to be(stderr)
true
}
@ -81,7 +81,7 @@ describe Vagrant::UI::Basic do
context "#detail" do
it "outputs details" do
expect(subject).to receive(:safe_puts).with { |message, **opts|
expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts|
expect(message).to eq("foo")
true
}
@ -114,7 +114,7 @@ describe Vagrant::UI::Colored do
end
it "does not bold by default with a color" do
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[0;31m")
expect(message).to end_with("\033[0m")
}
@ -125,7 +125,7 @@ describe Vagrant::UI::Colored do
describe "#error" do
it "colors red" do
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[0;31m")
expect(message).to end_with("\033[0m")
}
@ -153,7 +153,7 @@ describe Vagrant::UI::Colored do
it "colors output to color specified in global opts" do
subject.opts[:color] = :red
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[0;31m")
expect(message).to end_with("\033[0m")
}
@ -164,7 +164,7 @@ describe Vagrant::UI::Colored do
it "colors output to specified color over global opts" do
subject.opts[:color] = :red
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[0;32m")
expect(message).to end_with("\033[0m")
}
@ -175,7 +175,7 @@ describe Vagrant::UI::Colored do
it "bolds the output if specified" do
subject.opts[:color] = :red
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[1;31m")
expect(message).to end_with("\033[0m")
}
@ -186,7 +186,7 @@ describe Vagrant::UI::Colored do
describe "#success" do
it "colors green" do
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[0;32m")
expect(message).to end_with("\033[0m")
}
@ -197,7 +197,7 @@ describe Vagrant::UI::Colored do
describe "#warn" do
it "colors yellow" do
expect(subject).to receive(:safe_puts).with { |message, *args|
expect(subject).to receive(:safe_puts).with(any_args) { |message, *args|
expect(message).to start_with("\033[0;33m")
expect(message).to end_with("\033[0m")
}
@ -218,7 +218,7 @@ describe Vagrant::UI::MachineReadable do
[:detail, :warn, :error, :info, :output, :success].each do |method|
describe "##{method}" do
it "outputs UI type to the machine-readable output" do
expect(subject).to receive(:safe_puts).with { |message|
expect(subject).to receive(:safe_puts).with(any_args) { |message|
parts = message.split(",")
expect(parts.length).to eq(5)
expect(parts[1]).to eq("")
@ -235,7 +235,7 @@ describe Vagrant::UI::MachineReadable do
describe "#machine" do
it "is formatted properly" do
expect(subject).to receive(:safe_puts).with { |message|
expect(subject).to receive(:safe_puts).with(any_args) { |message|
parts = message.split(",")
expect(parts.length).to eq(5)
expect(parts[1]).to eq("")
@ -249,7 +249,7 @@ describe Vagrant::UI::MachineReadable do
end
it "includes a target if given" do
expect(subject).to receive(:safe_puts).with { |message|
expect(subject).to receive(:safe_puts).with(any_args) { |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[1]).to eq("boom")
@ -262,7 +262,7 @@ describe Vagrant::UI::MachineReadable do
end
it "replaces commas" do
expect(subject).to receive(:safe_puts).with { |message|
expect(subject).to receive(:safe_puts).with(any_args) { |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[3]).to eq("foo%!(VAGRANT_COMMA)bar")
@ -273,7 +273,7 @@ describe Vagrant::UI::MachineReadable do
end
it "replaces newlines" do
expect(subject).to receive(:safe_puts).with { |message|
expect(subject).to receive(:safe_puts).with(any_args) { |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[3]).to eq("foo\\nbar\\r")
@ -286,7 +286,7 @@ describe Vagrant::UI::MachineReadable do
# This is for a bug where JSON parses are frozen and an
# exception was being raised.
it "works properly with frozen string arguments" do
expect(subject).to receive(:safe_puts).with { |message|
expect(subject).to receive(:safe_puts).with(any_args) { |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[3]).to eq("foo\\nbar\\r")
@ -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
@ -69,7 +69,7 @@ describe Vagrant::Util::Downloader do
with("curl", *curl_options).
and_return(subprocess_result)
expect(subject.download!).to be_true
expect(subject.download!).to be(true)
end
end
@ -90,7 +90,7 @@ describe Vagrant::Util::Downloader do
with("curl", *curl_options).
and_return(subprocess_result)
expect(subject.download!).to be_true
expect(subject.download!).to be(true)
end
end
@ -116,7 +116,7 @@ describe Vagrant::Util::Downloader do
end
it "should not raise an exception" do
expect(subject.download!).to be_true
expect(subject.download!).to be(true)
end
end
@ -144,7 +144,7 @@ describe Vagrant::Util::Downloader do
end
it "should not raise an exception" do
expect(subject.download!).to be_true
expect(subject.download!).to be(true)
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

@ -52,14 +52,14 @@ describe Vagrant::Util::Subprocess do
context "when subprocess has not been started" do
it "should return false" do
sp = described_class.new("ls")
expect(sp.running?).to be_false
expect(sp.running?).to be(false)
end
end
context "when subprocess has completed" do
it "should return false" do
sp = described_class.new("ls")
sp.execute
expect(sp.running?).to be_false
expect(sp.running?).to be(false)
end
end
context "when subprocess is running" do
@ -67,7 +67,7 @@ describe Vagrant::Util::Subprocess do
sp = described_class.new("sleep", "5")
thread = Thread.new{ sp.execute }
sleep(0.3)
expect(sp.running?).to be_true
expect(sp.running?).to be(true)
sp.stop
thread.join
end
@ -78,7 +78,7 @@ describe Vagrant::Util::Subprocess do
context "when subprocess has not been started" do
it "should return false" do
sp = described_class.new("ls")
expect(sp.stop).to be_false
expect(sp.stop).to be(false)
end
end
@ -86,7 +86,7 @@ describe Vagrant::Util::Subprocess do
it "should return false" do
sp = described_class.new("ls")
sp.execute
expect(sp.stop).to be_false
expect(sp.stop).to be(false)
end
end
@ -95,7 +95,7 @@ describe Vagrant::Util::Subprocess do
it "should return true" do
thread = Thread.new{ sp.execute }
sleep(0.1)
expect(sp.stop).to be_true
expect(sp.stop).to be(true)
thread.join
end
@ -103,7 +103,7 @@ describe Vagrant::Util::Subprocess do
thread = Thread.new{ sp.execute }
sleep(0.1)
sp.stop
expect(sp.running?).to be_false
expect(sp.running?).to be(false)
thread.join
end
end

View File

@ -59,31 +59,31 @@ describe Vagrant do
name "i_am_installed"
end
expect(described_class.has_plugin?("i_am_installed")).to be_true
expect(described_class.has_plugin?("i_am_installed")).to be(true)
end
it "should return false if the plugin is not installed" do
expect(described_class.has_plugin?("i_dont_exist")).to be_false
expect(described_class.has_plugin?("i_dont_exist")).to be(false)
end
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
expect(described_class.has_plugin?("foo")).to be(true)
expect(described_class.has_plugin?("bar")).to be(false)
end
it "finds plugins by gem name and version" 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
expect(described_class.has_plugin?("bar", "~> 1.2.0")).to be_false
expect(described_class.has_plugin?("foo", "~> 1.2.0")).to be(true)
expect(described_class.has_plugin?("foo", "~> 1.0.0")).to be(false)
expect(described_class.has_plugin?("bar", "~> 1.2.0")).to be(false)
end
end

Some files were not shown because too many files have changed in this diff Show More