Update tests to use real UI instance

Replaces use of UI doubles within tests to use actual UI instance
    to ensure calls are passing parameters correctly.
This commit is contained in:
Chris Roberts 2021-06-23 14:04:48 -07:00
parent 31957a9d71
commit 3d0d0148e9
55 changed files with 119 additions and 219 deletions

View File

@ -271,7 +271,7 @@ module Vagrant
options[:color] = :red if !config.keep_color options[:color] = :red if !config.keep_color
end end
@ui.detail(data, options) @ui.detail(data, **options)
end end
if !exit_codes.include?(result.exit_code) if !exit_codes.include?(result.exit_code)
raise Errors::TriggersBadExitCodes, raise Errors::TriggersBadExitCodes,

View File

@ -171,8 +171,8 @@ module VagrantPlugins
raise Errors::NetworkNoInterfaces raise Errors::NetworkNoInterfaces
elsif valid_interfaces.size == 1 elsif valid_interfaces.size == 1
bridge_interface = valid_interfaces.first bridge_interface = valid_interfaces.first
elsif i = valid_interfaces.detect{|i| Array(root_options[:bridge]).include?(i.name) } elsif idx = valid_interfaces.detect{|i| Array(root_options[:bridge]).include?(i.name) }
bridge_interface = i bridge_interface = idx
end end
if !bridge_interface if !bridge_interface
env[:ui].info(I18n.t("vagrant.actions.vm.bridged_networking.available"), env[:ui].info(I18n.t("vagrant.actions.vm.bridged_networking.available"),

View File

@ -10,7 +10,7 @@ module VagrantPlugins
# Build an image given a path to a Dockerfile # Build an image given a path to a Dockerfile
# #
# @param [String] - Path to the Dockerfile to pass to # @param [Array<Array<String, Hash>>] - Path and options to the Dockerfile to pass to
# container build command # container build command
def build_images(images) def build_images(images)
@machine.communicate.tap do |comm| @machine.communicate.tap do |comm|
@ -195,7 +195,7 @@ module VagrantPlugins
options = {} options = {}
#options[:color] = color if !config.keep_color #options[:color] = color if !config.keep_color
@machine.ui.info(data.chomp, options) @machine.ui.info(data.chomp, **options)
end end
end end
end end

View File

@ -67,16 +67,12 @@ describe VagrantPlugins::CommandBox::Command::Prune do
iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1)) iso_vagrant_env.machine_index.set(new_entry("foo", "foobox", "virtualbox", 1))
output = "" allow(iso_vagrant_env.ui).to receive(:info).and_call_original
allow(iso_vagrant_env.ui).to receive(:info) do |data| expect(iso_vagrant_env.ui).to receive(:info).with(/No old versions of boxes/).
output << data and_call_original
end
expect(iso_vagrant_env.boxes.all.count).to eq(2) expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(subject.execute).to eq(0) expect(subject.execute).to eq(0)
expect(iso_vagrant_env.boxes.all.count).to eq(2) expect(iso_vagrant_env.boxes.all.count).to eq(2)
expect(output).to include("No old versions of boxes to remove...")
end end
end end

View File

@ -21,7 +21,6 @@ describe VagrantPlugins::CloudCommand::AddAuthentication do
before do before do
allow(Vagrant).to receive(:server_url).and_return(server_url) allow(Vagrant).to receive(:server_url).and_return(server_url)
allow(ui).to receive(:warn)
allow(VagrantPlugins::CloudCommand::Client).to receive(:new). allow(VagrantPlugins::CloudCommand::Client).to receive(:new).
with(iso_env).and_return(client) with(iso_env).and_return(client)
stub_env("ATLAS_TOKEN" => nil) stub_env("ATLAS_TOKEN" => nil)
@ -123,7 +122,7 @@ describe VagrantPlugins::CloudCommand::AddAuthentication do
expected[3] = expected[3] + "?access_token=#{token}" expected[3] = expected[3] + "?access_token=#{token}"
expect(subject).to receive(:sleep).once expect(subject).to receive(:sleep).once
expect(ui).to receive(:warn).once expect(ui).to receive(:warn).once.and_call_original
env[:box_urls] = original.dup env[:box_urls] = original.dup
subject.call(env) subject.call(env)

View File

@ -21,7 +21,6 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
before do before do
allow(Vagrant).to receive(:server_url).and_return(server_url) allow(Vagrant).to receive(:server_url).and_return(server_url)
allow(ui).to receive(:warn)
stub_env("ATLAS_TOKEN" => nil) stub_env("ATLAS_TOKEN" => nil)
stub_env("VAGRANT_SERVER_ACCESS_TOKEN_BY_URL" => nil) stub_env("VAGRANT_SERVER_ACCESS_TOKEN_BY_URL" => nil)
end end
@ -59,7 +58,7 @@ describe VagrantPlugins::CloudCommand::AddDownloaderAuthentication do
VagrantPlugins::CloudCommand::Client.new(iso_env).store_token(token) VagrantPlugins::CloudCommand::Client.new(iso_env).store_token(token)
expect(subject).to receive(:sleep).once expect(subject).to receive(:sleep).once
expect(ui).to receive(:warn).once expect(ui).to receive(:warn).once.and_call_original
env[:downloader] = dwnloader env[:downloader] = dwnloader
subject.call(env) subject.call(env)

View File

@ -19,10 +19,6 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Create do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -19,10 +19,6 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Delete do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -19,11 +19,6 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Show do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(ui).to receive(:output)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -18,10 +18,6 @@ describe VagrantPlugins::CloudCommand::BoxCommand::Command::Update do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -23,10 +23,6 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Create do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -22,10 +22,6 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Delete do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -23,10 +23,6 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Update do
let(:ui) { Vagrant::UI::Silent.new } let(:ui) { Vagrant::UI::Silent.new }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -26,11 +26,6 @@ describe VagrantPlugins::CloudCommand::ProviderCommand::Command::Upload do
let(:uploader) { double("uploader") } let(:uploader) { double("uploader") }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:output)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(I18n).to receive(:t) allow(I18n).to receive(:t)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).

View File

@ -21,10 +21,6 @@ describe VagrantPlugins::CloudCommand::Command::Publish do
subject { described_class.new(argv, iso_env) } subject { described_class.new(argv, iso_env) }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(iso_env).to receive(:ui).and_return(ui) allow(iso_env).to receive(:ui).and_return(ui)
allow(File).to receive(:stat).with(box). allow(File).to receive(:stat).with(box).
and_return(double("box_stat", size: box_size)) and_return(double("box_stat", size: box_size))

View File

