From f89536cff80a33a90a12c72a3e051d9257d45671 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 30 Jun 2017 08:13:06 +0200 Subject: [PATCH 1/2] Do not replace entire environment inside cd block --- lib/aruba/api/core.rb | 2 +- spec/aruba/api_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index e93bb6b8b..c9cc040ef 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -61,7 +61,7 @@ def cd(dir, &block) Aruba.platform.chdir File.join(aruba.root_directory, aruba.current_directory) - result = Aruba.platform.with_environment( + result = with_environment( 'OLDPWD' => old_dir, 'PWD' => File.expand_path(File.join(aruba.root_directory, aruba.current_directory)), &block diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index fcc84d2b3..6ca47a095 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -101,6 +101,26 @@ expect(File.exist?(File.expand_path(@directory_path))).to be_truthy end end + + describe '#cd' do + context 'with a block given' do + it 'runs the passed block in the given directory' do + @aruba.create_directory @directory_name + full_path = File.expand_path(@directory_path) + @aruba.cd @directory_name do + expect(Dir.pwd).to eq full_path + end + expect(Dir.pwd).not_to eq full_path + end + + it 'does not touch non-directory environment the passed block' do + @aruba.create_directory @directory_name + @aruba.cd @directory_name do + expect(ENV['HOME']).not_to be_nil + end + end + end + end end describe '#read' do From f7da54ab6cd71248ed33eace9cb2578568b8ed57 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 17 Mar 2019 21:09:50 +0100 Subject: [PATCH 2/2] Improve specs --- spec/aruba/api_spec.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index 6ca47a095..89ee79436 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -113,7 +113,25 @@ expect(Dir.pwd).not_to eq full_path end - it 'does not touch non-directory environment the passed block' do + it 'sets directory environment in the passed block' do + @aruba.create_directory @directory_name + old_pwd = ENV['PWD'] + full_path = File.expand_path(@directory_path) + @aruba.cd @directory_name do + expect(ENV['PWD']).to eq full_path + expect(ENV['OLDPWD']).to eq old_pwd + end + end + + it 'sets aruba environment in the passed block' do + @aruba.create_directory @directory_name + @aruba.set_environment_variable('FOO', 'bar') + @aruba.cd @directory_name do + expect(ENV['FOO']).to eq 'bar' + end + end + + it 'does not touch other environment variables in the passed block' do @aruba.create_directory @directory_name @aruba.cd @directory_name do expect(ENV['HOME']).not_to be_nil