diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index a3b13373e..4530364ad 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -170,7 +170,7 @@ module Vagrant # Extra env keys are the remaining opts extra_env = opts.dup - check_cwd + check_cwd # Warns the UI if the machine was last used on a different dir # Create a deterministic ID for this machine vf = nil diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index c59d3b029..9b40f9f61 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -307,6 +307,28 @@ describe Vagrant::Machine do expect { instance.action(action_name) }. to raise_error(Vagrant::Errors::UnimplementedProviderAction) end + + it 'should warn if the machine was last run under a different directory' 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) + + # Whenever the machine is run on a different directory, the user is warned + allow(env).to receive(:cwd).and_return('/a/new/path') + instance.action(action_name) + + expect(subject.ui).to have_received(:warn) do |warn_msg| + expect(warn_msg).to include(original_cwd) + expect(warn_msg).to include('/a/new/path') + end + end end describe "#action_raw" do