ruby-changes:61438
From: Benoit <ko1@a...>
Date: Mon, 1 Jun 2020 01:23:43 +0900 (JST)
Subject: [ruby-changes:61438] 34776105c8 (master): Update to ruby/spec@4e486fa
https://git.ruby-lang.org/ruby.git/commit/?id=34776105c8 From 34776105c8a6739ca3aad1de4a2c942f4a8f2f29 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Sun, 31 May 2020 18:22:49 +0200 Subject: Update to ruby/spec@4e486fa diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md index 50d8af5..8d18f11 100644 --- a/spec/ruby/CONTRIBUTING.md +++ b/spec/ruby/CONTRIBUTING.md @@ -59,8 +59,8 @@ There are a few extra specific matchers used in the couple specs that need it. https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L59 (1 + 2).should == 3 # Calls #== (1 + 2).should_not == 5 -File.should equal(File) # Calls #equal? (tests identity) -(1 + 2).should eql(3) # Calls #eql? (Hash equality) +File.should.equal?(File) # Calls #equal? (tests identity) +(1 + 2).should.eql?(3) # Calls #eql? (Hash equality) 1.should < 2 2.should <= 2 @@ -73,11 +73,14 @@ File.should equal(File) # Calls #equal? (tests identity) https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L73 #### Predicate matchers ```ruby -[].should be_empty # Calls #empty? -[1,2,3].should include(2) # Calls #include? +[].should.empty? +[1,2,3].should.include?(2) + +"hello".should.start_with?("h") +"hello".should.end_with?("o") (0.1 + 0.2).should be_close(0.3, TOLERANCE) # (0.2-0.1).abs < TOLERANCE -(0.0/0.0).should be_nan # Calls Float#nan? +(0.0/0.0).should.nan? (1.0/0.0).should be_positive_infinity (-1.0/0.0).should be_negative_infinity @@ -85,7 +88,7 @@ File.should equal(File) # Calls #equal? (tests identity) https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L88 3.14.should be_kind_of(Numeric) # Calls #is_a? Numeric.should be_ancestor_of(Float) # Float.ancestors.include?(Numeric) -3.14.should respond_to(:to_i) # Calls #respond_to? +3.14.should.respond_to?(:to_i) Fixnum.should have_instance_method(:+) Array.should have_method(:new) ``` @@ -103,7 +106,7 @@ Also `have_constant`, `have_private_instance_method`, `have_singleton_method`, e https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L106 raise "oops" }.should raise_error(RuntimeError) { |e| # Custom checks on the Exception object - e.message.should include("oops") + e.message.should.include?("oops") e.cause.should == nil } ``` diff --git a/spec/ruby/core/array/fixtures/classes.rb b/spec/ruby/core/array/fixtures/classes.rb index 42071ed..2791a2e 100644 --- a/spec/ruby/core/array/fixtures/classes.rb +++ b/spec/ruby/core/array/fixtures/classes.rb @@ -144,7 +144,7 @@ module ArraySpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/fixtures/classes.rb#L144 end def self.universal_pack_object - obj = mock("string float int") + obj = mock("string float int".freeze) obj.stub!(:to_int).and_return(1) obj.stub!(:to_str).and_return("1") obj.stub!(:to_f).and_return(1.0) diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb index d6b4547..f36890f 100644 --- a/spec/ruby/core/array/shared/slice.rb +++ b/spec/ruby/core/array/shared/slice.rb @@ -466,6 +466,12 @@ describe :array_slice, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/slice.rb#L466 obj = 8e19 -> { array.send(@method, obj) }.should raise_error(RangeError) + + # boundary value when longs are 64 bits + -> { array.send(@method, 2.0**63) }.should raise_error(RangeError) + + # just under the boundary value when longs are 64 bits + array.send(@method, max_long.to_f.prev_float).should == nil end it "raises a RangeError when the length is out of range of Fixnum" do diff --git a/spec/ruby/core/enumerator/new_spec.rb b/spec/ruby/core/enumerator/new_spec.rb index 15e42d2..100edc8 100644 --- a/spec/ruby/core/enumerator/new_spec.rb +++ b/spec/ruby/core/enumerator/new_spec.rb @@ -75,5 +75,36 @@ describe "Enumerator.new" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/new_spec.rb#L75 enum.to_a.should == ["a\n", "b\n", "c"] end end + + describe 'yielded values' do + it 'handles yield arguments properly' do + Enumerator.new { |y| y.yield(1) }.to_a.should == [1] + Enumerator.new { |y| y.yield(1) }.first.should == 1 + + Enumerator.new { |y| y.yield([1]) }.to_a.should == [[1]] + Enumerator.new { |y| y.yield([1]) }.first.should == [1] + + Enumerator.new { |y| y.yield(1, 2) }.to_a.should == [[1, 2]] + Enumerator.new { |y| y.yield(1, 2) }.first.should == [1, 2] + + Enumerator.new { |y| y.yield([1, 2]) }.to_a.should == [[1, 2]] + Enumerator.new { |y| y.yield([1, 2]) }.first.should == [1, 2] + end + + it 'handles << arguments properly' do + Enumerator.new { |y| y.<<(1) }.to_a.should == [1] + Enumerator.new { |y| y.<<(1) }.first.should == 1 + + Enumerator.new { |y| y.<<([1]) }.to_a.should == [[1]] + Enumerator.new { |y| y.<<([1]) }.first.should == [1] + + # << doesn't accept multiple arguments + # Enumerator.new { |y| y.<<(1, 2) }.to_a.should == [[1, 2]] + # Enumerator.new { |y| y.<<(1, 2) }.first.should == [1, 2] + + Enumerator.new { |y| y.<<([1, 2]) }.to_a.should == [[1, 2]] + Enumerator.new { |y| y.<<([1, 2]) }.first.should == [1, 2] + end + end end end diff --git a/spec/ruby/core/enumerator/yielder/append_spec.rb b/spec/ruby/core/enumerator/yielder/append_spec.rb index dac6658..7f70597 100644 --- a/spec/ruby/core/enumerator/yielder/append_spec.rb +++ b/spec/ruby/core/enumerator/yielder/append_spec.rb @@ -21,4 +21,27 @@ describe "Enumerator::Yielder#<<" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/yielder/append_spec.rb#L21 y = Enumerator::Yielder.new {|x| x + 1} (y << 1).should equal(y) end + + context "when multiple arguments passed" do + ruby_version_is '' ... '2.6' do + it "yields the arguments list to the block" do + ary = [] + y = Enumerator::Yielder.new { |*x| ary << x } + y.<<(1, 2) + + ary.should == [[1, 2]] + end + end + + ruby_version_is '2.6' do + it "raises an ArgumentError" do + ary = [] + y = Enumerator::Yielder.new { |*x| ary << x } + + -> { + y.<<(1, 2) + }.should raise_error(ArgumentError, /wrong number of arguments/) + end + end + end end diff --git a/spec/ruby/core/enumerator/yielder/yield_spec.rb b/spec/ruby/core/enumerator/yielder/yield_spec.rb index 58fc8e0..acfdf11 100644 --- a/spec/ruby/core/enumerator/yielder/yield_spec.rb +++ b/spec/ruby/core/enumerator/yielder/yield_spec.rb @@ -20,4 +20,14 @@ describe "Enumerator::Yielder#yield" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/yielder/yield_spec.rb#L20 y = Enumerator::Yielder.new {|x| x + 1} y.yield(1).should == 2 end + + context "when multiple arguments passed" do + it "yields the arguments list to the block" do + ary = [] + y = Enumerator::Yielder.new { |*x| ary << x } + y.yield(1, 2) + + ary.should == [[1, 2]] + end + end end diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb index 4b5ef93..f9a8c9b 100644 --- a/spec/ruby/core/integer/left_shift_spec.rb +++ b/spec/ruby/core/integer/left_shift_spec.rb @@ -71,8 +71,11 @@ describe "Integer#<< (with n << m)" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/integer/left_shift_spec.rb#L71 it "calls #to_int to convert the argument to an Integer" do obj = mock("4") obj.should_receive(:to_int).and_return(4) - (3 << obj).should == 48 + + obj = mock("to_int_neg_bignum") + obj.should_receive(:to_int).and_return(-bignum_value) + (3 << obj).should == 0 end it "raises a TypeError when #to_int does not return an Integer" do diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb index 3eeaf3e..1eac6cb 100644 --- a/spec/ruby/core/integer/right_shift_spec.rb +++ b/spec/ruby/core/integer/right_shift_spec.rb @@ -71,8 +71,11 @@ describe "Integer#>> (with n >> m)" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/integer/right_shift_spec.rb#L71 it "calls #to_int to convert the argument to an Integer" do obj = mock("2") obj.should_receive(:to_int).and_return(2) - (8 >> obj).should == 2 + + obj = mock("to_int_bignum") + obj.should_receive(:to_int).and_return(bignum_value) + (8 >> obj).should == 0 end it "raises a TypeError when #to_int does not return an Integer" do diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb index 6997719..28fdb5e 100644 --- a/spec/ruby/core/kernel/shared/require.rb +++ b/spec/ruby/core/kernel/shared/require.rb @@ -242,6 +242,15 @@ describe :kernel_require, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/shared/require.rb#L242 @object.require("load_fixture").should be_true ScratchPad.recorded.should == [:loaded] end + + ruby_bug "#16926", "2.7"..."2.8" do + it "does not load a feature twice when $LOAD_PATH has been modified" do + $LOAD_PATH.replace [CODE_LOADING_DIR] + @object.require("load_fixture").should be_true + $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR] + @object.require("load_fixture").should be_false + end + end end describe "(file extensions)" do diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index 6f0ca49..85a0d06 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -294,6 +294,32 @@ describe "Module#autoload" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/autoload_spec.rb#L294 ScratchPad.recorded.should == [nil, nil] @check.call.should == ["constant", nil] end + + it "does not raise an error if the autoload constant was not def (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/