diff --git a/library/stringio/each_line_spec.rb b/library/stringio/each_line_spec.rb index e4deb9b3e9..d770c18e67 100644 --- a/library/stringio/each_line_spec.rb +++ b/library/stringio/each_line_spec.rb @@ -13,3 +13,9 @@ describe "StringIO#each_line when self is not readable" do it_behaves_like :stringio_each_not_readable, :each_line end + +ruby_version_is "2.4" do + describe "StringIO#each_line when passed chomp" do + it_behaves_like :stringio_each_chomp, :each_line + end +end diff --git a/library/stringio/each_spec.rb b/library/stringio/each_spec.rb index 07ad070192..cebaa345d8 100644 --- a/library/stringio/each_spec.rb +++ b/library/stringio/each_spec.rb @@ -13,3 +13,9 @@ describe "StringIO#each when self is not readable" do it_behaves_like :stringio_each_not_readable, :each end + +ruby_version_is "2.4" do + describe "StringIO#each when passed chomp" do + it_behaves_like :stringio_each_chomp, :each + end +end diff --git a/library/stringio/gets_spec.rb b/library/stringio/gets_spec.rb index 307f564a6e..7cc65465a7 100644 --- a/library/stringio/gets_spec.rb +++ b/library/stringio/gets_spec.rb @@ -236,3 +236,12 @@ lambda { io.gets }.should raise_error(IOError) end end + +ruby_version_is "2.4" do + describe "StringIO#gets when passed [chomp]" do + it "returns the data read without a trailing newline character" do + io = StringIO.new("this>is>an>example\n") + io.gets(chomp: true).should == "this>is>an>example" + end + end +end \ No newline at end of file diff --git a/library/stringio/lines_spec.rb b/library/stringio/lines_spec.rb index 550b25549e..c3af802073 100644 --- a/library/stringio/lines_spec.rb +++ b/library/stringio/lines_spec.rb @@ -13,3 +13,9 @@ describe "StringIO#lines when self is not readable" do it_behaves_like :stringio_each_not_readable, :lines end + +ruby_version_is "2.4" do + describe "StringIO#lines when passed chomp" do + it_behaves_like :stringio_each_chomp, :lines + end +end diff --git a/library/stringio/readline_spec.rb b/library/stringio/readline_spec.rb index 90890e3ad1..106ad27e14 100644 --- a/library/stringio/readline_spec.rb +++ b/library/stringio/readline_spec.rb @@ -120,3 +120,12 @@ lambda { io.readline }.should raise_error(IOError) end end + +ruby_version_is "2.4" do + describe "StringIO#readline when passed [chomp]" do + it "returns the data read without a trailing newline character" do + io = StringIO.new("this>is>an>example\n") + io.readline(chomp: true).should == "this>is>an>example" + end + end +end diff --git a/library/stringio/readlines_spec.rb b/library/stringio/readlines_spec.rb index 215a6cbb2a..8581c47d14 100644 --- a/library/stringio/readlines_spec.rb +++ b/library/stringio/readlines_spec.rb @@ -90,3 +90,12 @@ lambda { io.readlines }.should raise_error(IOError) end end + +ruby_version_is "2.4" do + describe "StringIO#readlines when passed [chomp]" do + it "returns the data read without a trailing newline character" do + io = StringIO.new("this>is>an>example\n") + io.readlines(chomp: true).should == ["this>is>an>example"] + end + end +end diff --git a/library/stringio/shared/each.rb b/library/stringio/shared/each.rb index 0fde23634e..93fbd60a85 100644 --- a/library/stringio/shared/each.rb +++ b/library/stringio/shared/each.rb @@ -103,3 +103,12 @@ lambda { io.send(@method) { |b| b } }.should raise_error(IOError) end end + +describe :stringio_each_chomp, shared: true do + it "yields each line with removed newline characters to the passed block" do + seen = [] + io = StringIO.new("a b c d e\n1 2 3 4 5") + io.send(@method, chomp: true) {|s| seen << s } + seen.should == ["a b c d e", "1 2 3 4 5"] + end +end