aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2022-12-18 21:05:54 +0100
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-24 23:48:47 +0900
commitd0f5dc9eac78ecade459b740ed08795c8df6d129 (patch)
tree72dab3fcbff2e9deb40dbfce53268438b6bb6bd2 /spec/ruby/core
parent6a55b4601a50144a4c98571a79395b85465fda7f (diff)
downloadruby-d0f5dc9eac78ecade459b740ed08795c8df6d129.tar.gz
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.
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/dir/home_spec.rb17
1 files changed, 17 insertions, 0 deletions
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