summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-08-29 12:11:07 +0200
committerBenoit Daloze <eregontp@gmail.com>2020-08-29 12:11:07 +0200
commitff323b2a5c56cdec93900af4d67f3811f946d9b8 (patch)
tree24c209234cab995556f9ddfa61ca5263e25a4cb6 /spec
parentfa21985a7a2f8f52a8bd82bd12a724e9dca74934 (diff)
Adapt specs for the new Tempfile.open with block behavior
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/library/tempfile/open_spec.rb28
1 files changed, 25 insertions, 3 deletions
diff --git a/spec/ruby/library/tempfile/open_spec.rb b/spec/ruby/library/tempfile/open_spec.rb
index ef2c95376f..dabbe92a8a 100644
--- a/spec/ruby/library/tempfile/open_spec.rb
+++ b/spec/ruby/library/tempfile/open_spec.rb
@@ -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