[前][次][番号順一覧][スレッド一覧]

ruby-changes:54848

From: eregon <ko1@a...>
Date: Wed, 13 Feb 2019 09:31:55 +0900 (JST)
Subject: [ruby-changes:54848] eregon:r66622 (trunk): Update to ruby/spec@944ea57

eregon	2018-12-29 09:22:52 +0900 (Sat, 29 Dec 2018)

  New Revision: 66622

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66622

  Log:
    Update to ruby/spec@944ea57

  Added files:
    trunk/spec/ruby/core/array/difference_spec.rb
    trunk/spec/ruby/core/array/shared/difference.rb
    trunk/spec/ruby/core/array/shared/union.rb
  Modified files:
    trunk/spec/ruby/.travis.yml
    trunk/spec/ruby/core/array/minus_spec.rb
    trunk/spec/ruby/core/array/pack/l_spec.rb
    trunk/spec/ruby/core/array/union_spec.rb
    trunk/spec/ruby/core/dir/shared/open.rb
    trunk/spec/ruby/core/file/atime_spec.rb
    trunk/spec/ruby/core/file/ctime_spec.rb
    trunk/spec/ruby/core/file/mtime_spec.rb
    trunk/spec/ruby/core/file/reopen_spec.rb
    trunk/spec/ruby/core/file/utime_spec.rb
    trunk/spec/ruby/core/float/round_spec.rb
    trunk/spec/ruby/core/io/dup_spec.rb
    trunk/spec/ruby/core/io/reopen_spec.rb
    trunk/spec/ruby/core/kernel/match_spec.rb
    trunk/spec/ruby/core/marshal/dump_spec.rb
    trunk/spec/ruby/core/marshal/shared/load.rb
    trunk/spec/ruby/core/matchdata/begin_spec.rb
    trunk/spec/ruby/core/matchdata/end_spec.rb
    trunk/spec/ruby/core/matchdata/named_captures_spec.rb
    trunk/spec/ruby/core/module/name_spec.rb
    trunk/spec/ruby/core/process/clock_gettime_spec.rb
    trunk/spec/ruby/core/process/kill_spec.rb
    trunk/spec/ruby/core/process/spawn_spec.rb
    trunk/spec/ruby/core/string/scan_spec.rb
    trunk/spec/ruby/core/string/unpack/l_spec.rb
    trunk/spec/ruby/language/return_spec.rb
    trunk/spec/ruby/library/datetime/add_spec.rb
    trunk/spec/ruby/library/datetime/subtract_spec.rb
    trunk/spec/ruby/library/stringio/set_encoding_spec.rb
    trunk/spec/ruby/optional/capi/encoding_spec.rb
    trunk/spec/ruby/optional/capi/time_spec.rb
Index: spec/ruby/library/datetime/add_spec.rb
===================================================================
--- spec/ruby/library/datetime/add_spec.rb	(revision 66621)
+++ spec/ruby/library/datetime/add_spec.rb	(revision 66622)
@@ -4,6 +4,6 @@ require 'date' https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/datetime/add_spec.rb#L4
 describe "DateTime#+" do
   it "is able to add sub-millisecond precision values" do
     datetime = DateTime.new(2017)
-    (datetime + 0.00001).to_time.usec.should == 864000
+    (datetime + 0.00001001).to_time.usec.should == 864864
   end
 end
Index: spec/ruby/library/datetime/subtract_spec.rb
===================================================================
--- spec/ruby/library/datetime/subtract_spec.rb	(revision 66621)
+++ spec/ruby/library/datetime/subtract_spec.rb	(revision 66622)
@@ -4,6 +4,16 @@ require 'date' https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/datetime/subtract_spec.rb#L4
 describe "DateTime#-" do
   it "is able to subtract sub-millisecond precision values" do
     date = DateTime.new(2017)
