diff options
Diffstat (limited to 'spec/ruby/core/io/shared/each.rb')
-rw-r--r-- | spec/ruby/core/io/shared/each.rb | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb index 607e7de03e..aca622834f 100644 --- a/spec/ruby/core/io/shared/each.rb +++ b/spec/ruby/core/io/shared/each.rb @@ -33,10 +33,6 @@ describe :io_each, shared: true do $_.should == "test" end - it "returns self" do - @io.send(@method) { |l| l }.should equal(@io) - end - it "raises an IOError when self is not readable" do -> { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) end @@ -77,6 +73,10 @@ describe :io_each, shared: true do -> { @io.send(@method, 0){} }.should raise_error(ArgumentError) end end + + it "does not accept Integers that don't fit in a C off_t" do + -> { @io.send(@method, 2**128){} }.should raise_error(RangeError) + end end describe "when passed a String containing one space as a separator" do @@ -113,6 +113,13 @@ describe :io_each, shared: true do @io.send(@method, "") { |s| ScratchPad << s } ScratchPad.recorded.should == IOSpecs.paragraphs end + + it "discards leading newlines" do + @io.readline + @io.readline + @io.send(@method, "") { |s| ScratchPad << s } + ScratchPad.recorded.should == IOSpecs.paragraphs[1..-1] + end end describe "with both separator and limit" do @@ -152,6 +159,13 @@ describe :io_each, shared: true do @io.send(@method, "", 1024) { |s| ScratchPad << s } ScratchPad.recorded.should == IOSpecs.paragraphs end + + it "discards leading newlines" do + @io.readline + @io.readline + @io.send(@method, "", 1024) { |s| ScratchPad << s } + ScratchPad.recorded.should == IOSpecs.paragraphs[1..-1] + end end end end @@ -162,16 +176,14 @@ describe :io_each, shared: true do ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters end - ruby_version_is "3.0" do - it "raises exception when options passed as Hash" do - -> { - @io.send(@method, { chomp: true }) { |s| } - }.should raise_error(TypeError) + it "raises exception when options passed as Hash" do + -> { + @io.send(@method, { chomp: true }) { |s| } + }.should raise_error(TypeError) - -> { - @io.send(@method, "\n", 1, { chomp: true }) { |s| } - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") - end + -> { + @io.send(@method, "\n", 1, { chomp: true }) { |s| } + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") end end @@ -220,6 +232,14 @@ describe :io_each, shared: true do ] end end + + describe "when passed too many arguments" do + it "raises ArgumentError" do + -> { + @io.send(@method, "", 1, "excess argument", chomp: true) {} + }.should raise_error(ArgumentError) + end + end end describe :io_each_default_separator, shared: true do |