summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/shared/concat.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/shared/concat.rb')
-rw-r--r--spec/ruby/core/string/shared/concat.rb71
1 files changed, 35 insertions, 36 deletions
diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb
index 0a87410f2f..dded9a69e7 100644
--- a/spec/ruby/core/string/shared/concat.rb
+++ b/spec/ruby/core/string/shared/concat.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
describe :string_concat, shared: true do
it "concatenates the given argument to self and returns self" do
str = 'hello '
@@ -5,24 +6,12 @@ describe :string_concat, shared: true do
str.should == "hello world"
end
- it "converts the given argument to a String using to_str" do
- obj = mock('world!')
- obj.should_receive(:to_str).and_return("world!")
- a = 'hello '.send(@method, obj)
- a.should == 'hello world!'
- end
-
- it "raises a TypeError if the given argument can't be converted to a String" do
- lambda { 'hello '.send(@method, []) }.should raise_error(TypeError)
- lambda { 'hello '.send(@method, mock('x')) }.should raise_error(TypeError)
- end
-
- it "raises a #{frozen_error_class} when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a.send(@method, "") }.should raise_error(frozen_error_class)
- lambda { a.send(@method, "test") }.should raise_error(frozen_error_class)
+ -> { a.send(@method, "") }.should raise_error(FrozenError)
+ -> { a.send(@method, "test") }.should raise_error(FrozenError)
end
it "returns a String when given a subclass instance" do
@@ -39,16 +28,6 @@ describe :string_concat, shared: true do
str.should be_an_instance_of(StringSpecs::MyString)
end
- it "taints self if other is tainted" do
- "x".send(@method, "".taint).tainted?.should == true
- "x".send(@method, "y".taint).tainted?.should == true
- end
-
- it "untrusts self if other is untrusted" do
- "x".send(@method, "".untrust).untrusted?.should == true
- "x".send(@method, "y".untrust).untrusted?.should == true
- end
-
describe "with Integer" do
it "concatenates the argument interpreted as a codepoint" do
b = "".send(@method, 33)
@@ -71,28 +50,28 @@ describe :string_concat, shared: true do
end
it "raises RangeError if the argument is an invalid codepoint for self's encoding" do
- lambda { "".encode(Encoding::US_ASCII).send(@method, 256) }.should raise_error(RangeError)
- lambda { "".encode(Encoding::EUC_JP).send(@method, 0x81) }.should raise_error(RangeError)
+ -> { "".encode(Encoding::US_ASCII).send(@method, 256) }.should raise_error(RangeError)
+ -> { "".encode(Encoding::EUC_JP).send(@method, 0x81) }.should raise_error(RangeError)
end
it "raises RangeError if the argument is negative" do
- lambda { "".send(@method, -200) }.should raise_error(RangeError)
- lambda { "".send(@method, -bignum_value) }.should raise_error(RangeError)
+ -> { "".send(@method, -200) }.should raise_error(RangeError)
+ -> { "".send(@method, -bignum_value) }.should raise_error(RangeError)
end
it "doesn't call to_int on its argument" do
x = mock('x')
x.should_not_receive(:to_int)
- lambda { "".send(@method, x) }.should raise_error(TypeError)
+ -> { "".send(@method, x) }.should raise_error(TypeError)
end
- it "raises a #{frozen_error_class} when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a.send(@method, 0) }.should raise_error(frozen_error_class)
- lambda { a.send(@method, 33) }.should raise_error(frozen_error_class)
+ -> { a.send(@method, 0) }.should raise_error(FrozenError)
+ -> { a.send(@method, 33) }.should raise_error(FrozenError)
end
end
end
@@ -112,7 +91,7 @@ describe :string_concat_encoding, shared: true do
end
it "raises Encoding::CompatibilityError if neither are empty" do
- lambda { "x".encode("UTF-16LE").send(@method, "y".encode("UTF-8")) }.should raise_error(Encoding::CompatibilityError)
+ -> { "x".encode("UTF-16LE").send(@method, "y".encode("UTF-8")) }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -130,7 +109,7 @@ describe :string_concat_encoding, shared: true do
end
it "raises Encoding::CompatibilityError if neither are empty" do
- lambda { "x".encode("UTF-8").send(@method, "y".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError)
+ -> { "x".encode("UTF-8").send(@method, "y".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -148,7 +127,7 @@ describe :string_concat_encoding, shared: true do
end
it "raises Encoding::CompatibilityError if neither are ASCII-only" do
- lambda { "\u00E9".encode("UTF-8").send(@method, "\u00E9".encode("ISO-8859-1")) }.should raise_error(Encoding::CompatibilityError)
+ -> { "\u00E9".encode("UTF-8").send(@method, "\u00E9".encode("ISO-8859-1")) }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -158,3 +137,23 @@ describe :string_concat_encoding, shared: true do
end
end
end
+
+describe :string_concat_type_coercion, shared: true do
+ it "converts the given argument to a String using to_str" do
+ obj = mock('world!')
+ obj.should_receive(:to_str).and_return("world!")
+ a = 'hello '.send(@method, obj)
+ a.should == 'hello world!'
+ end
+
+ it "raises a TypeError if the given argument can't be converted to a String" do
+ -> { 'hello '.send(@method, []) }.should raise_error(TypeError)
+ -> { 'hello '.send(@method, mock('x')) }.should raise_error(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a String" do
+ obj = mock('world!')
+ obj.should_receive(:to_str).and_raise(NoMethodError)
+ -> { 'hello '.send(@method, obj) }.should raise_error(NoMethodError)
+ end
+end