diff options
Diffstat (limited to 'spec/ruby/core/string/center_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/center_spec.rb | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb index 0284fc28dc..ac5b8a2ff3 100644 --- a/spec/ruby/core/string/center_spec.rb +++ b/spec/ruby/core/string/center_spec.rb @@ -47,16 +47,6 @@ describe "String#center with length, padding" do "radiology".center(8, '-').should == "radiology" end - ruby_version_is ''...'2.7' do - it "taints result when self or padstr is tainted" do - "x".taint.center(4).tainted?.should == true - "x".taint.center(0).tainted?.should == true - "".taint.center(0).tainted?.should == true - "x".taint.center(4, "*").tainted?.should == true - "x".center(4, "*".taint).tainted?.should == true - end - end - it "calls #to_int to convert length to an integer" do "_".center(3.8, "^").should == "^_^" @@ -67,10 +57,10 @@ describe "String#center with length, padding" do end it "raises a TypeError when length can't be converted to an integer" do - -> { "hello".center("x") }.should raise_error(TypeError) - -> { "hello".center("x", "y") }.should raise_error(TypeError) - -> { "hello".center([]) }.should raise_error(TypeError) - -> { "hello".center(mock('x')) }.should raise_error(TypeError) + -> { "hello".center("x") }.should.raise(TypeError) + -> { "hello".center("x", "y") }.should.raise(TypeError) + -> { "hello".center([]) }.should.raise(TypeError) + -> { "hello".center(mock('x')) }.should.raise(TypeError) end it "calls #to_str to convert padstr to a String" do @@ -81,55 +71,47 @@ describe "String#center with length, padding" do end it "raises a TypeError when padstr can't be converted to a string" do - -> { "hello".center(20, 100) }.should raise_error(TypeError) - -> { "hello".center(20, []) }.should raise_error(TypeError) - -> { "hello".center(20, mock('x')) }.should raise_error(TypeError) + -> { "hello".center(20, 100) }.should.raise(TypeError) + -> { "hello".center(20, []) }.should.raise(TypeError) + -> { "hello".center(20, mock('x')) }.should.raise(TypeError) end it "raises an ArgumentError if padstr is empty" do - -> { "hello".center(10, "") }.should raise_error(ArgumentError) - -> { "hello".center(0, "") }.should raise_error(ArgumentError) + -> { "hello".center(10, "") }.should.raise(ArgumentError) + -> { "hello".center(0, "") }.should.raise(ArgumentError) end - it "returns subclass instances when called on subclasses" do - StringSpecs::MyString.new("").center(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").center(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString) + it "returns String instances when called on subclasses" do + StringSpecs::MyString.new("").center(10).should.instance_of?(String) + StringSpecs::MyString.new("foo").center(10).should.instance_of?(String) + StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should.instance_of?(String) - "".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end - - ruby_version_is ''...'2.7' do - it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do - "hello".center(4, 'X'.taint).tainted?.should be_false - "hello".center(5, 'X'.taint).tainted?.should be_false - "hello".center(6, 'X'.taint).tainted?.should be_true - end + "".center(10, StringSpecs::MyString.new("x")).should.instance_of?(String) + "foo".center(10, StringSpecs::MyString.new("x")).should.instance_of?(String) end describe "with width" do it "returns a String in the same encoding as the original" do - str = "abc".force_encoding Encoding::IBM437 + str = "abc".dup.force_encoding Encoding::IBM437 result = str.center 6 result.should == " abc " - result.encoding.should equal(Encoding::IBM437) + result.encoding.should.equal?(Encoding::IBM437) end end describe "with width, pattern" do it "returns a String in the compatible encoding" do - str = "abc".force_encoding Encoding::IBM437 + str = "abc".dup.force_encoding Encoding::IBM437 result = str.center 6, "あ" result.should == "あabcああ" - result.encoding.should equal(Encoding::UTF_8) + result.encoding.should.equal?(Encoding::UTF_8) end it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP -> do "あれ".center 5, pat - end.should raise_error(Encoding::CompatibilityError) + end.should.raise(Encoding::CompatibilityError) end end end |
