From d0f5dc9eac78ecade459b740ed08795c8df6d129 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Sun, 18 Dec 2022 21:05:54 +0100 Subject: Windows: Prefer USERPROFILE over HOMEPATH HOMEPATH is set to "\WINDOWS\system32" when running per "runas" session. This directory is not writable by ordinary users, leading to errors with many ruby tools. Also config files in the home directory are not recognized. Still keeping HOME at first which is not used by native Windows, but by ruby specs and by MSYS2 environment. --- spec/ruby/core/dir/home_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/ruby') diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb index c49a18041b..cde6899df2 100644 --- a/spec/ruby/core/dir/home_spec.rb +++ b/spec/ruby/core/dir/home_spec.rb @@ -32,6 +32,23 @@ describe "Dir.home" do end end + platform_is :windows do + it "retrieves the directory from HOME, USERPROFILE, HOMEDRIVE/HOMEPATH and the WinAPI in that order" do + old_dirs = [ENV.delete('HOME'), ENV.delete('USERPROFILE'), ENV.delete('HOMEDRIVE'), ENV.delete('HOMEPATH')] + + Dir.home.should == old_dirs[1].gsub("\\", "/") + ENV['HOMEDRIVE'] = "C:" + ENV['HOMEPATH'] = "\\rubyspec\\home1" + Dir.home.should == "C:/rubyspec/home1" + ENV['USERPROFILE'] = "C:\\rubyspec\\home2" + Dir.home.should == "C:/rubyspec/home2" + ENV['HOME'] = "C:\\rubyspec\\home3" + Dir.home.should == "C:/rubyspec/home3" + ensure + ENV['HOME'], ENV['USERPROFILE'], ENV['HOMEDRIVE'], ENV['HOMEPATH'] = *old_dirs + end + end + describe "when called with the current user name" do platform_is :solaris do it "returns the named user's home directory from the user database" do -- cgit v1.2.3