diff options
Diffstat (limited to 'spec/ruby/core/string/rjust_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/rjust_spec.rb | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb index d067b7bdb3..9f9c369745 100644 --- a/spec/ruby/core/string/rjust_spec.rb +++ b/spec/ruby/core/string/rjust_spec.rb @@ -41,10 +41,10 @@ describe "String#rjust with length, padding" do end it "raises a TypeError when length can't be converted to an integer" do - -> { "hello".rjust("x") }.should raise_error(TypeError) - -> { "hello".rjust("x", "y") }.should raise_error(TypeError) - -> { "hello".rjust([]) }.should raise_error(TypeError) - -> { "hello".rjust(mock('x')) }.should raise_error(TypeError) + -> { "hello".rjust("x") }.should.raise(TypeError) + -> { "hello".rjust("x", "y") }.should.raise(TypeError) + -> { "hello".rjust([]) }.should.raise(TypeError) + -> { "hello".rjust(mock('x')) }.should.raise(TypeError) end it "tries to convert padstr to a string using to_str" do @@ -55,59 +55,46 @@ describe "String#rjust with length, padding" do end it "raises a TypeError when padstr can't be converted" do - -> { "hello".rjust(20, []) }.should raise_error(TypeError) - -> { "hello".rjust(20, Object.new)}.should raise_error(TypeError) - -> { "hello".rjust(20, mock('x')) }.should raise_error(TypeError) + -> { "hello".rjust(20, []) }.should.raise(TypeError) + -> { "hello".rjust(20, Object.new)}.should.raise(TypeError) + -> { "hello".rjust(20, mock('x')) }.should.raise(TypeError) end it "raises an ArgumentError when padstr is empty" do - -> { "hello".rjust(10, '') }.should raise_error(ArgumentError) + -> { "hello".rjust(10, '') }.should.raise(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on subclasses" do - StringSpecs::MyString.new("").rjust(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").rjust(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString) + it "returns String instances when called on subclasses" do + StringSpecs::MyString.new("").rjust(10).should.instance_of?(String) + StringSpecs::MyString.new("foo").rjust(10).should.instance_of?(String) + StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should.instance_of?(String) - "".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on subclasses" do - StringSpecs::MyString.new("").rjust(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").rjust(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - - "".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end + "".rjust(10, StringSpecs::MyString.new("x")).should.instance_of?(String) + "foo".rjust(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.rjust 5 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.rjust 5, "あ" 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 "あれ".rjust 5, pat - end.should raise_error(Encoding::CompatibilityError) + end.should.raise(Encoding::CompatibilityError) end end end |
