Skip to content

Commit

Permalink
Merge pull request #604 from cucumber/fix-cd-environment
Browse files Browse the repository at this point in the history
Do not replace entire environment inside cd block
  • Loading branch information
mvz authored Mar 17, 2019
2 parents fc833a7 + f7da54a commit 8355549
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions spec/aruba/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,44 @@
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 '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
end
end
end
end
end

describe '#read' do
Expand Down

0 comments on commit 8355549

Please sign in to comment.