@ -20,10 +20,6 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Create do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -20,10 +20,6 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Delete do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -20,10 +20,6 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Release do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -20,10 +20,6 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Revoke do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -20,10 +20,6 @@ describe VagrantPlugins::CloudCommand::VersionCommand::Command::Update do
let(:argv) { [] } let(:argv) { [] }
before do before do
allow(ui).to receive(:info)
allow(ui).to receive(:warn)
allow(ui).to receive(:success)
allow(ui).to receive(:error)
allow(env).to receive(:ui).and_return(ui) allow(env).to receive(:ui).and_return(ui)
allow(VagrantCloud::Account).to receive(:new). allow(VagrantCloud::Account).to receive(:new).
with(custom_server: anything, access_token: access_token). with(custom_server: anything, access_token: access_token).

View File

@ -54,18 +54,16 @@ describe VagrantPlugins::CommandPort::Command do
it "ensures the vm is running" do it "ensures the vm is running" do
allow(state).to receive(:id).and_return(:stopped) allow(state).to receive(:id).and_return(:stopped)
expect(env.ui).to receive(:error).with(any_args) { |message, _| expect(env.ui).to receive(:error).with(/does not support listing forwarded ports/).
expect(message).to include("does not support listing forwarded ports") and_call_original
}
expect(subject.execute).to eq(1) expect(subject.execute).to eq(1)
end end
it "shows a friendly error when the capability is not supported" do it "shows a friendly error when the capability is not supported" do
allow(machine.provider).to receive(:capability?).and_return(false) allow(machine.provider).to receive(:capability?).and_return(false)
expect(env.ui).to receive(:error).with(any_args) { |message, _| expect(env.ui).to receive(:error).with(/does not support listing forwarded ports/).
expect(message).to include("does not support listing forwarded ports") and_call_original
}
expect(subject.execute).to eq(1) expect(subject.execute).to eq(1)
end end
@ -75,9 +73,8 @@ describe VagrantPlugins::CommandPort::Command do
allow(machine.provider).to receive(:capability).with(:forwarded_ports) allow(machine.provider).to receive(:capability).with(:forwarded_ports)
.and_return([]) .and_return([])
expect(env.ui).to receive(:info).with(any_args) { |message, _| expect(env.ui).to receive(:info).with(/there are no forwarded ports/).
expect(message).to include("there are no forwarded ports") and_call_original
}
expect(subject.execute).to eq(0) expect(subject.execute).to eq(0)
end end
@ -125,14 +122,10 @@ describe VagrantPlugins::CommandPort::Command do
allow(machine.provider).to receive(:capability).with(:forwarded_ports) allow(machine.provider).to receive(:capability).with(:forwarded_ports)
.and_return([[2222,22]]) .and_return([[2222,22]])
output = "" expect(env.ui).to receive(:error).with(/not currently mapping port 80/).
allow(env.ui).to receive(:error) do |data| and_call_original
output << data
end
expect(subject.execute).to_not eq(0) expect(subject.execute).to_not eq(0)
expect(output).to include("not currently mapping port 80")
end end
end end
end end

View File

@ -52,8 +52,8 @@ describe VagrantPlugins::CommandSnapshot::Command::List do
it "prints a message if the vm does not exist" do it "prints a message if the vm does not exist" do
machine.id = nil machine.id = nil
expect(iso_env.ui).to receive(:info).with("==> default: VM not created. Moving on...", anything) expect(iso_env.ui).to receive(:info).with("==> default: VM not created. Moving on...", anything).
.and_return({}) and_call_original
expect(machine).to_not receive(:action) expect(machine).to_not receive(:action)
expect(subject.execute).to eq(0) expect(subject.execute).to eq(0)
end end
@ -61,7 +61,7 @@ describe VagrantPlugins::CommandSnapshot::Command::List do
it "prints a message if no snapshots have been taken" do it "prints a message if no snapshots have been taken" do
machine.id = "foo" machine.id = "foo"
expect(iso_env.ui).to receive(:output) expect(iso_env.ui).to receive(:output).and_call_original
.with(/No snapshots have been taken yet!/, anything) .with(/No snapshots have been taken yet!/, anything)
expect(subject.execute).to eq(0) expect(subject.execute).to eq(0)
end end
@ -72,9 +72,9 @@ describe VagrantPlugins::CommandSnapshot::Command::List do
allow(machine.provider).to receive(:capability).with(:snapshot_list). allow(machine.provider).to receive(:capability).with(:snapshot_list).
and_return(["foo", "bar", "baz"]) and_return(["foo", "bar", "baz"])
expect(iso_env.ui).to receive(:output).with(/default/, anything) expect(iso_env.ui).to receive(:output).with(/default/, anything).and_call_original
expect(iso_env.ui).to receive(:detail).with(/foo/, anything) expect(iso_env.ui).to receive(:detail).with(/foo/, anything).and_call_original
expect(iso_env.ui).to receive(:detail).with(/bar/, anything) expect(iso_env.ui).to receive(:detail).with(/bar/, anything).and_call_original
expect(iso_env.ui).to receive(:detail).with(/baz/, anything) expect(iso_env.ui).to receive(:detail).with(/baz/, anything)
expect(subject.execute).to eq(0) expect(subject.execute).to eq(0)
end end

View File

