diff options
Diffstat (limited to 'spec/ruby/core/string/rindex_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/rindex_spec.rb | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb index 45ff13a006..acecec224f 100644 --- a/spec/ruby/core/string/rindex_spec.rb +++ b/spec/ruby/core/string/rindex_spec.rb @@ -1,24 +1,23 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' require_relative 'fixtures/classes' -require_relative 'fixtures/utf-8-encoding' describe "String#rindex with object" do it "raises a TypeError if obj isn't a String or Regexp" do not_supported_on :opal do - -> { "hello".rindex(:sym) }.should raise_error(TypeError) + -> { "hello".rindex(:sym) }.should.raise(TypeError) end - -> { "hello".rindex(mock('x')) }.should raise_error(TypeError) + -> { "hello".rindex(mock('x')) }.should.raise(TypeError) end it "raises a TypeError if obj is an Integer" do - -> { "hello".rindex(42) }.should raise_error(TypeError) + -> { "hello".rindex(42) }.should.raise(TypeError) end it "doesn't try to convert obj to an integer via to_int" do obj = mock('x') obj.should_not_receive(:to_int) - -> { "hello".rindex(obj) }.should raise_error(TypeError) + -> { "hello".rindex(obj) }.should.raise(TypeError) end it "tries to convert obj to a string via to_str" do @@ -194,22 +193,22 @@ describe "String#rindex with String" do end it "raises a TypeError when given offset is nil" do - -> { "str".rindex("st", nil) }.should raise_error(TypeError) + -> { "str".rindex("st", nil) }.should.raise(TypeError) end it "handles a substring in a superset encoding" do - 'abc'.force_encoding(Encoding::US_ASCII).rindex('é').should == nil + 'abc'.dup.force_encoding(Encoding::US_ASCII).rindex('é').should == nil end it "handles a substring in a subset encoding" do - 'été'.rindex('t'.force_encoding(Encoding::US_ASCII)).should == 1 + 'été'.rindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 1 end it "raises an Encoding::CompatibilityError if the encodings are incompatible" do - str = 'abc'.force_encoding("ISO-2022-JP") - pattern = 'b'.force_encoding("EUC-JP") + str = 'abc'.dup.force_encoding("ISO-2022-JP") + pattern = 'b'.dup.force_encoding("EUC-JP") - -> { str.rindex(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP") + -> { str.rindex(pattern) }.should.raise(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP") end end @@ -363,7 +362,7 @@ describe "String#rindex with Regexp" do end it "raises a TypeError when given offset is nil" do - -> { "str".rindex(/../, nil) }.should raise_error(TypeError) + -> { "str".rindex(/../, nil) }.should.raise(TypeError) end it "returns the reverse character index of a multibyte character" do @@ -372,14 +371,14 @@ describe "String#rindex with Regexp" do end it "returns the character index before the finish" do - "ありがりがとう".rindex("が", 3).should == 2 - "ありがりがとう".rindex(/が/, 3).should == 2 + "ありがりがとう".rindex("が", 3).should == 2 + "ありがりがとう".rindex(/が/, 3).should == 2 end it "raises an Encoding::CompatibilityError if the encodings are incompatible" do re = Regexp.new "れ".encode(Encoding::EUC_JP) -> do "あれ".rindex re - end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)") + end.should.raise(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)") end end |
