test/unit/vagrant/machine_test.rb in vagrant-unbundled-1.9.5.1 vs test/unit/vagrant/machine_test.rb in vagrant-unbundled-1.9.7.1
- old
+ new
@@ -305,9 +305,70 @@
allow(provider).to receive(:action).with(action_name).and_return(nil)
expect { instance.action(action_name) }.
to raise_error(Vagrant::Errors::UnimplementedProviderAction)
end
+
+ it 'should not warn if the machines cwd has not changed' do
+ initial_action_name = :up
+ second_action_name = :reload
+ 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(second_action_name).and_return(callable)
+ allow(subject.ui).to receive(:warn)
+
+ instance.action(initial_action_name)
+ expect(subject.ui).to_not have_received(:warn)
+
+ instance.action(second_action_name)
+ expect(subject.ui).to_not have_received(:warn)
+ 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(:root_path).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
+
+ 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
let(:callable) {lambda { |e|
e[:called] = true