@ -27,8 +27,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
let(:config) { double("config", ssh: ssh) } let(:config) { double("config", ssh: ssh) }
# Provider mock # Provider mock
let(:provider) { double("provider") } let(:provider) { double("provider") }
# UI mock let(:ui) { Vagrant::UI::Silent.new }
let(:ui) { double("ui") }
# Machine mock built with previously defined # Machine mock built with previously defined
let(:machine) do let(:machine) do
double("machine", double("machine",
@ -99,10 +98,6 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
describe ".wait_for_ready" do describe ".wait_for_ready" do
before(&connection_setup) before(&connection_setup)
context "with no static config (default scenario)" do context "with no static config (default scenario)" do
before do
allow(ui).to receive(:detail)
end
context "when ssh_info requires a multiple tries before it is ready" do context "when ssh_info requires a multiple tries before it is ready" do
before do before do
expect(machine).to receive(:ssh_info). expect(machine).to receive(:ssh_info).
@ -123,18 +118,19 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
and_return(host: '10.1.2.3', port: 22) and_return(host: '10.1.2.3', port: 22)
allow(communicator).to receive(:connect) allow(communicator).to receive(:connect)
allow(communicator).to receive(:ready?).and_return(true) allow(communicator).to receive(:ready?).and_return(true)
allow(ui).to receive(:detail).and_call_original
end end
it "should print message" do it "should print message" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(ui).to receive(:detail).with(/timeout/) expect(ui).to receive(:detail).with(/timeout/).and_call_original
communicator.wait_for_ready(0.5) communicator.wait_for_ready(0.5)
end end
it "should not print the same message twice" do it "should not print the same message twice" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(ui).to receive(:detail).with(/timeout/) expect(ui).to receive(:detail).with(/timeout/).and_call_original
expect(ui).not_to receive(:detail).with(/timeout/) expect(ui).not_to receive(:detail).with(/timeout/)
communicator.wait_for_ready(0.5) communicator.wait_for_ready(0.5)
end end
@ -142,8 +138,8 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
it "should print different messages" do it "should print different messages" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected)
expect(ui).to receive(:detail).with(/timeout/) expect(ui).to receive(:detail).with(/timeout/).and_call_original
expect(ui).to receive(:detail).with(/disconnect/) expect(ui).to receive(:detail).with(/disconnect/).and_call_original
communicator.wait_for_ready(0.5) communicator.wait_for_ready(0.5)
end end
@ -152,8 +148,8 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected) expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected)
expect(ui).to receive(:detail).with(/timeout/) expect(ui).to receive(:detail).with(/timeout/).and_call_original
expect(ui).to receive(:detail).with(/disconnect/) expect(ui).to receive(:detail).with(/disconnect/).and_call_original
expect(ui).not_to receive(:detail).with(/timeout/) expect(ui).not_to receive(:detail).with(/timeout/)
expect(ui).not_to receive(:detail).with(/disconnect/) expect(ui).not_to receive(:detail).with(/disconnect/)
communicator.wait_for_ready(0.5) communicator.wait_for_ready(0.5)
@ -206,7 +202,6 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
allow(guest).to receive(:capability?).with(:remove_public_key). allow(guest).to receive(:capability?).with(:remove_public_key).
and_return(has_remove_cap) and_return(has_remove_cap)
allow(communicator).to receive(:insecure_key?).with("KEY_PATH").and_return(true) allow(communicator).to receive(:insecure_key?).with("KEY_PATH").and_return(true)
allow(ui).to receive(:detail)
end end
let(:insert_ssh_key){ true } let(:insert_ssh_key){ true }
@ -249,7 +244,6 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
let(:path_joiner){ double("path_joiner") } let(:path_joiner){ double("path_joiner") }
before do before do
allow(ui).to receive(:info)
allow(Vagrant::Util::Keypair).to receive(:create). allow(Vagrant::Util::Keypair).to receive(:create).
and_return([new_public_key, new_private_key, openssh]) and_return([new_public_key, new_private_key, openssh])
allow(private_key_file).to receive(:open).and_yield(private_key_file) allow(private_key_file).to receive(:open).and_yield(private_key_file)

View File

@ -8,7 +8,7 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
let(:winrm) { double("winrm", timeout: 1, host: nil, port: 5986, guest_port: 5986) } let(:winrm) { double("winrm", timeout: 1, host: nil, port: 5986, guest_port: 5986) }
let(:config) { double("config", winrm: winrm) } let(:config) { double("config", winrm: winrm) }
let(:provider) { double("provider") } let(:provider) { double("provider") }
let(:ui) { double("ui") } let(:ui) { Vagrant::UI::Silent.new }
let(:machine) { double("machine", config: config, provider: provider, ui: ui) } let(:machine) { double("machine", config: config, provider: provider, ui: ui) }
let(:shell) { double("shell") } let(:shell) { double("shell") }
let(:good_output) { WinRM::Output.new.tap { |out| out.exitcode = 0 } } let(:good_output) { WinRM::Output.new.tap { |out| out.exitcode = 0 } }
@ -33,7 +33,6 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
allow(provider).to receive(:capability?).with(:winrm_info).and_return(false) allow(provider).to receive(:capability?).with(:winrm_info).and_return(false)
# Get us through the detail prints # Get us through the detail prints
allow(ui).to receive(:detail)
allow(shell).to receive(:host) allow(shell).to receive(:host)
allow(shell).to receive(:port) allow(shell).to receive(:port)
allow(shell).to receive(:username) allow(shell).to receive(:username)

View File

@ -33,8 +33,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
let(:config) { double("config", winssh: winssh, ssh: ssh) } let(:config) { double("config", winssh: winssh, ssh: ssh) }
# Provider mock # Provider mock
let(:provider) { double("provider") } let(:provider) { double("provider") }
# UI mock let(:ui) { Vagrant::UI::Silent.new }
let(:ui) { double("ui") }
# SSH info mock # SSH info mock
let(:ssh_info) { double("ssh_info") } let(:ssh_info) { double("ssh_info") }
# Machine mock built with previously defined # Machine mock built with previously defined
@ -111,10 +110,6 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do
describe "#wait_for_ready" do describe "#wait_for_ready" do
before(&connection_setup) before(&connection_setup)
context "with no static config (default scenario)" do context "with no static config (default scenario)" do
before do
allow(ui).to receive(:detail)
end
context "when ssh_info requires a multiple tries before it is ready" do context "when ssh_info requires a multiple tries before it is ready" do
before do before do
expect(machine).to receive(:ssh_info). expect(machine).to receive(:ssh_info).

View File

@ -152,9 +152,8 @@ describe "VagrantPlugins::GuestFreeBSD::Cap::MountVirtualBoxSharedFolder" do
context "with custom mount options" do context "with custom mount options" do
let(:ui){ double(:ui) } let(:ui){ Vagrant::UI::Silent.new }
before do before do
allow(ui).to receive(:warn)
allow(machine).to receive(:ui).and_return(ui) allow(machine).to receive(:ui).and_return(ui)
end end

View File

