diff --git a/plugins/kernel_v2/config/push.rb b/plugins/kernel_v2/config/push.rb index e1cb95734..e0137b29d 100644 --- a/plugins/kernel_v2/config/push.rb +++ b/plugins/kernel_v2/config/push.rb @@ -21,18 +21,18 @@ module VagrantPlugins # Compile all the provider configurations @__defined_pushes.each do |name, tuples| - # Capture the strategy so we can use it later. This will be used in - # the block iteration for merging/overwriting - strategy = name - strategy = tuples[0][0] if tuples[0] - # Find the configuration class for this push - config_class = Vagrant.plugin("2").manager.push_configs[strategy] + config_class = Vagrant.plugin("2").manager.push_configs[name] config_class ||= Vagrant::Config::V2::DummyConfig # Load it up config = config_class.new + # Capture the strategy so we can use it later. This will be used in + # the block iteration for merging/overwriting + strategy = name + strategy = tuples[0][0] if tuples[0] + begin tuples.each do |s, b| # Update the strategy if it has changed, reseting the current diff --git a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb index 57bb66558..99c99a8af 100644 --- a/test/unit/plugins/commands/login/middleware/add_authentication_test.rb +++ b/test/unit/plugins/commands/login/middleware/add_authentication_test.rb @@ -17,6 +17,7 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do before do allow(Vagrant).to receive(:server_url).and_return(server_url) + stub_env("ATLAS_TOKEN" => nil) end describe "#call" do diff --git a/test/unit/plugins/pushes/local-exec/push_test.rb b/test/unit/plugins/pushes/local-exec/push_test.rb index 6896428d1..1efdfa3b1 100644 --- a/test/unit/plugins/pushes/local-exec/push_test.rb +++ b/test/unit/plugins/pushes/local-exec/push_test.rb @@ -93,47 +93,9 @@ describe VagrantPlugins::LocalExecPush::Push do end describe "#execute!" do - let(:exit_code) { 0 } - let(:stdout) { "This is the output" } - let(:stderr) { "This is the errput" } - - let(:process) do - double("process", - exit_code: exit_code, - stdout: stdout, - stderr: stderr, - ) - end - - before do - allow(Vagrant::Util::Subprocess).to receive(:execute) - .and_return(process) - end - - it "creates a subprocess" do - expect(Vagrant::Util::Subprocess).to receive(:execute) + it "safe execs" do + expect(Vagrant::Util::SafeExec).to receive(:exec) expect { subject.execute! }.to_not raise_error end - - it "returns the resulting process" do - expect(subject.execute!).to be(process) - end - - context "when the exit code is non-zero" do - let(:exit_code) { 1 } - - it "raises an exception" do - klass = VagrantPlugins::LocalExecPush::Errors::CommandFailed - cmd = ["foo", "bar"] - - expect { subject.execute!(*cmd) }.to raise_error(klass) { |error| - expect(error.message).to eq(I18n.t("local_exec_push.errors.command_failed", - cmd: cmd.join(" "), - stdout: stdout, - stderr: stderr, - )) - } - end - end end end diff --git a/test/unit/support/shared/base_context.rb b/test/unit/support/shared/base_context.rb index 35c26788a..0f823948d 100644 --- a/test/unit/support/shared/base_context.rb +++ b/test/unit/support/shared/base_context.rb @@ -83,6 +83,18 @@ shared_context "unit" do return Pathname.new(d) end + # Stub the given environment in ENV, without actually touching ENV. Keys and + # values are converted to strings because that's how the real ENV works. + def stub_env(hash) + allow(ENV).to receive(:[]).and_call_original + + hash.each do |key, value| + allow(ENV).to receive(:[]) + .with(key.to_s) + .and_return(value.to_s) + end + end + # This helper provides temporary environmental variable changes. def with_temp_env(environment) # Build up the new environment, preserving the old values so we