diff --git a/core/io/fixtures/classes.rb b/core/io/fixtures/classes.rb index fb431d5023..a771e3d929 100644 --- a/core/io/fixtures/classes.rb +++ b/core/io/fixtures/classes.rb @@ -20,6 +20,18 @@ def self.lines "Here is line six.\n" ] end + def self.lines_without_newline_characters + [ "Voici la ligne une.", + "Qui \303\250 la linea due.", + "", + "", + "Aqu\303\255 est\303\241 la l\303\255nea tres.", + "Hier ist Zeile vier.", + "", + "Est\303\241 aqui a linha cinco.", + "Here is line six." ] + end + def self.lines_limit [ "Voici la l", "igne une.\n", diff --git a/core/io/gets_spec.rb b/core/io/gets_spec.rb index d984e795c2..18ea34fa27 100644 --- a/core/io/gets_spec.rb +++ b/core/io/gets_spec.rb @@ -138,6 +138,14 @@ end end end + + ruby_version_is "2.4" do + describe "when passed chomp" do + it "returns the first line without a trailing newline character" do + @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0] + end + end + end end describe "IO#gets" do diff --git a/core/io/readline_spec.rb b/core/io/readline_spec.rb index 39706948eb..a1cddafe5c 100644 --- a/core/io/readline_spec.rb +++ b/core/io/readline_spec.rb @@ -42,4 +42,12 @@ $_.should == line end end + + ruby_version_is "2.4" do + describe "when passed chomp" do + it "returns the first line without a trailing newline character" do + @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0] + end + end + end end diff --git a/core/io/shared/each.rb b/core/io/shared/each.rb index dc07434ecd..d87303b54a 100644 --- a/core/io/shared/each.rb +++ b/core/io/shared/each.rb @@ -114,6 +114,15 @@ ScratchPad.recorded.should == IOSpecs.paragraphs end end + + ruby_version_is "2.4" do + describe "when passed chomp" do + it "yields each line without trailing newline characters to the passed block" do + @io.send(@method, chomp: true) { |s| ScratchPad << s } + ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters + end + end + end end describe :io_each_default_separator, shared: true do diff --git a/core/io/shared/readlines.rb b/core/io/shared/readlines.rb index 4cb821274a..f545d8876a 100644 --- a/core/io/shared/readlines.rb +++ b/core/io/shared/readlines.rb @@ -17,6 +17,13 @@ result = IO.send(@method, @name, "", &@object) (result ? result : ScratchPad.recorded).should == IOSpecs.lines_empty_separator end + + ruby_version_is "2.4" do + it "yields a sequence of lines without trailing newline characters when chomp is passed" do + result = IO.send(@method, @name, chomp: true, &@object) + (result ? result : ScratchPad.recorded).should == IOSpecs.lines_without_newline_characters + end + end end describe :io_readlines_options_19, shared: true do