Skip to content

Commit c0934c6

Browse files
committed
Fix IO.copy_stream with a Tempfile destination
* Fixes oracle/truffleruby#3280
1 parent fb9a36a commit c0934c6

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

core/io/copy_stream_spec.rb

+27-6
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@
6969
end
7070

7171
it "raises an IOError if the destination IO is not open for writing" do
72-
@to_io.close
73-
@to_io = new_io @to_name, "r"
74-
-> { IO.copy_stream @object.from, @to_io }.should raise_error(IOError)
72+
to_io = new_io __FILE__, "r"
73+
begin
74+
-> { IO.copy_stream @object.from, to_io }.should raise_error(IOError)
75+
ensure
76+
to_io.close
77+
end
7578
end
7679

7780
it "does not close the destination IO" do
@@ -109,7 +112,8 @@
109112
end
110113

111114
after :each do
112-
rm_r @to_name, @from_bigfile
115+
rm_r @to_name if @to_name
116+
rm_r @from_bigfile
113117
end
114118

115119
describe "from an IO" do
@@ -164,6 +168,25 @@
164168
it_behaves_like :io_copy_stream_to_io, nil, IOSpecs::CopyStream
165169
it_behaves_like :io_copy_stream_to_io_with_offset, nil, IOSpecs::CopyStream
166170
end
171+
172+
describe "to a Tempfile" do
173+
before :all do
174+
require 'tempfile'
175+
end
176+
177+
before :each do
178+
@to_io = Tempfile.new("rubyspec_copy_stream", encoding: Encoding::BINARY, mode: File::RDONLY)
179+
@to_name = @to_io.path
180+
end
181+
182+
after :each do
183+
@to_io.close!
184+
@to_name = nil # do not rm_r it, already done by Tempfile#close!
185+
end
186+
187+
it_behaves_like :io_copy_stream_to_io, nil, IOSpecs::CopyStream
188+
it_behaves_like :io_copy_stream_to_io_with_offset, nil, IOSpecs::CopyStream
189+
end
167190
end
168191

169192
describe "from a file name" do
@@ -277,10 +300,8 @@
277300
@io.should_not_receive(:pos)
278301
IO.copy_stream(@io, @to_name)
279302
end
280-
281303
end
282304

283-
284305
describe "with a destination that does partial reads" do
285306
before do
286307
@from_out, @from_in = IO.pipe

0 commit comments

Comments
 (0)