From a47a176768c637b7d5158a31a5902b2e680fa47f Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 19 Jun 2024 12:23:12 -0700 Subject: [PATCH] Skip 3 specs when $HOME is not a valid directory If $HOME isn't a valid directory, these specs fail, but I think it is better to skip in this case, as it does not indicate a bug. This fixes specs when run in the OpenBSD port, which sets $HOME to an invalid directory to ensure that software's build system is not accidentally relying on it. --- spec/ruby/core/dir/chdir_spec.rb | 16 +++++++++------- spec/ruby/core/dir/shared/exist.rb | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb index 729ac403e3..7ced2a7057 100644 --- a/spec/ruby/core/dir/chdir_spec.rb +++ b/spec/ruby/core/dir/chdir_spec.rb @@ -19,14 +19,14 @@ describe "Dir.chdir" do end it "defaults to $HOME with no arguments" do - if ENV['HOME'] - Dir.chdir - current_dir = Dir.pwd + skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME']) - Dir.chdir(ENV['HOME']) - home = Dir.pwd - current_dir.should == home - end + Dir.chdir + current_dir = Dir.pwd + + Dir.chdir(ENV['HOME']) + home = Dir.pwd + current_dir.should == home end it "changes to the specified directory" do @@ -70,6 +70,8 @@ describe "Dir.chdir" do end it "defaults to the home directory when given a block but no argument" do + skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME']) + # Windows will return a path with forward slashes for ENV["HOME"] so we have # to compare the route representations returned by Dir.chdir. current_dir = "" diff --git a/spec/ruby/core/dir/shared/exist.rb b/spec/ruby/core/dir/shared/exist.rb index 2ea4f88a80..3097f57715 100644 --- a/spec/ruby/core/dir/shared/exist.rb +++ b/spec/ruby/core/dir/shared/exist.rb @@ -34,6 +34,7 @@ describe :dir_exist, shared: true do end it "doesn't expand paths" do + skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME']) Dir.send(@method, File.expand_path('~')).should be_true Dir.send(@method, '~').should be_false end