1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
require_relative '../../spec_helper'
describe "File.readlink" do
# symlink/readlink are not supported on Windows
platform_is_not :windows do
describe "with absolute paths" do
before :each do
@file = tmp('file_readlink.txt')
@link = tmp('file_readlink.lnk')
File.symlink(@file, @link)
end
after :each do
rm_r @file, @link
end
it "returns the name of the file referenced by the given link" do
touch @file
File.readlink(@link).should == @file
end
it "returns the name of the file referenced by the given link when the file does not exist" do
File.readlink(@link).should == @file
end
it "raises an Errno::ENOENT if there is no such file" do
# TODO: missing_file
-> { File.readlink("/this/surely/does/not/exist") }.should raise_error(Errno::ENOENT)
end
it "raises an Errno::EINVAL if called with a normal file" do
touch @file
-> { File.readlink(@file) }.should raise_error(Errno::EINVAL)
end
end
describe "with paths containing unicode characters" do
before :each do
@file = tmp('tàrget.txt')
@link = tmp('lïnk.lnk')
File.symlink(@file, @link)
end
after :each do
rm_r @file, @link
end
it "returns the name of the file referenced by the given link" do
touch @file
result = File.readlink(@link)
result.encoding.should equal Encoding.find('filesystem')
result.should == @file.dup.force_encoding(Encoding.find('filesystem'))
end
end
describe "when changing the working directory" do
before :each do
@cwd = Dir.pwd
@tmpdir = tmp("/readlink")
Dir.mkdir @tmpdir
Dir.chdir @tmpdir
@link = 'readlink_link'
@file = 'readlink_file'
File.symlink(@file, @link)
end
after :each do
rm_r @file, @link
Dir.chdir @cwd
Dir.rmdir @tmpdir
end
it "returns the name of the file referenced by the given link" do
touch @file
File.readlink(@link).should == @file
end
it "returns the name of the file referenced by the given link when the file does not exist" do
File.readlink(@link).should == @file
end
end
end
end
|