summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/chomp_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/chomp_spec.rb')
-rw-r--r--spec/ruby/core/string/chomp_spec.rb116
1 files changed, 25 insertions, 91 deletions
diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb
index 3d6207f876..3a8550892f 100644
--- a/spec/ruby/core/string/chomp_spec.rb
+++ b/spec/ruby/core/string/chomp_spec.rb
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
@@ -21,7 +22,7 @@ describe "String#chomp" do
it "returns a copy of the String when it is not modified" do
str = "abc"
- str.chomp.should_not equal(str)
+ str.chomp.should_not.equal?(str)
end
it "removes one trailing newline" do
@@ -40,24 +41,13 @@ describe "String#chomp" do
"".chomp.should == ""
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp.tainted?.should be_true
- end
+ it "returns a String in the same encoding as self" do
+ "abc\n\n".encode("US-ASCII").chomp.encoding.should == Encoding::US_ASCII
end
- ruby_version_is ''...'3.0' do
- it "returns subclass instances when called on a subclass" do
- str = StringSpecs::MyString.new("hello\n").chomp
- str.should be_an_instance_of(StringSpecs::MyString)
- end
- end
-
- ruby_version_is '3.0' do
- it "returns String instances when called on a subclass" do
- str = StringSpecs::MyString.new("hello\n").chomp
- str.should be_an_instance_of(String)
- end
+ it "returns String instances when called on a subclass" do
+ str = StringSpecs::MyString.new("hello\n").chomp
+ str.should.instance_of?(String)
end
it "removes trailing characters that match $/ when it has been assigned a value" do
@@ -77,13 +67,7 @@ describe "String#chomp" do
it "returns a copy of the String" do
str = "abc"
- str.chomp(nil).should_not equal(str)
- end
-
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp(nil).tainted?.should be_true
- end
+ str.chomp(nil).should_not.equal?(str)
end
it "returns an empty String when self is empty" do
@@ -112,12 +96,6 @@ describe "String#chomp" do
"abc\r\n\r\n\r\n".chomp("").should == "abc"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp("").tainted?.should be_true
- end
- end
-
it "returns an empty String when self is empty" do
"".chomp("").should == ""
end
@@ -140,12 +118,6 @@ describe "String#chomp" do
"abc\r\n\r\n".chomp("\n").should == "abc\r\n"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp("\n").tainted?.should be_true
- end
- end
-
it "returns an empty String when self is empty" do
"".chomp("\n").should == ""
end
@@ -161,7 +133,7 @@ describe "String#chomp" do
it "raises a TypeError if #to_str does not return a String" do
arg = mock("string chomp")
arg.should_receive(:to_str).and_return(1)
- -> { "abc".chomp(arg) }.should raise_error(TypeError)
+ -> { "abc".chomp(arg) }.should.raise(TypeError)
end
end
@@ -178,16 +150,6 @@ describe "String#chomp" do
"".chomp("abc").should == ""
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp("abc").tainted?.should be_true
- end
-
- it "does not taint the result when the argument is tainted" do
- "abc".chomp("abc".taint).tainted?.should be_false
- end
- end
-
it "returns an empty String when the argument equals self" do
"abc".chomp("abc").should == ""
end
@@ -209,11 +171,11 @@ describe "String#chomp!" do
it "modifies self" do
str = "abc\n"
- str.chomp!.should equal(str)
+ str.chomp!.should.equal?(str)
end
it "returns nil if self is not modified" do
- "abc".chomp!.should be_nil
+ "abc".chomp!.should == nil
end
it "removes one trailing newline" do
@@ -229,18 +191,12 @@ describe "String#chomp!" do
end
it "returns nil when self is empty" do
- "".chomp!.should be_nil
- end
-
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!.tainted?.should be_true
- end
+ "".chomp!.should == nil
end
it "returns subclass instances when called on a subclass" do
str = StringSpecs::MyString.new("hello\n").chomp!
- str.should be_an_instance_of(StringSpecs::MyString)
+ str.should.instance_of?(StringSpecs::MyString)
end
it "removes trailing characters that match $/ when it has been assigned a value" do
@@ -251,11 +207,11 @@ describe "String#chomp!" do
describe "when passed nil" do
it "returns nil" do
- "abc\r\n".chomp!(nil).should be_nil
+ "abc\r\n".chomp!(nil).should == nil
end
it "returns nil when self is empty" do
- "".chomp!(nil).should be_nil
+ "".chomp!(nil).should == nil
end
end
@@ -269,7 +225,7 @@ describe "String#chomp!" do
end
it "does not remove a final carriage return" do
- "abc\r".chomp!("").should be_nil
+ "abc\r".chomp!("").should == nil
end
it "removes more than one trailing newlines" do
@@ -280,14 +236,8 @@ describe "String#chomp!" do
"abc\r\n\r\n\r\n".chomp!("").should == "abc"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!("").tainted?.should be_true
- end
- end
-
it "returns nil when self is empty" do
- "".chomp!("").should be_nil
+ "".chomp!("").should == nil
end
end
@@ -304,14 +254,8 @@ describe "String#chomp!" do
"abc\r\n\r\n".chomp!("\n").should == "abc\r\n"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!("\n").tainted?.should be_true
- end
- end
-
it "returns nil when self is empty" do
- "".chomp!("\n").should be_nil
+ "".chomp!("\n").should == nil
end
end
@@ -325,7 +269,7 @@ describe "String#chomp!" do
it "raises a TypeError if #to_str does not return a String" do
arg = mock("string chomp")
arg.should_receive(:to_str).and_return(1)
- -> { "abc".chomp!(arg) }.should raise_error(TypeError)
+ -> { "abc".chomp!(arg) }.should.raise(TypeError)
end
end
@@ -335,21 +279,11 @@ describe "String#chomp!" do
end
it "returns nil if the argument does not match the trailing characters" do
- "abc".chomp!("def").should be_nil
+ "abc".chomp!("def").should == nil
end
it "returns nil when self is empty" do
- "".chomp!("abc").should be_nil
- end
-
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp!("abc").tainted?.should be_true
- end
-
- it "does not taint the result when the argument is tainted" do
- "abc".chomp!("abc".taint).tainted?.should be_false
- end
+ "".chomp!("abc").should == nil
end
end
@@ -357,15 +291,15 @@ describe "String#chomp!" do
a = "string\n\r"
a.freeze
- -> { a.chomp! }.should raise_error(FrozenError)
+ -> { a.chomp! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
it "raises a FrozenError on a frozen instance when it would not be modified" do
a = "string\n\r"
a.freeze
- -> { a.chomp!(nil) }.should raise_error(FrozenError)
- -> { a.chomp!("x") }.should raise_error(FrozenError)
+ -> { a.chomp!(nil) }.should.raise(FrozenError)
+ -> { a.chomp!("x") }.should.raise(FrozenError)
end
end
@@ -412,7 +346,7 @@ describe "String#chomp!" do
end
it "returns nil when the String is not modified" do
- "あれ".chomp!.should be_nil
+ "あれ".chomp!.should == nil
end
it "removes the final carriage return, newline from a multibyte String" do