diff options
Diffstat (limited to 'spec/ruby/core/string/squeeze_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/squeeze_spec.rb | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb index 6f75402c9c..52b6e1eed4 100644 --- a/spec/ruby/core/string/squeeze_spec.rb +++ b/spec/ruby/core/string/squeeze_spec.rb @@ -1,4 +1,5 @@ -# -*- encoding: binary -*- +# encoding: binary +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' @@ -50,18 +51,8 @@ describe "String#squeeze" do it "raises an ArgumentError when the parameter is out of sequence" do s = "--subbookkeeper--" - -> { s.squeeze("e-b") }.should raise_error(ArgumentError) - -> { s.squeeze("^e-b") }.should raise_error(ArgumentError) - end - - ruby_version_is ''...'2.7' do - it "taints the result when self is tainted" do - "hello".taint.squeeze("e").should.tainted? - "hello".taint.squeeze("a-z").should.tainted? - - "hello".squeeze("e".taint).should_not.tainted? - "hello".squeeze("l".taint).should_not.tainted? - end + -> { s.squeeze("e-b") }.should.raise(ArgumentError) + -> { s.squeeze("^e-b") }.should.raise(ArgumentError) end it "tries to convert each set arg to a string using to_str" do @@ -74,29 +65,26 @@ describe "String#squeeze" do "hello room".squeeze(other_string, other_string2).should == "hello rom" end - it "raises a TypeError when one set arg can't be converted to a string" do - -> { "hello world".squeeze([]) }.should raise_error(TypeError) - -> { "hello world".squeeze(Object.new)}.should raise_error(TypeError) - -> { "hello world".squeeze(mock('x')) }.should raise_error(TypeError) + it "returns a String in the same encoding as self" do + "yellow moon".encode("US-ASCII").squeeze.encoding.should == Encoding::US_ASCII + "yellow moon".encode("US-ASCII").squeeze("a").encoding.should == Encoding::US_ASCII end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(StringSpecs::MyString) - end + it "raises a TypeError when one set arg can't be converted to a string" do + -> { "hello world".squeeze([]) }.should.raise(TypeError) + -> { "hello world".squeeze(Object.new)}.should.raise(TypeError) + -> { "hello world".squeeze(mock('x')) }.should.raise(TypeError) end - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("oh no!!!").squeeze("!").should.instance_of?(String) end end describe "String#squeeze!" do it "modifies self in place and returns self" do a = "yellow moon" - a.squeeze!.should equal(a) + a.squeeze!.should.equal?(a) a.should == "yelow mon" end @@ -109,15 +97,15 @@ describe "String#squeeze!" do it "raises an ArgumentError when the parameter is out of sequence" do s = "--subbookkeeper--" - -> { s.squeeze!("e-b") }.should raise_error(ArgumentError) - -> { s.squeeze!("^e-b") }.should raise_error(ArgumentError) + -> { s.squeeze!("e-b") }.should.raise(ArgumentError) + -> { s.squeeze!("^e-b") }.should.raise(ArgumentError) end it "raises a FrozenError when self is frozen" do a = "yellow moon" a.freeze - -> { a.squeeze!("") }.should raise_error(FrozenError) - -> { a.squeeze! }.should raise_error(FrozenError) + -> { a.squeeze!("") }.should.raise(FrozenError) + -> { a.squeeze! }.should.raise(FrozenError) end end |
