diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-27 20:38:57 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-27 20:38:57 +0000 |
commit | 50441014ffd3645f258e56b9415b7787c910408b (patch) | |
tree | 3d5eef5ad1ea7e389dc51fc87437664b984ac184 /spec/ruby/core/file/expand_path_spec.rb | |
parent | 49cd16bfaf4f03885058ce748119bc8ea2de735a (diff) | |
download | ruby-50441014ffd3645f258e56b9415b7787c910408b.tar.gz |
Update to ruby/spec@cdd6ff7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/file/expand_path_spec.rb')
-rw-r--r-- | spec/ruby/core/file/expand_path_spec.rb | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index 99279aec85..b7363fefa9 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -88,7 +88,8 @@ describe "File.expand_path" do platform_is_not :windows do before do - @home = ENV['HOME'].chomp('/') + @var_home = ENV['HOME'].chomp('/') + @db_home = `echo ~#{ENV['USER']}`.chomp end # FIXME: these are insane! @@ -107,9 +108,9 @@ describe "File.expand_path" do File.expand_path('./////').should == Dir.pwd File.expand_path('.').should == Dir.pwd File.expand_path(Dir.pwd).should == Dir.pwd - File.expand_path('~/').should == @home - File.expand_path('~/..badfilename').should == "#{@home}/..badfilename" - File.expand_path('~/a','~/b').should == "#{@home}/a" + File.expand_path('~/').should == @var_home + File.expand_path('~/..badfilename').should == "#{@var_home}/..badfilename" + File.expand_path('~/a','~/b').should == "#{@var_home}/a" File.expand_path('..').should == File.dirname(Dir.pwd) end @@ -126,8 +127,11 @@ describe "File.expand_path" do end it "expands ~ENV['USER'] to the user's home directory" do - File.expand_path("~#{ENV['USER']}").should == @home - File.expand_path("~#{ENV['USER']}/a").should == "#{@home}/a" + File.expand_path("~#{ENV['USER']}").should == @db_home + end + + it "expands ~ENV['USER']/a to a in the user's home directory" do + File.expand_path("~#{ENV['USER']}/a").should == "#{@db_home}/a" end it "does not expand ~ENV['USER'] when it's not at the start" do @@ -135,7 +139,7 @@ describe "File.expand_path" do end it "expands ../foo with ~/dir as base dir to /path/to/user/home/foo" do - File.expand_path('../foo', '~/dir').should == "#{@home}/foo" + File.expand_path('../foo', '~/dir').should == "#{@var_home}/foo" end end @@ -239,4 +243,19 @@ platform_is_not :windows do lambda { File.expand_path("~") }.should raise_error(ArgumentError) end end + + describe "File.expand_path with a non-absolute HOME" do + before :each do + @home = ENV["HOME"] + end + + after :each do + ENV["HOME"] = @home + end + + it "raises an ArgumentError" do + ENV["HOME"] = "non-absolute" + lambda { File.expand_path("~") }.should raise_error(ArgumentError, 'non-absolute home') + end + end end |