diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-04-27 19:42:54 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-04-27 19:42:54 +0200 |
commit | 0d227d1ce6aa01b0f6db06bbbf828acb962d4734 (patch) | |
tree | aeae857319556e0e440aaefa1143fb5d401e7bcb /spec | |
parent | 5b93321064e83ea180492469071189372e8289e8 (diff) | |
download | ruby-0d227d1ce6aa01b0f6db06bbbf828acb962d4734.tar.gz |
Try to more accurately reflect MRI's logic in specs for finding the home if $HOME is unset
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/file/expand_path_spec.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index c2899fe1ac..5bb60d2c23 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -223,7 +223,16 @@ platform_is_not :windows do ENV["HOME"] = @home end - guard -> { Etc.getlogin } do + guard -> { + # We need to check if getlogin(3) returns non-NULL, + # as MRI only checks getlogin(3) for expanding '~' if $HOME is not set. + user = ENV.delete("USER") + begin + Etc.getlogin != nil + ensure + ENV["USER"] = user + end + } do it "uses the user database when passed '~' if HOME is nil" do ENV.delete "HOME" File.directory?(File.expand_path("~")).should == true |