Skip to content

Commit f569c12

Browse files
committed
Avoid use of File.identical? on files in the source tree
On Windows, this method does not seem to work correctly with files on network drives (perhaps only WebDAV?). Presumably, the temporary file directory is located on the local device.
1 parent 83ec1ba commit f569c12

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

test/pathname/test_pathname.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,15 @@ def test_to_s
649649
end
650650

651651
def test_kernel_open
652-
count = 0
653-
result = Kernel.open(Pathname.new(__FILE__)) {|f|
654-
assert_file.identical?(__FILE__, f)
655-
count += 1
656-
2
657-
}
658-
assert_equal(1, count)
659-
assert_equal(2, result)
652+
token = sprintf("%s\#%s|%d|%.8x", self.class.name, __method__, $$, rand(0x1_0000_0000))
653+
Dir.mktmpdir("rubytest-pathname") do |dir|
654+
path = Pathname.new(dir) + "file"
655+
File.write(path, token)
656+
assert_equal(token, File.read(path))
657+
assert_equal(token, Kernel.open(path, &:read))
658+
ensure
659+
File.unlink(path)
660+
end
660661
end
661662

662663
def test_each_filename

0 commit comments

Comments
 (0)