Merge pull request #8699 from briancain/maint/master/fix-cwd-warnings

Fix vagrant_cwd warnings
This commit is contained in:
Brian Cain 2017-06-19 13:28:00 -07:00 committed by GitHub
commit 09d9c7563a
2 changed files with 27 additions and 5 deletions

View File

@ -577,13 +577,13 @@ module Vagrant
end
if vagrant_cwd.nil?
File.write(vagrant_cwd_filepath, @env.cwd)
elsif vagrant_cwd != @env.cwd.to_s
File.write(vagrant_cwd_filepath, @env.root_path)
elsif vagrant_cwd != @env.root_path.to_s
ui.warn(I18n.t(
'vagrant.moved_cwd',
old_wd: vagrant_cwd,
current_wd: @env.cwd.to_s))
File.write(vagrant_cwd_filepath, @env.cwd)
current_wd: @env.root_path.to_s))
File.write(vagrant_cwd_filepath, @env.root_path)
end
end
end

View File

@ -338,7 +338,7 @@ describe Vagrant::Machine do
expect(subject.ui).to_not have_received(:warn)
# Whenever the machine is run on a different directory, the user is warned
allow(env).to receive(:cwd).and_return('/a/new/path')
allow(env).to receive(:root_path).and_return('/a/new/path')
instance.action(action_name)
expect(subject.ui).to have_received(:warn) do |warn_msg|
@ -346,6 +346,28 @@ describe Vagrant::Machine do
expect(warn_msg).to include('/a/new/path')
end
end
context "if in a subdir" do
let (:data_dir) { env.cwd }
it 'should not warn if vagrant is run in subdirectory' do
action_name = :up
callable = lambda { |_env| }
original_cwd = env.cwd.to_s
allow(provider).to receive(:action).with(action_name).and_return(callable)
allow(subject.ui).to receive(:warn)
instance.action(action_name)
expect(subject.ui).to_not have_received(:warn)
# mock out cwd to be subdir and ensure no warn is printed
allow(env).to receive(:cwd).and_return("#{original_cwd}/a/new/path")
instance.action(action_name)
expect(subject.ui).to_not have_received(:warn)
end
end
end
describe "#action_raw" do