1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Adapt specs for the new Tempfile.open with block behavior

This commit is contained in:
Benoit Daloze 2020-08-29 12:11:07 +02:00
parent fa21985a7a
commit ff323b2a5c

View file

@ -38,8 +38,10 @@ describe "Tempfile.open" do
end
it "is passed an array [base, suffix] as first argument" do
Tempfile.open(["specs", ".tt"]) { |tempfile| @tempfile = tempfile }
@tempfile.path.should =~ /specs.*\.tt$/
Tempfile.open(["specs", ".tt"]) { |tempfile|
@tempfile = tempfile
tempfile.path.should =~ /specs.*\.tt$/
}
end
it "passes the third argument (options) to open" do
@ -65,7 +67,7 @@ describe "Tempfile.open when passed a block" do
end
after :each do
# Tempfile.open with block does not unlink
# Tempfile.open with block does not unlink in Ruby <= 2.7
@tempfile.close! if @tempfile
end
@ -94,4 +96,24 @@ describe "Tempfile.open when passed a block" do
Tempfile.open("specs") { |tempfile| @tempfile = tempfile }
@tempfile.closed?.should be_true
end
ruby_version_is ""..."2.8" do
it "does not unlink the file after the block ends" do
path = Tempfile.open("specs") { |tempfile|
@tempfile = tempfile
tempfile.path
}
File.should.exist?(path)
end
end
ruby_version_is "2.8" do
it "unlinks the file after the block ends" do
path = Tempfile.open("specs") { |tempfile|
@tempfile = tempfile
tempfile.path
}
File.should_not.exist?(path)
end
end
end