diff --git a/lib/truffle/pathname.rb b/lib/truffle/pathname.rb
index 40d395d02f35..286d2df22953 100644
--- a/lib/truffle/pathname.rb
+++ b/lib/truffle/pathname.rb
@@ -806,26 +806,26 @@ class Pathname # * IO *
#
# This method has existed since 1.8.1.
#
- def each_line(*args, **kw, &block) # :yield: line
- IO.foreach(@path, *args, **kw, &block)
+ def each_line(...) # :yield: line
+ IO.foreach(@path, ...)
end
# See IO.read. Returns all data from the file, or the first +N+ bytes
# if specified.
- def read(*args, **kw) IO.read(@path, *args, **kw) end
+ def read(...) IO.read(@path, ...) end
# See IO.binread. Returns all the bytes from the file, or the first +N+
# if specified.
def binread(*args) IO.binread(@path, *args) end
# See IO.write. Returns the number of bytes written to the file.
- def write(*args, **kw) IO.write(@path, *args, **kw) end
+ def write(...) IO.write(@path, ...) end
# See IO.binwrite. Returns the number of bytes written to the file.
def binwrite(*args) IO.binwrite(@path, *args) end
# See IO.readlines. Returns all the lines from the file.
- def readlines(*args, **kw) IO.readlines(@path, *args, **kw) end
+ def readlines(...) IO.readlines(@path, ...) end
# See IO.sysopen.
def sysopen(*args) IO.sysopen(@path, *args) end
@@ -870,8 +870,8 @@ def ftype() File.ftype(@path) end
def make_link(old) File.link(old, @path) end
# See File.open. Opens the file for reading or writing.
- def open(*args, **kw, &block) # :yield: file
- File.open(@path, *args, **kw, &block)
+ def open(...) # :yield: file
+ File.open(@path, ...)
end
# See File.readlink. Read symbolic link.
diff --git a/spec/ruby/core/file/new_spec.rb b/spec/ruby/core/file/new_spec.rb
index 878c3b6df975..a1ca46979ed8 100644
--- a/spec/ruby/core/file/new_spec.rb
+++ b/spec/ruby/core/file/new_spec.rb
@@ -83,6 +83,7 @@
-> { @fh.puts("test") }.should raise_error(IOError)
@fh.read.should == ""
+ File.should.exist?(@file)
end
it "returns a new read-only File when mode is not specified but flags option is present" do
@@ -90,6 +91,7 @@
-> { @fh.puts("test") }.should raise_error(IOError)
@fh.read.should == ""
+ File.should.exist?(@file)
end
it "creates a new file when use File::EXCL mode" do
@@ -132,6 +134,26 @@
File.should.exist?(@file)
end
+ it "returns a new read-only File when use File::RDONLY|File::CREAT mode" do
+ @fh = File.new(@file, File::RDONLY|File::CREAT)
+ @fh.should be_kind_of(File)
+ File.should.exist?(@file)
+
+ # it's read-only
+ -> { @fh.puts("test") }.should raise_error(IOError)
+ @fh.read.should == ""
+ end
+
+ it "returns a new read-only File when use File::CREAT mode" do
+ @fh = File.new(@file, File::CREAT)
+ @fh.should be_kind_of(File)
+ File.should.exist?(@file)
+
+ # it's read-only
+ -> { @fh.puts("test") }.should raise_error(IOError)
+ @fh.read.should == ""
+ end
+
it "coerces filename using to_str" do
name = mock("file")
name.should_receive(:to_str).and_return(@file)
@@ -146,13 +168,16 @@
File.should.exist?(@file)
end
- it "accepts options as a keyword argument" do
- @fh = File.new(@file, 'w', 0755, flags: @flags)
- @fh.should be_kind_of(File)
+ ruby_version_is "3.0" do
+ it "accepts options as a keyword argument" do
+ @fh = File.new(@file, 'w', 0755, flags: @flags)
+ @fh.should be_kind_of(File)
+ @fh.close
- -> {
- @fh = File.new(@file, 'w', 0755, {flags: @flags})
- }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ -> {
+ @fh = File.new(@file, 'w', 0755, {flags: @flags})
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ end
end
it "bitwise-ORs mode and flags option" do
diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb
index 0346224b93fc..0c6d6cd19c32 100644
--- a/spec/ruby/core/file/open_spec.rb
+++ b/spec/ruby/core/file/open_spec.rb
@@ -565,13 +565,15 @@
File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY}
end
- it "accepts options as a keyword argument" do
- @fh = File.open(@file, 'w', 0755, flags: File::CREAT)
- @fh.should be_an_instance_of(File)
+ ruby_version_is "3.0" do
+ it "accepts options as a keyword argument" do
+ @fh = File.open(@file, 'w', 0755, flags: File::CREAT)
+ @fh.should be_an_instance_of(File)
- -> {
- File.open(@file, 'w', 0755, {flags: File::CREAT})
- }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ -> {
+ File.open(@file, 'w', 0755, {flags: File::CREAT})
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ end
end
it "uses the second argument as an options Hash" do
diff --git a/spec/ruby/core/io/initialize_spec.rb b/spec/ruby/core/io/initialize_spec.rb
index 026252a13d16..28fd7af7ab43 100644
--- a/spec/ruby/core/io/initialize_spec.rb
+++ b/spec/ruby/core/io/initialize_spec.rb
@@ -27,15 +27,17 @@
@io.fileno.should == fd
end
- it "accepts options as keyword arguments" do
- fd = new_fd @name, "w:utf-8"
+ ruby_version_is "3.0" do
+ it "accepts options as keyword arguments" do
+ fd = new_fd @name, "w:utf-8"
- @io.send(:initialize, fd, "w", flags: File::CREAT)
- @io.fileno.should == fd
+ @io.send(:initialize, fd, "w", flags: File::CREAT)
+ @io.fileno.should == fd
- -> {
- @io.send(:initialize, fd, "w", {flags: File::CREAT})
- }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
+ -> {
+ @io.send(:initialize, fd, "w", {flags: File::CREAT})
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
+ end
end
it "raises a TypeError when passed an IO" do
diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb
index c5a370f10524..4294988351bc 100644
--- a/spec/ruby/core/io/read_spec.rb
+++ b/spec/ruby/core/io/read_spec.rb
@@ -23,12 +23,15 @@
IO.read(p)
end
- it "accepts options as keyword arguments" do
- IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3]
+ ruby_version_is "3.0" do
+ # https://bugs.ruby-lang.org/issues/19354
+ it "accepts options as keyword arguments" do
+ IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3]
- -> {
- IO.read(@fname, 3, 0, {mode: "r+"})
- }.should raise_error(ArgumentError, /wrong number of arguments/)
+ -> {
+ IO.read(@fname, 3, 0, {mode: "r+"})
+ }.should raise_error(ArgumentError, /wrong number of arguments/)
+ end
end
it "accepts an empty options Hash" do
diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb
index 6780c236cba0..da4c0af7a979 100644
--- a/spec/ruby/core/io/shared/new.rb
+++ b/spec/ruby/core/io/shared/new.rb
@@ -64,13 +64,15 @@
@io.should be_an_instance_of(IO)
end
- it "accepts options as keyword arguments" do
- @io = IO.send(@method, @fd, "w", flags: File::CREAT)
- @io.write("foo").should == 3
+ ruby_version_is "3.0" do
+ it "accepts options as keyword arguments" do
+ @io = IO.send(@method, @fd, "w", flags: File::CREAT)
+ @io.write("foo").should == 3
- -> {
- IO.send(@method, @fd, "w", {flags: File::CREAT})
- }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
+ -> {
+ IO.send(@method, @fd, "w", {flags: File::CREAT})
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
+ end
end
it "accepts a :mode option" do
diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb
index 8a02fc56debc..bad2ae9d2cd7 100644
--- a/spec/ruby/core/kernel/open_spec.rb
+++ b/spec/ruby/core/kernel/open_spec.rb
@@ -72,13 +72,15 @@
-> { open }.should raise_error(ArgumentError)
end
- it "accepts options as keyword arguments" do
- @file = open(@name, "r", 0666, flags: File::CREAT)
- @file.should be_kind_of(File)
+ ruby_version_is "3.0" do
+ it "accepts options as keyword arguments" do
+ @file = open(@name, "r", 0666, flags: File::CREAT)
+ @file.should be_kind_of(File)
- -> {
- open(@name, "r", 0666, {flags: File::CREAT})
- }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ -> {
+ open(@name, "r", 0666, {flags: File::CREAT})
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ end
end
describe "when given an object that responds to to_open" do