From 979c152bb9df311bf70ac0bffa0d9460afcdae50 Mon Sep 17 00:00:00 2001 From: Ryan O'Connor Date: Fri, 13 Oct 2017 14:46:46 -0400 Subject: [PATCH 1/2] Add chomp specs for StringIO#gets, StringIO#readline, StringIO#each_line, StringIO#readlines, StringIO#each and StringIO#lines --- library/stringio/each_line_spec.rb | 6 ++++++ library/stringio/each_spec.rb | 6 ++++++ library/stringio/gets_spec.rb | 9 +++++++++ library/stringio/lines_spec.rb | 6 ++++++ library/stringio/readline_spec.rb | 9 +++++++++ library/stringio/readlines_spec.rb | 9 +++++++++ library/stringio/shared/each.rb | 9 +++++++++ 7 files changed, 54 insertions(+) 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..44e7a5ae9f 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 carriage returns" 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..6c70a0103f 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 carriage returns" 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..80c3fec2f9 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 carriage returns" 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..19cdfb7dda 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 carriage return 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 From 1626abe96f4138264758b31d029b283d703113f5 Mon Sep 17 00:00:00 2001 From: Ryan O'Connor Date: Fri, 20 Oct 2017 11:28:43 -0400 Subject: [PATCH 2/2] Changed incorrect carriage return usage to newline characters --- library/stringio/gets_spec.rb | 2 +- library/stringio/readline_spec.rb | 2 +- library/stringio/readlines_spec.rb | 2 +- library/stringio/shared/each.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/stringio/gets_spec.rb b/library/stringio/gets_spec.rb index 44e7a5ae9f..7cc65465a7 100644 --- a/library/stringio/gets_spec.rb +++ b/library/stringio/gets_spec.rb @@ -239,7 +239,7 @@ ruby_version_is "2.4" do describe "StringIO#gets when passed [chomp]" do - it "returns the data read without carriage returns" 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 diff --git a/library/stringio/readline_spec.rb b/library/stringio/readline_spec.rb index 6c70a0103f..106ad27e14 100644 --- a/library/stringio/readline_spec.rb +++ b/library/stringio/readline_spec.rb @@ -123,7 +123,7 @@ ruby_version_is "2.4" do describe "StringIO#readline when passed [chomp]" do - it "returns the data read without carriage returns" 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 diff --git a/library/stringio/readlines_spec.rb b/library/stringio/readlines_spec.rb index 80c3fec2f9..8581c47d14 100644 --- a/library/stringio/readlines_spec.rb +++ b/library/stringio/readlines_spec.rb @@ -93,7 +93,7 @@ ruby_version_is "2.4" do describe "StringIO#readlines when passed [chomp]" do - it "returns the data read without carriage returns" 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 diff --git a/library/stringio/shared/each.rb b/library/stringio/shared/each.rb index 19cdfb7dda..93fbd60a85 100644 --- a/library/stringio/shared/each.rb +++ b/library/stringio/shared/each.rb @@ -105,7 +105,7 @@ end describe :stringio_each_chomp, shared: true do - it "yields each line with removed carriage return to the passed block" 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 }