From abee4622cd9b85fc0d07163ea55c47c3ee64bacf Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Wed, 25 Jan 2023 15:26:48 +0200 Subject: [PATCH] Add specs for File.new --- spec/ruby/core/file/new_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/ruby/core/file/new_spec.rb b/spec/ruby/core/file/new_spec.rb index 9383192ee951..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)