From 0d227d1ce6aa01b0f6db06bbbf828acb962d4734 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 27 Apr 2019 19:42:54 +0200 Subject: Try to more accurately reflect MRI's logic in specs for finding the home if $HOME is unset --- spec/ruby/core/file/expand_path_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'spec/ruby/core/file/expand_path_spec.rb') 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 -- cgit v1.2.3