diff options
Diffstat (limited to 'spec/ruby/core/string/equal_value_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/equal_value_spec.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/spec/ruby/core/string/equal_value_spec.rb b/spec/ruby/core/string/equal_value_spec.rb index cec6843fe6..e8b706c524 100644 --- a/spec/ruby/core/string/equal_value_spec.rb +++ b/spec/ruby/core/string/equal_value_spec.rb @@ -1,8 +1,30 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/eql', __FILE__) -require File.expand_path('../shared/equal_value', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/eql' describe "String#==" do it_behaves_like :string_eql_value, :== - it_behaves_like :string_equal_value, :== + + it "returns false if obj does not respond to to_str" do + ('hello' == 5).should == false + not_supported_on :opal do + ('hello' == :hello).should == false + end + ('hello' == mock('x')).should == false + end + + it "returns obj == self if obj responds to to_str" do + obj = Object.new + + # String#== merely checks if #to_str is defined. It does + # not call it. + obj.stub!(:to_str) + + obj.should_receive(:==).and_return(true) + + ('hello' == obj).should == true + end + + it "is not fooled by NUL characters" do + ("abc\0def" == "abc\0xyz").should == false + end end |
