Skip to content

Commit a47a176

Browse files
committed
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.
1 parent 9bd5995 commit a47a176

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

spec/ruby/core/dir/chdir_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
end
2020

2121
it "defaults to $HOME with no arguments" do
22-
if ENV['HOME']
23-
Dir.chdir
24-
current_dir = Dir.pwd
22+
skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
2523

26-
Dir.chdir(ENV['HOME'])
27-
home = Dir.pwd
28-
current_dir.should == home
29-
end
24+
Dir.chdir
25+
current_dir = Dir.pwd
26+
27+
Dir.chdir(ENV['HOME'])
28+
home = Dir.pwd
29+
current_dir.should == home
3030
end
3131

3232
it "changes to the specified directory" do
@@ -70,6 +70,8 @@ def to_str; DirSpecs.mock_dir; end
7070
end
7171

7272
it "defaults to the home directory when given a block but no argument" do
73+
skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
74+
7375
# Windows will return a path with forward slashes for ENV["HOME"] so we have
7476
# to compare the route representations returned by Dir.chdir.
7577
current_dir = ""

spec/ruby/core/dir/shared/exist.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
end
3535

3636
it "doesn't expand paths" do
37+
skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
3738
Dir.send(@method, File.expand_path('~')).should be_true
3839
Dir.send(@method, '~').should be_false
3940
end

0 commit comments

Comments
 (0)