Skip to content

Commit 4e8c63d

Browse files
committed
Add tests for anonymous option in Tempfile.create
1 parent 63824bd commit 4e8c63d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

library/tempfile/create_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@
104104
end
105105
end
106106

107+
ruby_version_is "3.4" do
108+
context "when called with anonymous: true" do
109+
it "returns an already unlinked File without a proper path" do
110+
@tempfile = Tempfile.create(anonymous: true)
111+
@tempfile.should_not.closed?
112+
@tempfile.path.should == "#{Dir.tmpdir}/"
113+
File.file?(@tempfile.path).should be_false
114+
end
115+
116+
it "unlinks file before calling the block" do
117+
Tempfile.create(anonymous: true) do |tempfile|
118+
@tempfile = tempfile
119+
@tempfile.should_not.closed?
120+
@tempfile.path.should == "#{Dir.tmpdir}/"
121+
File.file?(@tempfile.path).should be_false
122+
end
123+
@tempfile.should.closed?
124+
end
125+
end
126+
127+
context "when called with anonymous: false" do
128+
it "returns a usual File with a path" do
129+
@tempfile = Tempfile.create(anonymous: false)
130+
@tempfile.should_not.closed?
131+
@tempfile.path.should.start_with?(Dir.tmpdir)
132+
File.file?(@tempfile.path).should be_true
133+
end
134+
end
135+
end
136+
107137
context "when called with other options" do
108138
it "passes them along to File.open" do
109139
@tempfile = Tempfile.create(encoding: "IBM037:IBM037", binmode: true)

0 commit comments

Comments
 (0)