From 62c1bbe88028961acd8fc059c3d14c24a95e0316 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 8 Dec 2022 18:19:53 +1300 Subject: [PATCH] Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867) --- core/file/shared/path.rb | 14 ++++++++------ core/io/path_spec.rb | 11 +++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 core/io/path_spec.rb diff --git a/core/file/shared/path.rb b/core/file/shared/path.rb index 0a5abe33f0..ee8109ba05 100644 --- a/core/file/shared/path.rb +++ b/core/file/shared/path.rb @@ -78,13 +78,15 @@ rm_r @dir end - it "raises IOError if file was opened with File::TMPFILE" do - begin - File.open(@dir, File::RDWR | File::TMPFILE) do |f| - -> { f.send(@method) }.should raise_error(IOError) + ruby_version_is ""..."3.1" do + it "raises IOError if file was opened with File::TMPFILE" do + begin + File.open(@dir, File::RDWR | File::TMPFILE) do |f| + -> { f.send(@method) }.should raise_error(IOError) + end + rescue Errno::EOPNOTSUPP, Errno::EINVAL, Errno::EISDIR + skip "no support from the filesystem" end - rescue Errno::EOPNOTSUPP, Errno::EINVAL, Errno::EISDIR - skip "no support from the filesystem" end end end diff --git a/core/io/path_spec.rb b/core/io/path_spec.rb new file mode 100644 index 0000000000..51055673d7 --- /dev/null +++ b/core/io/path_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../spec_helper' + +describe "IO#path" do + ruby_version_is "3.2" do + it "returns the path of the file associated with the IO object" do + File.open(tmp("io_path.txt"), "w") do |file| + IO.new(file.fileno, path: file.path, autoclose: false).path.should == file.path + end + end + end +end