|
69 | 69 | end
|
70 | 70 |
|
71 | 71 | 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 |
75 | 78 | end
|
76 | 79 |
|
77 | 80 | it "does not close the destination IO" do
|
|
109 | 112 | end
|
110 | 113 |
|
111 | 114 | after :each do
|
112 |
| - rm_r @to_name, @from_bigfile |
| 115 | + rm_r @to_name if @to_name |
| 116 | + rm_r @from_bigfile |
113 | 117 | end
|
114 | 118 |
|
115 | 119 | describe "from an IO" do
|
|
164 | 168 | it_behaves_like :io_copy_stream_to_io, nil, IOSpecs::CopyStream
|
165 | 169 | it_behaves_like :io_copy_stream_to_io_with_offset, nil, IOSpecs::CopyStream
|
166 | 170 | 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 |
167 | 190 | end
|
168 | 191 |
|
169 | 192 | describe "from a file name" do
|
|
277 | 300 | @io.should_not_receive(:pos)
|
278 | 301 | IO.copy_stream(@io, @to_name)
|
279 | 302 | end
|
280 |
| - |
281 | 303 | end
|
282 | 304 |
|
283 |
| - |
284 | 305 | describe "with a destination that does partial reads" do
|
285 | 306 | before do
|
286 | 307 | @from_out, @from_in = IO.pipe
|
|
0 commit comments