Skip to content

Commit

Permalink
Introduce IO.new(..., path:) and promote File#path to IO#path. …
Browse files Browse the repository at this point in the history
…(#6867)
  • Loading branch information
ioquatix authored and eregon committed Jan 5, 2023
1 parent 8caf02d commit 62c1bbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/file/shared/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions core/io/path_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 62c1bbe

Please sign in to comment.