diff options
Diffstat (limited to 'spec/ruby/core/io/readpartial_spec.rb')
| -rw-r--r-- | spec/ruby/core/io/readpartial_spec.rb | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb index 2b33a0d5b1..d3f5545c8f 100644 --- a/spec/ruby/core/io/readpartial_spec.rb +++ b/spec/ruby/core/io/readpartial_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require_relative '../../spec_helper' require_relative 'fixtures/classes' @@ -15,10 +15,10 @@ describe "IO#readpartial" do end it "raises IOError on closed stream" do - -> { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError) + -> { IOSpecs.closed_io.readpartial(10) }.should.raise(IOError) @rd.close - -> { @rd.readpartial(10) }.should raise_error(IOError) + -> { @rd.readpartial(10) }.should.raise(IOError) end it "reads at most the specified number of bytes" do @@ -59,10 +59,10 @@ describe "IO#readpartial" do end it "discards the existing buffer content upon successful read" do - buffer = "existing" + buffer = +"existing content" @wr.write("hello world") @wr.close - @rd.readpartial(11, buffer) + @rd.readpartial(11, buffer).should.equal?(buffer) buffer.should == "hello world" end @@ -70,27 +70,46 @@ describe "IO#readpartial" do @wr.write("abc") @wr.close @rd.readpartial(10).should == 'abc' - -> { @rd.readpartial(10) }.should raise_error(EOFError) + -> { @rd.readpartial(10) }.should.raise(EOFError) end it "discards the existing buffer content upon error" do - buffer = 'hello' + buffer = +'hello' @wr.close - -> { @rd.readpartial(1, buffer) }.should raise_error(EOFError) - buffer.should be_empty + -> { @rd.readpartial(1, buffer) }.should.raise(EOFError) + buffer.should.empty? end it "raises IOError if the stream is closed" do @wr.close - -> { @rd.readpartial(1) }.should raise_error(IOError) + -> { @rd.readpartial(1) }.should.raise(IOError) end it "raises ArgumentError if the negative argument is provided" do - -> { @rd.readpartial(-1) }.should raise_error(ArgumentError) + -> { @rd.readpartial(-1) }.should.raise(ArgumentError) end it "immediately returns an empty string if the length argument is 0" do @rd.readpartial(0).should == "" end + it "raises IOError if the stream is closed and the length argument is 0" do + @rd.close + -> { @rd.readpartial(0) }.should.raise(IOError, "closed stream") + end + + it "clears and returns the given buffer if the length argument is 0" do + buffer = +"existing content" + @rd.readpartial(0, buffer).should == buffer + buffer.should == "" + end + + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + @wr.write("abc") + @wr.close + @rd.readpartial(10, buffer) + + buffer.encoding.should == Encoding::ISO_8859_1 + end end |