@ -48,11 +48,10 @@ describe "VagrantPlugins::GuestLinux::Cap::PersistMountSharedFolder" do
describe ".persist_mount_shared_folder" do describe ".persist_mount_shared_folder" do
let(:ui){ double(:ui) } let(:ui){ Vagrant::UI::Silent.new }
before do before do
allow(comm).to receive(:sudo).with(any_args) allow(comm).to receive(:sudo).with(any_args)
allow(ui).to receive(:warn)
allow(machine).to receive(:ui).and_return(ui) allow(machine).to receive(:ui).and_return(ui)
end end
@ -101,7 +100,7 @@ describe "VagrantPlugins::GuestLinux::Cap::PersistMountSharedFolder" do
cap.persist_mount_shared_folder(machine, nil) cap.persist_mount_shared_folder(machine, nil)
end end
end end
context "smb folder" do context "smb folder" do
let (:fstab_folders) { let (:fstab_folders) {
Vagrant::Plugin::V2::SyncedFolder::Collection[ Vagrant::Plugin::V2::SyncedFolder::Collection[
@ -123,13 +122,13 @@ describe "VagrantPlugins::GuestLinux::Cap::PersistMountSharedFolder" do
allow(folder_plugin).to receive(:capability?).with(:mount_name).and_return(true) allow(folder_plugin).to receive(:capability?).with(:mount_name).and_return(true)
allow(folder_plugin).to receive(:capability).with(:mount_name, instance_of(String), any_args).and_return("//192.168.42.42/dummyname") allow(folder_plugin).to receive(:capability).with(:mount_name, instance_of(String), any_args).and_return("//192.168.42.42/dummyname")
end end
it "inserts folders into /etc/fstab" do it "inserts folders into /etc/fstab" do
expected_entry_vagrant = "//192.168.42.42/dummyname /vagrant cifs #{expected_mount_options} 0 0" expected_entry_vagrant = "//192.168.42.42/dummyname /vagrant cifs #{expected_mount_options} 0 0"
expected_entry_test = "//192.168.42.42/dummyname /test1 cifs #{expected_mount_options} 0 0" expected_entry_test = "//192.168.42.42/dummyname /test1 cifs #{expected_mount_options} 0 0"
expect(cap).to receive(:remove_vagrant_managed_fstab) expect(cap).to receive(:remove_vagrant_managed_fstab)
expect(comm).to receive(:sudo).with(/#{expected_entry_test}\n#{expected_entry_vagrant}/) expect(comm).to receive(:sudo).with(/#{expected_entry_test}\n#{expected_entry_vagrant}/)
cap.persist_mount_shared_folder(machine, folders) cap.persist_mount_shared_folder(machine, folders)
end end
end end

View File

@ -18,7 +18,6 @@ describe "VagrantPlugins::GuestLinux::Cap::Reboot" do
allow(machine).to receive(:guest).and_return(guest) allow(machine).to receive(:guest).and_return(guest)
allow(machine.guest).to receive(:ready?).and_return(true) allow(machine.guest).to receive(:ready?).and_return(true)
allow(machine).to receive(:ui).and_return(ui) allow(machine).to receive(:ui).and_return(ui)
allow(ui).to receive(:info)
allow(communicator).to receive(:test).and_return(false) allow(communicator).to receive(:test).and_return(false)
end end
@ -45,7 +44,7 @@ describe "VagrantPlugins::GuestLinux::Cap::Reboot" do
after { described_class.reboot(machine) } after { described_class.reboot(machine) }
it "sends message to user that guest is rebooting" do it "sends message to user that guest is rebooting" do
expect(ui).to receive(:info) expect(ui).to receive(:info).and_call_original
end end
end end
end end
@ -56,7 +55,6 @@ describe "VagrantPlugins::GuestLinux::Cap::Reboot" do
allow(machine).to receive(:guest).and_return(guest) allow(machine).to receive(:guest).and_return(guest)
allow(machine.guest).to receive(:ready?).and_return(true) allow(machine.guest).to receive(:ready?).and_return(true)
allow(machine).to receive(:ui).and_return(ui) allow(machine).to receive(:ui).and_return(ui)
allow(ui).to receive(:info)
allow(communicator).to receive(:test).and_return(true) allow(communicator).to receive(:test).and_return(true)
end end

View File

@ -19,7 +19,6 @@ describe "VagrantPlugins::GuestWindows::Cap::Reboot" do
allow(machine.guest).to receive(:ready?).and_return(true) allow(machine.guest).to receive(:ready?).and_return(true)
allow(machine).to receive(:config).and_return(config) allow(machine).to receive(:config).and_return(config)
allow(config).to receive(:vm).and_return(vm) allow(config).to receive(:vm).and_return(vm)
allow(ui).to receive(:info)
end end
describe ".reboot" do describe ".reboot" do
@ -47,7 +46,7 @@ describe "VagrantPlugins::GuestWindows::Cap::Reboot" do
it "sends message to user that guest is rebooting" do it "sends message to user that guest is rebooting" do
expect(communicator).to receive(:test).and_return(true) expect(communicator).to receive(:test).and_return(true)
expect(ui).to receive(:info) expect(ui).to receive(:info).and_call_original
end end
end end

View File

@ -20,7 +20,6 @@ describe VagrantPlugins::HostBSD::Cap::NFS do
allow(described_class).to receive(:nfs_cleanup) allow(described_class).to receive(:nfs_cleanup)
allow(described_class).to receive(:system) allow(described_class).to receive(:system)
allow(File).to receive(:writable?).with("/etc/exports") allow(File).to receive(:writable?).with("/etc/exports")
allow(ui).to receive(:info)
allow(Vagrant::Util::Subprocess).to receive(:execute).with("nfsd", "checkexports"). allow(Vagrant::Util::Subprocess).to receive(:execute).with("nfsd", "checkexports").
and_return(Vagrant::Util::Subprocess::Result.new(0, "", "")) and_return(Vagrant::Util::Subprocess::Result.new(0, "", ""))

View File

@ -17,7 +17,7 @@ describe VagrantPlugins::HostLinux::Cap::NFS do
end end
let(:exports_path){ VagrantPlugins::HostLinux::Cap::NFS::NFS_EXPORTS_PATH } let(:exports_path){ VagrantPlugins::HostLinux::Cap::NFS::NFS_EXPORTS_PATH }
let(:env){ double(:env) } let(:env){ double(:env) }
let(:ui){ double(:ui) } let(:ui){ Vagrant::UI::Silent.new }
let(:host){ double(:host) } let(:host){ double(:host) }
before do before do
@ -125,7 +125,6 @@ describe VagrantPlugins::HostLinux::Cap::NFS do
allow(host).to receive(:capability).with(:nfs_apply_command).and_return("/bin/true") allow(host).to receive(:capability).with(:nfs_apply_command).and_return("/bin/true")
allow(host).to receive(:capability).with(:nfs_check_command).and_return("/bin/true") allow(host).to receive(:capability).with(:nfs_check_command).and_return("/bin/true")
allow(host).to receive(:capability).with(:nfs_start_command).and_return("/bin/true") allow(host).to receive(:capability).with(:nfs_start_command).and_return("/bin/true")
allow(ui).to receive(:info)
allow(Vagrant::Util::Subprocess).to receive(:execute).and_call_original allow(Vagrant::Util::Subprocess).to receive(:execute).and_call_original
allow(Vagrant::Util::Subprocess).to receive(:execute).with("sudo", "/bin/true").and_return(double(:result, exit_code: 0)) allow(Vagrant::Util::Subprocess).to receive(:execute).with("sudo", "/bin/true").and_return(double(:result, exit_code: 0))
allow(Vagrant::Util::Subprocess).to receive(:execute).with("/bin/true").and_return(double(:result, exit_code: 0)) allow(Vagrant::Util::Subprocess).to receive(:execute).with("/bin/true").and_return(double(:result, exit_code: 0))
@ -206,7 +205,6 @@ EOH
let(:cap){ caps.get(:nfs_prune) } let(:cap){ caps.get(:nfs_prune) }
before do before do
allow(ui).to receive(:info)
allow(Vagrant::Util::Subprocess).to receive(:execute).with("mv", any_args). allow(Vagrant::Util::Subprocess).to receive(:execute).with("mv", any_args).
and_call_original and_call_original
end end

View File

@ -4,7 +4,7 @@ require_relative "../../../../../../plugins/hosts/windows/cap/smb"
describe VagrantPlugins::HostWindows::Cap::SMB do describe VagrantPlugins::HostWindows::Cap::SMB do
let(:subject){ VagrantPlugins::HostWindows::Cap::SMB } let(:subject){ VagrantPlugins::HostWindows::Cap::SMB }
let(:machine){ double(:machine, env: double(:machine_env, ui: double(:ui))) } let(:machine){ double(:machine, env: double(:machine_env, ui: Vagrant::UI::Silent.new)) }
let(:env){ double(:env) } let(:env){ double(:env) }
let(:options){ {} } let(:options){ {} }
let(:result){ Vagrant::Util::Subprocess::Result } let(:result){ Vagrant::Util::Subprocess::Result }
@ -62,7 +62,6 @@ Remark Not Vagrant Owned
allow(subject).to receive(:machine_id).and_return("CUSTOM_ID") allow(subject).to receive(:machine_id).and_return("CUSTOM_ID")
allow(Vagrant::Util::PowerShell).to receive(:version).and_return(powershell_version) allow(Vagrant::Util::PowerShell).to receive(:version).and_return(powershell_version)
allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).and_return("") allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).and_return("")
allow(machine.env.ui).to receive(:warn)
allow(subject).to receive(:sleep) allow(subject).to receive(:sleep)
end end
@ -103,7 +102,7 @@ Remark Not Vagrant Owned
after{ subject.smb_cleanup(env, machine, options) } after{ subject.smb_cleanup(env, machine, options) }
it "should pause after warning user" do it "should pause after warning user" do
expect(machine.env.ui).to receive(:warn) expect(machine.env.ui).to receive(:warn).and_call_original
expect(subject).to receive(:sleep) expect(subject).to receive(:sleep)
end end
@ -184,7 +183,7 @@ Remark Not Vagrant Owned
end end
it "should pause after warning user" do it "should pause after warning user" do
expect(machine.env.ui).to receive(:warn) expect(machine.env.ui).to receive(:warn).and_call_original
expect(subject).to receive(:sleep) expect(subject).to receive(:sleep)
subject.smb_prepare(env, machine, folders, options) subject.smb_prepare(env, machine, folders, options)
end end

View File

@ -11,8 +11,6 @@ describe VagrantPlugins::HyperV::Action::CheckEnabled do
let(:machine){ double("machine", provider: provider) } let(:machine){ double("machine", provider: provider) }
let(:subject){ described_class.new(app, env) } let(:subject){ described_class.new(app, env) }
before{ allow(ui).to receive(:output) }
it "should continue when Hyper-V is enabled" do it "should continue when Hyper-V is enabled" do
expect(driver).to receive(:execute).and_return("result" => true) expect(driver).to receive(:execute).and_return("result" => true)
expect(app).to receive(:call) expect(app).to receive(:call)

View File

@ -41,8 +41,6 @@ describe VagrantPlugins::HyperV::Action::Configure do
allow(driver).to receive(:execute) allow(driver).to receive(:execute)
allow(app).to receive(:call) allow(app).to receive(:call)
expect(driver).to receive(:execute).with(:get_switches).and_return(switches) expect(driver).to receive(:execute).with(:get_switches).and_return(switches)
allow(ui).to receive(:detail)
allow(ui).to receive(:output)
allow(ui).to receive(:ask).and_return("1") allow(ui).to receive(:ask).and_return("1")
allow(data_dir).to receive(:join).and_return(sentinel) allow(data_dir).to receive(:join).and_return(sentinel)
allow(sentinel).to receive(:file?).and_return(false) allow(sentinel).to receive(:file?).and_return(false)

View File

@ -13,7 +13,6 @@ describe VagrantPlugins::HyperV::Action::DeleteVM do
before do before do
allow(app).to receive(:call) allow(app).to receive(:call)
allow(ui).to receive(:info)
allow(driver).to receive(:delete_vm) allow(driver).to receive(:delete_vm)
allow(FileUtils).to receive(:rm_rf) allow(FileUtils).to receive(:rm_rf)
allow(FileUtils).to receive(:mkdir_p) allow(FileUtils).to receive(:mkdir_p)

View File

@ -16,9 +16,6 @@ describe VagrantPlugins::HyperV::Action::Export do
before do before do
allow(app).to receive(:call) allow(app).to receive(:call)
allow(ui).to receive(:info)
allow(ui).to receive(:clear_line)
allow(ui).to receive(:report_progress)
allow(driver).to receive(:export) allow(driver).to receive(:export)
end end

View File

@ -36,8 +36,6 @@ describe VagrantPlugins::HyperV::Action::Import do
allow(data_dir).to receive(:to_s).and_return("DATA_DIR_PATH") allow(data_dir).to receive(:to_s).and_return("DATA_DIR_PATH")
allow(driver).to receive(:import).and_return("id" => "VMID") allow(driver).to receive(:import).and_return("id" => "VMID")
allow(machine).to receive(:id=) allow(machine).to receive(:id=)
allow(ui).to receive(:output)
allow(ui).to receive(:detail)
end end
context "with missing virtual machines directory" do context "with missing virtual machines directory" do

View File

@ -14,7 +14,6 @@ describe VagrantPlugins::HyperV::Action::NetSetMac do
let(:subject){ described_class.new(app, env) } let(:subject){ described_class.new(app, env) }
before do before do
allow(ui).to receive(:info)
allow(driver).to receive(:net_set_mac) allow(driver).to receive(:net_set_mac)
allow(app).to receive(:call) allow(app).to receive(:call)
end end

View File

@ -14,7 +14,6 @@ describe VagrantPlugins::HyperV::Action::NetSetVLan do
let(:subject){ described_class.new(app, env) } let(:subject){ described_class.new(app, env) }
before do before do
allow(ui).to receive(:info)
allow(driver).to receive(:net_set_vlan) allow(driver).to receive(:net_set_vlan)
allow(app).to receive(:call) allow(app).to receive(:call)
end end

View File

@ -17,7 +17,6 @@ describe VagrantPlugins::HyperV::Action::SetName do
let(:subject){ described_class.new(app, env) } let(:subject){ described_class.new(app, env) }
before do before do
allow(ui).to receive(:info)
allow(driver).to receive(:set_name) allow(driver).to receive(:set_name)
allow(app).to receive(:call) allow(app).to receive(:call)
allow(data_dir).to receive(:join).and_return(sentinel) allow(data_dir).to receive(:join).and_return(sentinel)

View File

@ -15,8 +15,6 @@ describe VagrantPlugins::HyperV::Action::WaitForIPAddress do
let(:subject){ described_class.new(app, env) } let(:subject){ described_class.new(app, env) }
before do before do
allow(ui).to receive(:output)
allow(ui).to receive(:detail)
allow(driver).to receive(:read_guest_ip).and_return("ip" => "127.0.0.1") allow(driver).to receive(:read_guest_ip).and_return("ip" => "127.0.0.1")
allow(app).to receive(:call) allow(app).to receive(:call)
end end

View File

@ -16,7 +16,6 @@ describe VagrantPlugins::ProviderVirtualBox::Action::MatchMACAddress do
let(:subject) { described_class.new(app, env) } let(:subject) { described_class.new(app, env) }
before do before do
allow(ui).to receive(:info)
allow(app).to receive(:call) allow(app).to receive(:call)
end end

View File

@ -129,9 +129,8 @@ describe "VagrantPlugins::ProviderVirtualBox::Cap::MountOptions" do
end end
context "with custom mount options" do context "with custom mount options" do
let(:ui){ double(:ui) } let(:ui){ Vagrant::UI::Silent.new }
before do before do
allow(ui).to receive(:warn)
allow(machine).to receive(:ui).and_return(ui) allow(machine).to receive(:ui).and_return(ui)
end end

View File

@ -59,7 +59,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
end end
describe "#enable" do describe "#enable" do
let(:ui){ double(:ui) } let(:ui){ Vagrant::UI::Silent.new }
let(:guest) { double("guest") } let(:guest) { double("guest") }
let(:no_guestpath_folder) { {"/no_guestpath_folder"=> let(:no_guestpath_folder) { {"/no_guestpath_folder"=>
@ -72,8 +72,6 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
before do before do
allow(subject).to receive(:share_folders).and_return(true) allow(subject).to receive(:share_folders).and_return(true)
allow(ui).to receive(:detail).with(any_args)
allow(ui).to receive(:output).with(any_args)
allow(machine).to receive(:ui).and_return(ui) allow(machine).to receive(:ui).and_return(ui)
allow(machine).to receive(:ssh_info).and_return({:username => "test"}) allow(machine).to receive(:ssh_info).and_return({:username => "test"})
allow(machine).to receive(:guest).and_return(guest) allow(machine).to receive(:guest).and_return(guest)
@ -226,7 +224,6 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
allow(env.data_dir).to receive(:join).and_return(gate_file) allow(env.data_dir).to receive(:join).and_return(gate_file)
allow(gate_file).to receive(:exist?).and_return(false) allow(gate_file).to receive(:exist?).and_return(false)
allow(FileUtils).to receive(:touch) allow(FileUtils).to receive(:touch)
allow(env.ui).to receive(:warn)
end end
it "should create file" do it "should create file" do
@ -234,7 +231,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
end end
it "should output warning to user" do it "should output warning to user" do
expect(env.ui).to receive(:warn) expect(env.ui).to receive(:warn).and_call_original
end end
end end
@ -243,7 +240,6 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
allow(env.data_dir).to receive(:join).and_return(gate_file) allow(env.data_dir).to receive(:join).and_return(gate_file)
allow(gate_file).to receive(:exist?).and_return(true) allow(gate_file).to receive(:exist?).and_return(true)
allow(FileUtils).to receive(:touch) allow(FileUtils).to receive(:touch)
allow(env.ui).to receive(:warn)
end end
it "should not create/update file" do it "should not create/update file" do
@ -251,7 +247,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
end end
it "should not output warning to user" do it "should not output warning to user" do
expect(env.ui).not_to receive(:warn) expect(env.ui).not_to receive(:warn).and_call_original
end end
end end
end end

View File

@ -3,9 +3,11 @@ require File.expand_path("../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/provisioners/container/client") require Vagrant.source_root.join("plugins/provisioners/container/client")
describe VagrantPlugins::ContainerProvisioner::Client do describe VagrantPlugins::ContainerProvisioner::Client do
let(:machine) { double("machine") } let(:machine) { double("machine", communicate: communicator, ui: ui) }
let(:container_command) { double("docker") } let(:ui) { Vagrant::UI::Silent.new }
let(:communicator) { double("communicator") }
let(:container_command) { "CONTAINER_COMMAND" }
subject { described_class.new(machine, container_command) } subject { described_class.new(machine, container_command) }
describe "#container_name" do describe "#container_name" do
@ -14,4 +16,40 @@ describe VagrantPlugins::ContainerProvisioner::Client do
expect(subject.container_name(config)).to eq("test-test-1.1.1") expect(subject.container_name(config)).to eq("test-test-1.1.1")
end end
end end
describe "#build_images" do
before { allow(communicator).to receive(:sudo) }
it "should use sudo to run command" do
expect(communicator).to receive(:sudo).with(/#{Regexp.escape(container_command)}/)
subject.build_images([["path", {}]])
end
it "should output information to use" do
expect(ui).to receive(:info).and_call_original
subject.build_images([["path", {}]])
end
it "should handle communicator output" do
expect(communicator).to receive(:sudo).with(/#{Regexp.escape(container_command)}/).
and_yield(:stdout, "some output")
subject.build_images([["path", {}]])
end
end
describe "#pull_images" do
before do
allow(communicator).to receive(:sudo)
end
it "should use sudo to run command" do
expect(communicator).to receive(:sudo).with(/#{Regexp.escape(container_command)}/)
subject.pull_images(:image)
end
it "should output information to use" do
expect(ui).to receive(:info).and_call_original
subject.pull_images(:image)
end
end
end end

View File

@ -673,7 +673,8 @@ describe "Vagrant::Shell::Provisioner" do
end end
it "should color the output" do it "should color the output" do
expect(ui).to receive(:detail).with(data, hash_including(color: :green)) expect(ui).to receive(:detail).with(data, hash_including(color: :green)).
and_call_original
vsp.send(:handle_comm, type, data) vsp.send(:handle_comm, type, data)
end end
@ -700,7 +701,8 @@ describe "Vagrant::Shell::Provisioner" do
end end
it "should color the output" do it "should color the output" do
expect(ui).to receive(:detail).with(data, hash_including(color: :red)) expect(ui).to receive(:detail).with(data, hash_including(color: :red)).
and_call_original
vsp.send(:handle_comm, type, data) vsp.send(:handle_comm, type, data)
end end

View File

@ -42,9 +42,6 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
allow(m).to receive(:state).and_return(double("state", id: :not_created)) 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(:env).and_return(iso_env)
allow(m).to receive(:config).and_return(double("config")) allow(m).to receive(:config).and_return(double("config"))
allow(m.ui).to receive(:error).and_return(nil)
end end
end end
@ -76,7 +73,6 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
before do before do
allow(subject).to receive(:with_target_vms) { |&block| block.call machine } allow(subject).to receive(:with_target_vms) { |&block| block.call machine }
allow(machine.ui).to receive(:info)
allow(machine.state).to receive(:id).and_return(:created) allow(machine.state).to receive(:id).and_return(:created)
allow(machine.env).to receive(:cwd). allow(machine.env).to receive(:cwd).
and_return("/Users/brian/code/vagrant-sandbox") and_return("/Users/brian/code/vagrant-sandbox")
@ -92,12 +88,16 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
end end
it "does not sync folders outside of the cwd" do it "does not sync folders outside of the cwd" do
allow(machine.ui).to receive(:info).and_call_original
expect(machine.ui).to receive(:info). expect(machine.ui).to receive(:info).
with("Not syncing /Not/The/Same/Path as it is not part of the current working directory.") with("Not syncing /Not/The/Same/Path as it is not part of the current working directory.").
and_call_original
expect(machine.ui).to receive(:info). expect(machine.ui).to receive(:info).
with("Watching: /Users/brian/code/vagrant-sandbox") with("Watching: /Users/brian/code/vagrant-sandbox").
and_call_original
expect(machine.ui).to receive(:info). expect(machine.ui).to receive(:info).
with("Watching: /Users/brian/code/relative-dir") with("Watching: /Users/brian/code/relative-dir").
and_call_original
expect(helper_class).to receive(:rsync_single) expect(helper_class).to receive(:rsync_single)
expect(Listen).to receive(:to). expect(Listen).to receive(:to).
@ -237,7 +237,6 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
before do before do
allow_any_instance_of(Vagrant::Errors::VagrantError). allow_any_instance_of(Vagrant::Errors::VagrantError).
to receive(:translate_error) to receive(:translate_error)
allow(machine.ui).to receive(:error)
end end
context "when rsync command fails" do context "when rsync command fails" do
@ -247,7 +246,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
end end
it "should notify on error" do it "should notify on error" do
expect(machine.ui).to receive(:error) expect(machine.ui).to receive(:error).and_call_original
subject.callback(*args) subject.callback(*args)
end end
@ -263,7 +262,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
end end
it "should notify on error" do it "should notify on error" do
expect(machine.ui).to receive(:error) expect(machine.ui).to receive(:error).and_call_original
subject.callback(*args) subject.callback(*args)
end end

View File

@ -339,7 +339,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows, :bsdtar do
expect(app).to receive(:call).with(env) expect(app).to receive(:call).with(env)
expect(env[:ui]).to receive(:warn) expect(env[:ui]).to receive(:warn).and_call_original
.with(/It looks like you attempted to add a box with a URL for the name/) .with(/It looks like you attempted to add a box with a URL for the name/)
subject.call(env) subject.call(env)
@ -383,8 +383,9 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows, :bsdtar do
true true
}.and_return(box) }.and_return(box)
allow(env[:ui]).to receive(:detail) allow(env[:ui]).to receive(:detail).and_call_original
expect(env[:ui]).to receive(:detail).with(%r{.*http://(?!#{username}).+?:(?!#{password}).+?@127\.0\.0\.1:#{port}/#{box_path.basename}.*}) expect(env[:ui]).to receive(:detail).with(%r{.*http://(?!#{username}).+?:(?!#{password}).+?@127\.0\.0\.1:#{port}/#{box_path.basename}.*}).
and_call_original
expect(app).to receive(:call).with(env) expect(app).to receive(:call).with(env)
subject.call(env) subject.call(env)

View File

@ -13,10 +13,6 @@ describe Vagrant::Action::Builtin::CloudInitWait do
describe "#call" do describe "#call" do
before do
allow(ui).to receive(:output)
end
context "cloud init configuration exists" do context "cloud init configuration exists" do
let(:vm) { double("vm", cloud_init_configs: ["some config"]) } let(:vm) { double("vm", cloud_init_configs: ["some config"]) }

View File

@ -11,7 +11,6 @@ describe Vagrant::Action::Builtin::SetHostname do
before do before do
allow(machine).to receive_message_chain(:config, :vm, :hostname).and_return("whatever") allow(machine).to receive_message_chain(:config, :vm, :hostname).and_return("whatever")
allow(machine).to receive_message_chain(:guest, :capability) allow(machine).to receive_message_chain(:guest, :capability)
allow(ui).to receive(:info)
end end
it "should change hostname if hosts modification enabled" do it "should change hostname if hosts modification enabled" do

View File

@ -87,7 +87,6 @@ describe Vagrant::Action::General::Package do
let(:path) { double("path") } let(:path) { double("path") }
before do before do
allow(ui).to receive(:info)
allow(FileUtils).to receive(:mkdir_p) allow(FileUtils).to receive(:mkdir_p)
subject.instance_variable_set(:@env, env) subject.instance_variable_set(:@env, env)
end end
@ -158,8 +157,6 @@ describe Vagrant::Action::General::Package do
env["package.files"] = package_files env["package.files"] = package_files
env["package.directory"] = package_directory env["package.directory"] = package_directory
subject.instance_variable_set(:@env, env) subject.instance_variable_set(:@env, env)
allow(ui).to receive(:info)
end end
after do after do
@ -178,7 +175,7 @@ describe Vagrant::Action::General::Package do
end end
it "should notify user of copy" do it "should notify user of copy" do
expect(ui).to receive(:info) expect(ui).to receive(:info).at_least(1).and_call_original
subject.copy_include_files subject.copy_include_files
end end
end end
@ -333,8 +330,6 @@ describe Vagrant::Action::General::Package do
let(:fullpath) { "FULLPATH" } let(:fullpath) { "FULLPATH" }
before do before do
allow(ui).to receive(:info)
allow(described_class).to receive(:validate!) allow(described_class).to receive(:validate!)
allow(subject).to receive(:fullpath).and_return(fullpath) allow(subject).to receive(:fullpath).and_return(fullpath)
allow(subject).to receive(:package_with_folder_path) allow(subject).to receive(:package_with_folder_path)
@ -362,7 +357,7 @@ describe Vagrant::Action::General::Package do
end end
it "should notify of package compressing" do it "should notify of package compressing" do
expect(ui).to receive(:info) expect(ui).to receive(:info).and_call_original
subject.call(env) subject.call(env)
end end

View File

@ -49,7 +49,7 @@ describe Vagrant::BoxCollection, :skip_windows do
environment.box3("foo-VAGRANTSLASH-bar", "1.0", :virtualbox) environment.box3("foo-VAGRANTSLASH-bar", "1.0", :virtualbox)
environment.box3("foo-VAGRANTCOLON-colon", "1.0", :virtualbox) environment.box3("foo-VAGRANTCOLON-colon", "1.0", :virtualbox)
expect(ui).to receive(:warn).once expect(ui).to receive(:warn).once.and_call_original
# Verify some output # Verify some output
results = subject.all results = subject.all

View File

@ -335,7 +335,6 @@ describe Vagrant::Machine do
initial_action_name = :destroy initial_action_name = :destroy
second_action_name = :reload second_action_name = :reload
callable = lambda { |_env| } callable = lambda { |_env| }
original_cwd = env.cwd.to_s
allow(provider).to receive(:action).with(initial_action_name).and_return(callable) allow(provider).to receive(:action).with(initial_action_name).and_return(callable)
allow(provider).to receive(:action).with(second_action_name).and_return(callable) allow(provider).to receive(:action).with(second_action_name).and_return(callable)

View File

@ -224,13 +224,9 @@ describe Vagrant::Plugin::V2::Trigger do
let(:message) { "Printing some info" } let(:message) { "Printing some info" }
it "prints messages at INFO" do it "prints messages at INFO" do
output = "" expect(ui).to receive(:info).with(message).and_call_original
allow(ui).to receive(:info) do |data|
output << data
end
subject.send(:info, message) subject.send(:info, message)
expect(output).to include(message)
end end
end end
@ -238,13 +234,9 @@ describe Vagrant::Plugin::V2::Trigger do
let(:message) { "Printing some warnings" } let(:message) { "Printing some warnings" }
it "prints messages at WARN" do it "prints messages at WARN" do
output = "" expect(ui).to receive(:warn).with(message).and_call_original
allow(ui).to receive(:warn) do |data|
output << data
end
subject.send(:warn, message) subject.send(:warn, message)
expect(output).to include(message)
end end
end end
@ -297,6 +289,7 @@ describe Vagrant::Plugin::V2::Trigger do
it "executes an inline script with powershell if windows" do it "executes an inline script with powershell if windows" do
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true)
allow(Vagrant::Util::PowerShell).to receive(:execute_inline). allow(Vagrant::Util::PowerShell).to receive(:execute_inline).
and_yield(:stderr, "some output").
and_return(subprocess_result) and_return(subprocess_result)
trigger = trigger_run.after_triggers.first trigger = trigger_run.after_triggers.first
@ -309,9 +302,10 @@ describe Vagrant::Plugin::V2::Trigger do
subject.send(:run, shell_config, on_error, exit_codes) subject.send(:run, shell_config, on_error, exit_codes)
end end
it "executes an path script with powershell if windows" do it "executes a path script with powershell if windows" do
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true)
allow(Vagrant::Util::PowerShell).to receive(:execute). allow(Vagrant::Util::PowerShell).to receive(:execute).
and_yield(:stdout, "more output").
and_return(subprocess_result) and_return(subprocess_result)
allow(env).to receive(:root_path).and_return("/vagrant/home") allow(env).to receive(:root_path).and_return("/vagrant/home")
@ -339,7 +333,7 @@ describe Vagrant::Plugin::V2::Trigger do
subject.send(:run, shell_config, on_error, exit_codes) subject.send(:run, shell_config, on_error, exit_codes)
end end
it "executes an path script" do it "executes a path script" do
allow(Vagrant::Util::Subprocess).to receive(:execute). allow(Vagrant::Util::Subprocess).to receive(:execute).
and_return(subprocess_result) and_return(subprocess_result)
allow(env).to receive(:root_path).and_return("/vagrant/home") allow(env).to receive(:root_path).and_return("/vagrant/home")
@ -524,10 +518,6 @@ describe Vagrant::Plugin::V2::Trigger do
describe "#trigger_abort" do describe "#trigger_abort" do
it "system exits when called" do it "system exits when called" do
allow(Process).to receive(:exit!).and_return(true) allow(Process).to receive(:exit!).and_return(true)
output = ""
allow(machine.ui).to receive(:warn) do |data|
output << data
end
expect(Process).to receive(:exit!).with(3) expect(Process).to receive(:exit!).with(3)
subject.send(:trigger_abort, 3) subject.send(:trigger_abort, 3)

View File

@ -36,12 +36,6 @@ describe Vagrant::Util::Downloader do
let(:redirect) { nil } let(:redirect) { nil }
let(:progress_data) { "Location: #{redirect}" } let(:progress_data) { "Location: #{redirect}" }
before do
allow(ui).to receive(:clear_line)
allow(ui).to receive(:detail)
allow(ui).to receive(:rewriting).and_yield(ui)
end
after do after do
expect(subject).to receive(:execute_curl) do |*_, &data_proc| expect(subject).to receive(:execute_curl) do |*_, &data_proc|
expect(data_proc).not_to be_nil expect(data_proc).not_to be_nil
@ -62,7 +56,7 @@ describe Vagrant::Util::Downloader do
let(:redirect) { "http://example.com/vagrant.box" } let(:redirect) { "http://example.com/vagrant.box" }
it "should output redirection information" do it "should output redirection information" do
expect(ui).to receive(:detail).with(/example.com/) expect(ui).to receive(:detail).with(/example.com/).and_call_original
end end
end end
@ -70,7 +64,7 @@ describe Vagrant::Util::Downloader do
let(:redirect) { "http://downloads.example.org/vagrant.box" } let(:redirect) { "http://downloads.example.org/vagrant.box" }
it "should output redirection information" do it "should output redirection information" do
expect(ui).to receive(:detail).with(/downloads.example.org/) expect(ui).to receive(:detail).with(/downloads.example.org/).and_call_original
end end
end end
@ -87,7 +81,7 @@ describe Vagrant::Util::Downloader do
let(:progress_data) { "X-Custom-Location: #{custom_redirect}\nLocation: #{redirect}" } let(:progress_data) { "X-Custom-Location: #{custom_redirect}\nLocation: #{redirect}" }
it "should output redirection information" do it "should output redirection information" do
expect(ui).to receive(:detail).with(/downloads.example.com/) expect(ui).to receive(:detail).with(/downloads.example.com/).and_call_original
end end
end end
end end