summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/chop_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/chop_spec.rb')
-rw-r--r--spec/ruby/core/string/chop_spec.rb73
1 files changed, 32 insertions, 41 deletions
diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb
index 57c037322d..2113da543b 100644
--- a/spec/ruby/core/string/chop_spec.rb
+++ b/spec/ruby/core/string/chop_spec.rb
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
@@ -19,7 +20,7 @@ describe "String#chop" do
"abc\r\n".chop.should == "abc"
end
- it "removes the carrige return, newline if they are the only characters" do
+ it "removes the carriage return, newline if they are the only characters" do
"\r\n".chop.should == ""
end
@@ -27,19 +28,17 @@ describe "String#chop" do
"abc\r\n\r\n".chop.should == "abc\r\n"
end
- with_feature :encoding do
- it "removes a multi-byte character" do
- "あれ".chop.should == "あ"
- end
+ it "removes a multi-byte character" do
+ "あれ".chop.should == "あ"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "あれ\r\n".chop.should == "あれ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "あれ\r\n".chop.should == "あれ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chop.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chop.should == "abc".encode("utf-32be")
end
it "returns an empty string when applied to an empty string" do
@@ -48,21 +47,15 @@ describe "String#chop" do
it "returns a new string when applied to an empty string" do
s = ""
- s.chop.should_not equal(s)
- end
-
- it "taints result when self is tainted" do
- "hello".taint.chop.tainted?.should == true
- "".taint.chop.tainted?.should == true
+ s.chop.should_not.equal?(s)
end
- it "untrusts result when self is untrusted" do
- "hello".untrust.chop.untrusted?.should == true
- "".untrust.chop.untrusted?.should == true
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("hello\n").chop.should.instance_of?(String)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(StringSpecs::MyString)
+ it "returns a String in the same encoding as self" do
+ "abc\n\n".encode("US-ASCII").chop.encoding.should == Encoding::US_ASCII
end
end
@@ -83,7 +76,7 @@ describe "String#chop!" do
"abc\r\n".chop!.should == "abc"
end
- it "removes the carrige return, newline if they are the only characters" do
+ it "removes the carriage return, newline if they are the only characters" do
"\r\n".chop!.should == ""
end
@@ -91,38 +84,36 @@ describe "String#chop!" do
"abc\r\n\r\n".chop!.should == "abc\r\n"
end
- with_feature :encoding do
- it "removes a multi-byte character" do
- "あれ".chop!.should == "あ"
- end
+ it "removes a multi-byte character" do
+ "あれ".chop!.should == "あ"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "あれ\r\n".chop!.should == "あれ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "あれ\r\n".chop!.should == "あれ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chop!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chop!.should == "abc".encode("utf-32be")
end
it "returns self if modifications were made" do
str = "hello"
- str.chop!.should equal(str)
+ str.chop!.should.equal?(str)
end
it "returns nil when called on an empty string" do
- "".chop!.should be_nil
+ "".chop!.should == nil
end
- it "raises a #{frozen_error_class} on a frozen instance that is modified" do
- lambda { "string\n\r".freeze.chop! }.should raise_error(frozen_error_class)
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { "string\n\r".freeze.chop! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do
+ it "raises a FrozenError on a frozen instance that would not be modified" do
a = ""
a.freeze
- lambda { a.chop! }.should raise_error(frozen_error_class)
+ -> { a.chop! }.should.raise(FrozenError)
end
end