-    ((date + 0.00001) - date).should == Rational(1, 100000)
+    diff = Rational(123456789, 24*60*60*1000*1000)
+    ((date + diff) - date).should == diff
+    (date - (date + diff)).should == -diff
+    (date - (date - diff)).should == diff
+    ((date - diff) - date).should == -diff
+  end
+
+  it "correctly calculates sub-millisecond time differences" do  #5493
+    dt1 = DateTime.new(2018, 1, 1, 0, 0, 30)
+    dt2 = DateTime.new(2018, 1, 1, 0, 1, 29.000001)
+    ((dt2 - dt1) * 24 * 60 * 60).should == 59.000001
   end
 end
Index: spec/ruby/library/stringio/set_encoding_spec.rb
===================================================================
--- spec/ruby/library/stringio/set_encoding_spec.rb	(revision 66621)
+++ spec/ruby/library/stringio/set_encoding_spec.rb	(revision 66622)
@@ -2,9 +2,19 @@ require 'stringio' https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/set_encoding_spec.rb#L2
 require_relative '../../spec_helper'
 
 describe "StringIO#set_encoding" do
-  it "sets the encoding of the underlying String" do
-    io = StringIO.new
+  it "sets the encoding of the underlying String if the String is not frozen" do
+    str = "".encode(Encoding::US_ASCII)
+
+    io = StringIO.new(str)
     io.set_encoding Encoding::UTF_8
     io.string.encoding.should == Encoding::UTF_8
   end
+
+  it "does not set the encoding of the underlying String if the String is frozen" do
+    str = "".encode(Encoding::US_ASCII).freeze
+
+    io = StringIO.new(str)
+    io.set_encoding Encoding::UTF_8
+    io.string.encoding.should == Encoding::US_ASCII
+  end
 end
Index: spec/ruby/language/return_spec.rb
===================================================================
--- spec/ruby/language/return_spec.rb	(revision 66621)
+++ spec/ruby/language/return_spec.rb	(revision 66622)
@@ -442,6 +442,21 @@ describe "The return keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/return_spec.rb#L442
         end
       end
 
+      describe "within a block within a class" do
+        it "is allowed" do
+          File.write(@filename, <<-END_OF_CODE)
+            class A
+              ScratchPad << "before return"
+              1.times { return }
+              ScratchPad << "after return"
+            end
+          END_OF_CODE
+
+          load @filename
+          ScratchPad.recorded.should == ["before return"]
+        end
+      end
+
       describe "file loading" do
         it "stops file loading and execution" do
           File.write(@filename, <<-END_OF_CODE)
Index: spec/ruby/optional/capi/encoding_spec.rb
===================================================================
--- spec/ruby/optional/capi/encoding_spec.rb	(revision 66621)
+++ spec/ruby/optional/capi/encoding_spec.rb	(revision 66622)
@@ -42,6 +42,8 @@ describe :rb_enc_set_index, shared: true https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/encoding_spec.rb#L42
 end
 
 describe "C-API Encoding function" do
+  @n = 0
+
   before :each do
     @s = CApiEncodingSpecs.new
   end
@@ -49,8 +51,9 @@ describe "C-API Encoding function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/encoding_spec.rb#L51
   ruby_version_is "2.6" do
     describe "rb_enc_alias" do
       it "creates an alias for an existing Encoding" do
-        @s.rb_enc_alias("ZOMGWTFBBQ", "UTF-8").should >= 0
-        Encoding.find("ZOMGWTFBBQ").name.should == "UTF-8"
+        name = "ZOMGWTFBBQ#{@n += 1}"
+        @s.rb_enc_alias(name, "UTF-8").should >= 0
+        Encoding.find(name).name.should == "UTF-8"
       end
     end
   end
Index: spec/ruby/optional/capi/time_spec.rb
===================================================================
--- spec/ruby/optional/capi/time_spec.rb	(revision 66621)
+++ spec/ruby/optional/capi/time_spec.rb	(revision 66622)
@@ -165,7 +165,7 @@ describe "CApiTimeSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/time_spec.rb#L165
       usec.should == 500000
     end
 
