diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/file/realdirpath_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) | |
download | ruby-1d15d5f08032acf1b7bceacbb450d617ff6e0931.tar.gz |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/file/realdirpath_spec.rb')
-rw-r--r-- | spec/ruby/core/file/realdirpath_spec.rb | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/ruby/core/file/realdirpath_spec.rb b/spec/ruby/core/file/realdirpath_spec.rb new file mode 100644 index 0000000000..06900ad461 --- /dev/null +++ b/spec/ruby/core/file/realdirpath_spec.rb @@ -0,0 +1,104 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +platform_is_not :windows do + describe "File.realdirpath" do + before :each do + @real_dir = tmp('dir_realdirpath_real') + @fake_dir = tmp('dir_realdirpath_fake') + @link_dir = tmp('dir_realdirpath_link') + + mkdir_p @real_dir + File.symlink(@real_dir, @link_dir) + + @file = File.join(@real_dir, 'file') + @link = File.join(@link_dir, 'link') + + touch @file + File.symlink(@file, @link) + + @fake_file_in_real_dir = File.join(@real_dir, 'fake_file_in_real_dir') + @fake_file_in_fake_dir = File.join(@fake_dir, 'fake_file_in_fake_dir') + @fake_link_to_real_dir = File.join(@link_dir, 'fake_link_to_real_dir') + @fake_link_to_fake_dir = File.join(@link_dir, 'fake_link_to_fake_dir') + + File.symlink(@fake_file_in_real_dir, @fake_link_to_real_dir) + File.symlink(@fake_file_in_fake_dir, @fake_link_to_fake_dir) + + @dir_for_relative_link = File.join(@real_dir, 'dir1') + mkdir_p @dir_for_relative_link + + @relative_path_to_file = File.join('..', 'file') + @relative_symlink = File.join(@dir_for_relative_link, 'link') + File.symlink(@relative_path_to_file, @relative_symlink) + end + + after :each do + rm_r @file, @link, @fake_link_to_real_dir, @fake_link_to_fake_dir, @real_dir, @link_dir + end + + it "returns '/' when passed '/'" do + File.realdirpath('/').should == '/' + end + + it "returns the real (absolute) pathname not containing symlinks" do + File.realdirpath(@link).should == @file + end + + it "uses base directory for interpreting relative pathname" do + File.realdirpath(File.basename(@link), @link_dir).should == @file + end + + it "uses current directory for interpreting relative pathname" do + Dir.chdir @link_dir do + File.realdirpath(File.basename(@link)).should == @file + end + end + + it "uses link directory for expanding relative links" do + File.realdirpath(@relative_symlink).should == @file + end + + it "raises an Errno::ELOOP if the symlink points to itself" do + File.unlink @link + File.symlink(@link, @link) + lambda { File.realdirpath(@link) }.should raise_error(Errno::ELOOP) + end + + it "returns the real (absolute) pathname if the file is absent" do + File.realdirpath(@fake_file_in_real_dir).should == @fake_file_in_real_dir + end + + it "raises Errno::ENOENT if the directory is absent" do + lambda { File.realdirpath(@fake_file_in_fake_dir) }.should raise_error(Errno::ENOENT) + end + + it "returns the real (absolute) pathname if the symlink points to an absent file" do + File.realdirpath(@fake_link_to_real_dir).should == @fake_file_in_real_dir + end + + it "raises Errno::ENOENT if the symlink points to an absent directory" do + lambda { File.realdirpath(@fake_link_to_fake_dir) }.should raise_error(Errno::ENOENT) + end + end +end + +platform_is :windows do + describe "File.realdirpath" do + before :each do + @file = tmp("realdirpath") + end + + after :each do + rm_r @file + end + + it "returns the same path" do + touch @file + File.realdirpath(@file).should == @file + end + + it "returns the same path even if the last component does not exist" do + File.realdirpath(@file).should == @file + end + end +end |