summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringio/shared/read.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/stringio/shared/read.rb')
-rw-r--r--spec/ruby/library/stringio/shared/read.rb54
1 files changed, 36 insertions, 18 deletions
diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb
index 252a85d89d..6e04e75dba 100644
--- a/spec/ruby/library/stringio/shared/read.rb
+++ b/spec/ruby/library/stringio/shared/read.rb
@@ -5,30 +5,48 @@ describe :stringio_read, shared: true do
it "returns the passed buffer String" do
# Note: Rubinius bug:
- # @io.send(@method, 7, buffer = "").should equal(buffer)
- ret = @io.send(@method, 7, buffer = "")
- ret.should equal(buffer)
+ # @io.send(@method, 7, buffer = +"").should.equal?(buffer)
+ ret = @io.send(@method, 7, buffer = +"")
+ ret.should.equal?(buffer)
end
it "reads length bytes and writes them to the buffer String" do
- @io.send(@method, 7, buffer = "")
+ @io.send(@method, 7, buffer = +"").should.equal?(buffer)
buffer.should == "example"
end
+ guard -> { StringIO::VERSION < "3.1.2" } do
+ it "does not preserve the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @io.send(@method, 7, buffer)
+
+ buffer.encoding.should_not == Encoding::ISO_8859_1
+ end
+ end
+
+ guard -> { StringIO::VERSION >= "3.1.2" } do
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @io.send(@method, 7, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+ end
+
it "tries to convert the passed buffer Object to a String using #to_str" do
obj = mock("to_str")
- obj.should_receive(:to_str).and_return(buffer = "")
+ obj.should_receive(:to_str).and_return(buffer = +"")
@io.send(@method, 7, obj)
buffer.should == "example"
end
it "raises a TypeError when the passed buffer Object can't be converted to a String" do
- -> { @io.send(@method, 7, Object.new) }.should raise_error(TypeError)
+ -> { @io.send(@method, 7, Object.new) }.should.raise(TypeError)
end
it "raises a FrozenError error when passed a frozen String as buffer" do
- -> { @io.send(@method, 7, "".freeze) }.should raise_error(FrozenError)
+ -> { @io.send(@method, 7, "".freeze) }.should.raise(FrozenError)
end
end
@@ -48,10 +66,10 @@ describe :stringio_read_length, shared: true do
it "correctly updates the position" do
@io.send(@method, 3)
- @io.pos.should eql(3)
+ @io.pos.should.eql?(3)
@io.send(@method, 999)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
it "tries to convert the passed length to an Integer using #to_int" do
@@ -61,11 +79,11 @@ describe :stringio_read_length, shared: true do
end
it "raises a TypeError when the passed length can't be converted to an Integer" do
- -> { @io.send(@method, Object.new) }.should raise_error(TypeError)
+ -> { @io.send(@method, Object.new) }.should.raise(TypeError)
end
it "raises a TypeError when the passed length is negative" do
- -> { @io.send(@method, -2) }.should raise_error(ArgumentError)
+ -> { @io.send(@method, -2) }.should.raise(ArgumentError)
end
it "returns a binary String" do
@@ -75,7 +93,7 @@ end
describe :stringio_read_no_arguments, shared: true do
before :each do
- @io = StringIO.new("example")
+ @io = StringIO.new(+"example")
end
it "reads the whole content starting from the current position" do
@@ -87,13 +105,13 @@ describe :stringio_read_no_arguments, shared: true do
it "correctly updates the current position" do
@io.send(@method)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
it "correctly update the current position in bytes when multi-byte characters are used" do
@io.print("example\u03A3") # Overwrite the original string with 8 characters containing 9 bytes.
@io.send(@method)
- @io.pos.should eql(9)
+ @io.pos.should.eql?(9)
end
end
@@ -111,17 +129,17 @@ describe :stringio_read_nil, shared: true do
it "updates the current position" do
@io.send(@method, nil)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
end
describe :stringio_read_not_readable, shared: true do
it "raises an IOError" do
- io = StringIO.new("test", "w")
- -> { io.send(@method) }.should raise_error(IOError)
+ io = StringIO.new(+"test", "w")
+ -> { io.send(@method) }.should.raise(IOError)
io = StringIO.new("test")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
end
end