-    platform_is_not :mingw32 do
+    guard -> { platform_is_not :mingw or ruby_version_is '2.5' } do
       it "creates a timeval for a negative Fixnum" do
         sec, usec = @s.rb_time_timeval(-1232141421)
         sec.should be_kind_of(Integer)
@@ -224,7 +224,7 @@ describe "CApiTimeSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/time_spec.rb#L224
       nsec.should == 500000000
     end
 
-    platform_is_not :mingw32 do
+    guard -> { platform_is_not :mingw or ruby_version_is '2.5' } do
       it "creates a timespec for a negative Fixnum" do
         sec, nsec = @s.rb_time_timespec(-1232141421)
         sec.should be_kind_of(Integer)
Index: spec/ruby/.travis.yml
===================================================================
--- spec/ruby/.travis.yml	(revision 66621)
+++ spec/ruby/.travis.yml	(revision 66622)
@@ -10,13 +10,16 @@ matrix: https://github.com/ruby/ruby/blob/trunk/spec/ruby/.travis.yml#L10
       env: MSPEC_OPTS="-R2 -ff"
     - rvm: 2.3.8
     - rvm: 2.4.5
+      env: CHECK_LEAKS=true
     - rvm: 2.5.3
       env: CHECK_LEAKS=true
+    - rvm: 2.6.0
+      env: CHECK_LEAKS=true
     - rvm: ruby-head
     - env: RUBOCOP=true
       rvm: 2.4.5
       script:
-        - gem install rubocop -v 0.54.0
+        - gem install rubocop:0.61.0
         - rubocop
   allow_failures:
     - rvm: ruby-head
Index: spec/ruby/core/array/pack/l_spec.rb
===================================================================
--- spec/ruby/core/array/pack/l_spec.rb	(revision 66621)
+++ spec/ruby/core/array/pack/l_spec.rb	(revision 66622)
@@ -29,7 +29,7 @@ describe "Array#pack with format 'L'" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L29
     it_behaves_like :array_pack_32bit_be, 'L>'
   end
 
-  guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+  platform_is wordsize: 32 do
     describe "with modifier '<' and '_'" do
       it_behaves_like :array_pack_32bit_le, 'L<_'
       it_behaves_like :array_pack_32bit_le, 'L_<'
@@ -51,7 +51,7 @@ describe "Array#pack with format 'L'" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L51
     end
   end
 
-  guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+  platform_is wordsize: 64 do
     describe "with modifier '<' and '_'" do
       it_behaves_like :array_pack_64bit_le, 'L<_'
       it_behaves_like :array_pack_64bit_le, 'L_<'
@@ -83,7 +83,7 @@ describe "Array#pack with format 'l'" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L83
     it_behaves_like :array_pack_32bit_be, 'l>'
   end
 
-  guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+  platform_is wordsize: 32 do
     describe "with modifier '<' and '_'" do
       it_behaves_like :array_pack_32bit_le, 'l<_'
       it_behaves_like :array_pack_32bit_le, 'l_<'
@@ -105,7 +105,7 @@ describe "Array#pack with format 'l'" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L105
     end
   end
 
-  guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+  platform_is wordsize: 64 do
     describe "with modifier '<' and '_'" do
       it_behaves_like :array_pack_64bit_le, 'l<_'
       it_behaves_like :array_pack_64bit_le, 'l_<'
@@ -137,7 +137,7 @@ little_endian do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L137
     it_behaves_like :array_pack_32bit_le, 'l'
   end
 
-  guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+  platform_is wordsize: 32 do
     describe "Array#pack with format 'L' with modifier '_'" do
       it_behaves_like :array_pack_32bit_le, 'L_'
     end
@@ -155,7 +155,7 @@ little_endian do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L155
     end
   end
 
-  guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+  platform_is wordsize: 64 do
     describe "Array#pack with format 'L' with modifier '_'" do
       it_behaves_like :array_pack_64bit_le, 'L_'
     end
