Skip to content

Commit

Permalink
Add specs for File.new
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin authored and nirvdrum committed Jan 30, 2023
1 parent 884bf7c commit abee462
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/ruby/core/file/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@

-> { @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
@fh = File.new(@file, flags: File::CREAT)

-> { @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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit abee462

Please sign in to comment.