ruby-changes:61957
From: Benoit <ko1@a...>
Date: Sat, 27 Jun 2020 22:52:50 +0900 (JST)
Subject: [ruby-changes:61957] b3fa158d1c (master): Update to ruby/spec@b6b7752
https://git.ruby-lang.org/ruby.git/commit/?id=b3fa158d1c From b3fa158d1c4d8e03b8dc04f1e4f9940a8a4ef44c Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Sat, 27 Jun 2020 15:51:37 +0200 Subject: Update to ruby/spec@b6b7752 diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml index 54780ed..5370d99 100644 --- a/spec/ruby/.rubocop.yml +++ b/spec/ruby/.rubocop.yml @@ -15,6 +15,10 @@ Layout/TrailingEmptyLines: https://github.com/ruby/ruby/blob/trunk/spec/ruby/.rubocop.yml#L15 Exclude: - library/coverage/fixtures/some_class.rb +Layout/SpaceInLambdaLiteral: + Enabled: true + EnforcedStyle: require_space + Lint: Enabled: true diff --git a/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh b/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh index 0eede2a..fd3249f 100644 --- a/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh +++ b/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh#L1 #!/usr/bin/env bash -exec somehow this file +echo 'error' && exit 1 #!ruby puts 'success' diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb index 09066d6..2e01e83 100644 --- a/spec/ruby/core/array/element_set_spec.rb +++ b/spec/ruby/core/array/element_set_spec.rb @@ -323,6 +323,10 @@ describe "Array#[]= with [index, count]" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/element_set_spec.rb#L323 b = [1, 2, 3, 4, 5] b[10, 0] = [1] a.should == [1, 2, 3, 4, 5, nil, nil, nil, nil, nil, 1] + + c = [1, 2, 3, 4, 5] + c[10, 0] = [] + c.should == [1, 2, 3, 4, 5, nil, nil, nil, nil, nil] end it "inserts other section in place defined by idx" do diff --git a/spec/ruby/core/exception/top_level_spec.rb b/spec/ruby/core/exception/top_level_spec.rb new file mode 100644 index 0000000..96f9574 --- /dev/null +++ b/spec/ruby/core/exception/top_level_spec.rb @@ -0,0 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/exception/top_level_spec.rb#L1 +require_relative '../../spec_helper' + +describe "An Exception reaching the top level" do + it "is printed on STDERR" do + ruby_exe('raise "foo"', args: "2>&1").should.include?("in `<main>': foo (RuntimeError)") + end + + describe "with a custom backtrace" do + it "is printed on STDERR" do + code = <<-RUBY + raise RuntimeError, "foo", [ + "/dir/foo.rb:10:in `raising'", + "/dir/bar.rb:20:in `caller'", + ] + RUBY + ruby_exe(code, args: "2>&1").should == <<-EOS +/dir/foo.rb:10:in `raising': foo (RuntimeError) +\tfrom /dir/bar.rb:20:in `caller' + EOS + end + end +end diff --git a/spec/ruby/core/integer/pow_spec.rb b/spec/ruby/core/integer/pow_spec.rb index d7561ba..4712911 100644 --- a/spec/ruby/core/integer/pow_spec.rb +++ b/spec/ruby/core/integer/pow_spec.rb @@ -43,5 +43,9 @@ describe "Integer#pow" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/integer/pow_spec.rb#L43 it "raises a ZeroDivisionError when the given argument is 0" do -> { 2.pow(5, 0) }.should raise_error(ZeroDivisionError) end + + it "raises a RangeError when the first argument is negative and the second argument is present" do + -> { 2.pow(-5, 1) }.should raise_error(RangeError) + end end end diff --git a/spec/ruby/core/io/ungetbyte_spec.rb b/spec/ruby/core/io/ungetbyte_spec.rb index 1971dee..9d189f8 100644 --- a/spec/ruby/core/io/ungetbyte_spec.rb +++ b/spec/ruby/core/io/ungetbyte_spec.rb @@ -66,6 +66,10 @@ describe "IO#ungetbyte" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/ungetbyte_spec.rb#L66 end end + it "raises IOError on stream not opened for reading" do + -> { STDOUT.ungetbyte(42) }.should raise_error(IOError, "not opened for reading") + end + it "raises an IOError if the IO is closed" do @io.close -> { @io.ungetbyte(42) }.should raise_error(IOError) diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb index 85c15b5..dc31c37 100644 --- a/spec/ruby/core/io/ungetc_spec.rb +++ b/spec/ruby/core/io/ungetc_spec.rb @@ -136,6 +136,10 @@ describe "IO#ungetc" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/ungetc_spec.rb#L136 @io.ungetc(100).should be_nil end + it "raises IOError on stream not opened for reading" do + -> { STDOUT.ungetc(100) }.should raise_error(IOError, "not opened for reading") + end + it "raises IOError on closed stream" do @io.getc @io.close diff --git a/spec/ruby/core/kernel/initialize_copy_spec.rb b/spec/ruby/core/kernel/initialize_copy_spec.rb new file mode 100644 index 0000000..fe08d18 --- /dev/null +++ b/spec/ruby/core/kernel/initialize_copy_spec.rb @@ -0,0 +1,29 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/initialize_copy_spec.rb#L1 +require_relative '../../spec_helper' + +describe "Kernel#initialize_copy" do + it "does nothing if the argument is the same as the receiver" do + obj = Object.new + obj.send(:initialize_copy, obj).should.equal?(obj) + obj.freeze + obj.send(:initialize_copy, obj).should.equal?(obj) + 1.send(:initialize_copy, 1).should.equal?(1) + end + + it "raises FrozenError if the receiver is frozen" do + -> { Object.new.freeze.send(:initialize_copy, Object.new) }.should raise_error(FrozenError) + -> { 1.send(:initialize_copy, Object.new) }.should raise_error(FrozenError) + end + + it "raises TypeError if the objects are of different class" do + klass = Class.new + sub = Class.new(klass) + a = klass.new + b = sub.new + message = 'initialize_copy should take same class object' + -> { a.send(:initialize_copy, b) }.should raise_error(TypeError, message) + -> { b.send(:initialize_copy, a) }.should raise_error(TypeError, message) + + -> { a.send(:initialize_copy, 1) }.should raise_error(TypeError, message) + -> { a.send(:initialize_copy, 1.0) }.should raise_error(TypeError, message) + end +end diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index 3930715..7b4493d 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -36,27 +36,31 @@ describe "Kernel.proc" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/proc_spec.rb#L36 end describe "Kernel#proc" do + def some_method + proc + end + ruby_version_is ""..."2.7" do it "uses the implicit block from an enclosing method" do - def some_method - proc - end - prc = some_method { "hello" } prc.call.should == "hello" end end - ruby_version_is "2.7" ... "2.8" do + ruby_version_is "2.7"..."2.8" do it "can be created when called with no block" do - def some_method - proc - end - -> { some_method { "hello" } }.should complain(/Capturing the given block using Kernel#proc is deprecated/) end end + + ruby_version_is "2.8" do + it "raises an ArgumentError when passed no block" do + -> { + some_method { "hello" } + }.should raise_error(ArgumentError, 'tried to create Proc object without a block') + end + end end diff --git a/spec/ruby/core/kernel/srand_spec.rb b/spec/ruby/core/kernel/srand_spec.rb index 5454aae..0985c76 100644 --- a/spec/ruby/core/kernel/srand_spec.rb +++ b/spec/ruby/core/kernel/srand_spec.rb @@ -11,6 +11,10 @@ describe "Kernel.srand" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/srand_spec.rb#L11 srand(20).should == 10 end + it "returns the previous seed value on the first call" do + ruby_exe('p srand(10)', options: '--disable-gems').chomp.should =~ /\A\d+\z/ + end + it "seeds the RNG correctly and repeatably" do srand(10) x = rand diff --git a/spec/ruby/core/module/fixtures/refine.rb b/spec/ruby/core/module/fixtures/refine.rb index 4697536..79e2e80 100644 --- a/spec/ruby/core/module/fixtures/refine.rb +++ b/spec/ruby/core/module/fixtures/refine.rb @@ -10,4 +10,8 @@ module ModuleSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/fixtures/refine.rb#L10 module IncludedModule def foo; "foo from included module"; end end + + def self.build_refined_class + Class.new(ClassWithFoo) + end end diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb index 6df4fa4..ca12d5d 100644 --- a/spec/ruby/core/module/refine_spec.rb +++ b/spec/ruby/core/module/refine_spec.rb @@ -87,6 +87,31 @@ describe "Module#refine" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/refine_spec.rb#L87 inner_self.public_instance_methods.should include(:blah) end + it "applies refinements to the module" do + refinement = Module.new do + refine(Enumerable) do + def foo? + self.any? ? "yes" : "no" + end + end + end + + foo = Class.new do + using refinement + + def initialize(items) + @items = items + end + + def result + @items.foo? + end + end + + foo.new([]).result.should == "no" + foo.new([1]).result.should == "yes" + end + it "raises ArgumentError if not given a block" do -> do Module.new do @@ -196,8 +221,10 @@ describe "Module#refine" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/refine_spec.rb#L221 # * The included modules of C describe "method lookup" do it "looks in the object singleton class first" do + refined_class = ModuleSpecs.build_refined_class + refinement = Module.new do - refine ModuleSpecs::ClassWithFoo do + refine refined_class do def foo; "foo from refinement"; end end end @@ -206,7 +233,7 @@ describe "Module#refine" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/refine_spec.rb#L233 Module.new do using refinement - obj = ModuleSpecs::ClassWithFoo.new + obj = refined_class.new (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/