@@ -183,7 +183,7 @@ big_endian do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L183
     it_behaves_like :array_pack_32bit_be, 'l'
   end
 
-  guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+  platform_is wordsize: 32 do
     describe "Array#pack with format 'L' with modifier '_'" do
       it_behaves_like :array_pack_32bit_be, 'L_'
     end
@@ -201,7 +201,7 @@ big_endian do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/pack/l_spec.rb#L201
     end
   end
 
-  guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+  platform_is wordsize: 64 do
     describe "Array#pack with format 'L' with modifier '_'" do
       it_behaves_like :array_pack_64bit_be, 'L_'
     end
Index: spec/ruby/core/array/union_spec.rb
===================================================================
--- spec/ruby/core/array/union_spec.rb	(revision 66621)
+++ spec/ruby/core/array/union_spec.rb	(revision 66622)
@@ -1,82 +1,27 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/union_spec.rb#L1
 require_relative '../../spec_helper'
 require_relative 'fixtures/classes'
+require_relative 'shared/union'
 
 describe "Array#|" do
-  it "returns an array of elements that appear in either array (union)" do
-    ([] | []).should == []
-    ([1, 2] | []).should == [1, 2]
-    ([] | [1, 2]).should == [1, 2]
-    ([ 1, 2, 3, 4 ] | [ 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
-  end
-
-  it "creates an array with no duplicates" do
-    ([ 1, 2, 3, 1, 4, 5 ] | [ 1, 3, 4, 5, 3, 6 ]).should == [1, 2, 3, 4, 5, 6]
-  end
-
-  it "creates an array with elements in order they are first encountered" do
-    ([ 1, 2, 3, 1 ] | [ 1, 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
-  end
-
-  it "properly handles recursive arrays" do
-    empty = ArraySpecs.empty_recursive_array
-    (empty | empty).should == empty
-
-    array = ArraySpecs.recursive_array
-    (array | []).should == [1, 'two', 3.0, array]
-    ([] | array).should == [1, 'two', 3.0, array]
-    (array | array).should == [1, 'two', 3.0, array]
-    (array | empty).should == [1, 'two', 3.0, array, empty]
-  end
-
-  it "tries to convert the passed argument to an Array using #to_ary" do
-    obj = mock('[1,2,3]')
-    obj.should_receive(:to_ary).and_return([1, 2, 3])
-    ([0] | obj).should == ([0] | [1, 2, 3])
-  end
+  it_behaves_like :array_binary_union, :|
+end
 
-  # MRI follows hashing semantics here, so doesn't actually call eql?/hash for Fixnum/Symbol
-  it "acts as if using an intermediate hash to collect values" do
-    not_supported_on :opal do
-      ([5.0, 4.0] | [5, 4]).should == [5.0, 4.0, 5, 4]
+ruby_version_is "2.6" do
+  describe "Array#union" do
+    it_behaves_like :array_binary_union, :union
+
+    it "returns unique elements when given no argument" do
+      x = [1, 2, 3, 2]
+      x.union.should == [1, 2, 3]
     end
 
-    str = "x"
-    ([str] | [str.dup]).should == [str]
-
-    obj1 = mock('1')
-    obj2 = mock('2')
-    obj1.stub!(:hash).and_return(0)
-    obj2.stub!(:hash).and_return(0)
-    obj2.should_receive(:eql?).at_least(1).and_return(true)
-
-    ([obj1] | [obj2]).should == [obj1]
-    ([obj1, obj1, obj2, obj2] | [obj2]).should == [obj1]
-
-    obj1 = mock('3')
-    obj2 = mock('4')
-    obj1.stub!(:hash).and_return(0)
-    obj2.stub!(:hash).and_return(0)
-    obj2.should_receive(:eql?).at_least(1).and_return(false)
-
-    ([obj1] | [obj2]).should == [obj1, obj2]
-    ([obj1, obj1, obj2, obj2] | [obj2]).should == [obj1, obj2]
-  end
-
-  it "does not return subclass instances for Array subclasses" do
-    (ArraySpecs::MyArray[1, 2, 3] | []).should be_an_instance_of(Array)
-    (ArraySpecs::MyArray[1, 2, 3] | ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
-    ([] | ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
-  end
-
-  it "does not call to_ary on array subclasses" do
-    ([1, 2] | ArraySpecs::ToAryArray[5, 6]).should == [1, 2, 5, 6]
-  end
-
-  it "properly handles an identical item even when its #eql? isn't reflexive" do
-    x = mock('x')
-    x.stub!(:hash).and_return(42)
-    x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+    it "does not return subclass instances for Array subclasses" do
+      ArraySpecs::MyArray[1, 2, 3].union.should be_an_instance_of(Array)
+    end
 
-    ([x] | [x]).should == [x]
+    it "accepts multiple arguments" do
+      x = [1, 2, 3]
+      x.union(x, x, x, x, [3, 4], x).should == [1, 2, 3, 4]
+    end
   end
 end
Index: spec/ruby/core/array/shared/union.rb
===================================================================
--- spec/ruby/core/array/shared/union.rb	(nonexistent)
+++ spec/ruby/core/array/shared/union.rb	(revision 66622)
@@ -0,0 +1,79 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/union.rb#L1
+describe :array_binary_union, shared: true do
+  it "returns an array of elements that appear in either array (union)" do
+    [].send(@method, []).should == []
+    [1, 2].send(@method, []).should == [1, 2]
+    [].send(@method, [1, 2]).should == [1, 2]
+    [ 1, 2, 3, 4 ].send(@method, [ 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
+  end
+
+  it "creates an array with no duplicates" do
+    [ 1, 2, 3, 1, 4, 5 ].send(@method, [ 1, 3, 4, 5, 3, 6 ]).should == [1, 2, 3, 4, 5, 6]
+  end
+
+  it "creates an array with elements in order they are first encountered" do
+    [ 1, 2, 3, 1 ].send(@method, [ 1, 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
+  end
+
+  it "properly handles recursive arrays" do
+    empty = ArraySpecs.empty_recursive_array
+    empty.send(@method, empty).should == empty
+
+    array = ArraySpecs.recursive_array
+    array.send(@method, []).should == [1, 'two', 3.0, array]
+    [].send(@method, array).should == [1, 'two', 3.0, array]
+    array.send(@method, array).should == [1, 'two', 3.0, array]
+    array.send(@method, empty).should == [1, 'two', 3.0, array, empty]
+  end
+
+  it "tries to convert the passed argument to an Array using #to_ary" do
+    obj = mock('[1,2,3]')
+    obj.should_receive(:to_ary).and_return([1, 2, 3])
+    [0].send(@method, obj).should == ([0] | [1, 2, 3])
+  end
+
+  # MRI follows hashing semantics here, so doesn't actually call eql?/hash for Fixnum/Symbol
+  it "acts as if using an intermediate hash to collect values" do
+    not_supported_on :opal do
+      [5.0, 4.0].send(@method, [5, 4]).should == [5.0, 4.0, 5, 4]
+    end
+
+    str = "x"
+    [str].send(@method, [str.dup]).should == [str]
+
+    obj1 = mock('1')
+    obj2 = mock('2')
+    obj1.stub!(:hash).and_return(0)
+    obj2.stub!(:hash).and_return(0)
+    obj2.should_receive(:eql?).at_least(1).and_return(true)
+
+    [obj1].send(@method, [obj2]).should == [obj1]
+    [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1]
+
+    obj1 = mock('3')
+    obj2 = mock('4')
+    obj1.stub!(:hash).and_return(0)
+    obj2.stub!(:hash).and_return(0)
+    obj2.should_receive(:eql?).at_least(1).and_return(false)
+
+    [obj1].send(@method, [obj2]).should == [obj1, obj2]
+    [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1, obj2]
+  end
+
+  it "does not return subclass instances for Array subclasses" do
+    ArraySpecs::MyArray[1, 2, 3].send(@method, []).should be_an_instance_of(Array)
+    ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
+    [].send(@method, ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
+  end
+
+  it "does not call to_ary on array subclasses" do
+    [1, 2].send(@method, ArraySpecs::ToAryArray[5, 6]).should == [1, 2, 5, 6]
+  end
+
+  it "properly handles an identical item even when its #eql? isn't reflexive" do
+    x = mock('x')
+    x.stub!(:hash).and_return(42)
+    x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+
+    [x].send(@method, [x]).should == [x]
+  end
+end
Index: spec/ruby/core/array/shared/difference.rb
===================================================================
--- spec/ruby/core/array/shared/difference.rb	(nonexistent)
+++ spec/ruby/core/array/shared/difference.rb	(revision 66622)
@@ -0,0 +1,78 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/difference.rb#L1
+describe :array_binary_difference, shared: true do
+  it "creates an array minus any items from other array" do
+    [].send(@method, [ 1, 2, 4 ]).should == []
+    [1, 2, 4].send(@method, []).should == [1, 2, 4]
+    [ 1, 2, 3, 4, 5 ].send(@method, [ 1, 2, 4 ]).should == [3, 5]
+  end
+
+  it "removes multiple items on the lhs equal to one on the rhs" do
+    [1, 1, 2, 2, 3, 3, 4, 5].send(@method, [1, 2, 4]).should == [3, 3, 5]
+  end
+
+  it "properly handles recursive arrays" do
+    empty = ArraySpecs.empty_recursive_array
+    empty.send(@method, empty).should == []
+
+    [].send(@method, ArraySpecs.recursive_array).should == []
+
+    array = ArraySpecs.recursive_array
+    array.send(@method, array).should == []
+  end
+
+  it "tries to convert the passed arguments to Arrays using #to_ary" do
+    obj = mock('[2,3,3,4]')
+    obj.should_receive(:to_ary).and_return([2, 3, 3, 4])
+    [1, 1, 2, 2, 3, 4].send(@method, obj).should == [1, 1]
+  end
+
+  it "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do
+    obj = mock('not an array')
+    lambda { [1, 2, 3].send(@method, obj) }.should raise_error(TypeError)
+  end
+
+  it "does not return subclass instance for Array subclasses" do
+    ArraySpecs::MyArray[1, 2, 3].send(@method, []).should be_an_instance_of(Array)
+    ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[]).should be_an_instance_of(Array)
+    [1, 2, 3].send(@method, ArraySpecs::MyArray[]).should be_an_instance_of(Array)
+  end
+
+  it "does not call to_ary on array subclasses" do
+    [5, 6, 7].send(@method, ArraySpecs::ToAryArray[7]).should == [5, 6]
+  end
+
+  it "removes an item identified as equivalent via #hash and #eql?" do
+    obj1 = mock('1')
+    obj2 = mock('2')
+    obj1.stub!(:hash).and_return(0)
+    obj2.stub!(:hash).and_return(0)
+    obj1.should_receive(:eql?).at_least(1).and_return(true)
+
+    [obj1].send(@method, [obj2]).should == []
+    [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == []
+  end
+
+  it "doesn't remove an item with the same hash but not #eql?" do
+    obj1 = mock('1')
+    obj2 = mock('2')
+    obj1.stub!(:hash).and_return(0)
+    obj2.stub!(:hash).and_return(0)
+    obj1.should_receive(:eql?).at_least(1).and_return(false)
+
+    [obj1].send(@method, [obj2]).should == [obj1]
+    [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1, obj1]
+  end
+
+  it "removes an identical item even when its #eql? isn't reflexive" do
+    x = mock('x')
+    x.stub!(:hash).and_return(42)
+    x.stub!(:eql?).and_return(false) # Stubbed  (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]