diff options
Diffstat (limited to 'spec/ruby/core/io/readpartial_spec.rb')
| -rw-r--r-- | spec/ruby/core/io/readpartial_spec.rb | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb index 16cb08dada..d3f5545c8f 100644 --- a/spec/ruby/core/io/readpartial_spec.rb +++ b/spec/ruby/core/io/readpartial_spec.rb @@ -1,6 +1,6 @@ -# -*- encoding: ascii-8bit -*- -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +# encoding: binary +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "IO#readpartial" do before :each do @@ -15,10 +15,10 @@ describe "IO#readpartial" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError) + -> { IOSpecs.closed_io.readpartial(10) }.should.raise(IOError) @rd.close - lambda { @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' - lambda { @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 - lambda { @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 - lambda { @rd.readpartial(1) }.should raise_error(IOError) + -> { @rd.readpartial(1) }.should.raise(IOError) end it "raises ArgumentError if the negative argument is provided" do - lambda { @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 |
