2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "String#include? with String" do
|
|
|
|
it "returns true if self contains other_str" do
|
|
|
|
"hello".include?("lo").should == true
|
|
|
|
"hello".include?("ol").should == false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores subclass differences" do
|
|
|
|
"hello".include?(StringSpecs::MyString.new("lo")).should == true
|
|
|
|
StringSpecs::MyString.new("hello").include?("lo").should == true
|
|
|
|
StringSpecs::MyString.new("hello").include?(StringSpecs::MyString.new("lo")).should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "tries to convert other to string using to_str" do
|
|
|
|
other = mock('lo')
|
|
|
|
other.should_receive(:to_str).and_return("lo")
|
|
|
|
|
|
|
|
"hello".include?(other).should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a TypeError if other can't be converted to string" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { "hello".include?([]) }.should raise_error(TypeError)
|
|
|
|
-> { "hello".include?('h'.ord) }.should raise_error(TypeError)
|
|
|
|
-> { "hello".include?(mock('x')) }.should raise_error(TypeError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
2017-09-28 05:19:59 -04:00
|
|
|
|
|
|
|
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
|
|
|
pat = "ア".encode Encoding::EUC_JP
|
2019-07-27 06:40:09 -04:00
|
|
|
-> do
|
2017-09-28 05:19:59 -04:00
|
|
|
"あれ".include?(pat)
|
|
|
|
end.should raise_error(Encoding::CompatibilityError)
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|