summaryrefslogtreecommitdiff
path: root/spec/ruby/core/file/expand_path_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-04-27 19:42:54 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-04-27 19:42:54 +0200
commit0d227d1ce6aa01b0f6db06bbbf828acb962d4734 (patch)
treeaeae857319556e0e440aaefa1143fb5d401e7bcb /spec/ruby/core/file/expand_path_spec.rb
parent5b93321064e83ea180492469071189372e8289e8 (diff)
Try to more accurately reflect MRI's logic in specs for finding the home if $HOME is unset
Diffstat (limited to 'spec/ruby/core/file/expand_path_spec.rb')
-rw-r--r--spec/ruby/core/file/expand_path_spec.rb11
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