ruby-changes:55885
From: Benoit <ko1@a...>
Date: Wed, 29 May 2019 05:45:38 +0900 (JST)
Subject: [ruby-changes:55885] Benoit Daloze: a66bc2c011 (trunk): Update to ruby/spec@9a501a8
https://git.ruby-lang.org/ruby.git/commit/?id=a66bc2c011 From a66bc2c01194a9c017c874a30db5b3b6bd95e966 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Tue, 28 May 2019 22:41:48 +0200 Subject: Update to ruby/spec@9a501a8 diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md index dd33f7b..2f9b138 100644 --- a/spec/ruby/CONTRIBUTING.md +++ b/spec/ruby/CONTRIBUTING.md @@ -188,7 +188,7 @@ variables from the implementor spec: `@method` and `@object`, which the implemen https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L188 Here's an example of a snippet of a shared spec and two specs which integrates it: -``` ruby +```ruby # core/hash/shared/key.rb describe :hash_key_p, shared: true do it "returns true if the key's matching value was false" do @@ -216,7 +216,7 @@ Sometimes, shared specs require more context from the implementor class than a s https://github.com/ruby/ruby/blob/trunk/spec/ruby/CONTRIBUTING.md#L216 this by passing a lambda as the method, which will have the scope of the implementor. Here's an example of how this is used currently: -``` ruby +```ruby describe :kernel_sprintf, shared: true do it "raises TypeError exception if cannot convert to Integer" do -> { @method.call("%b", Object.new) }.should raise_error(TypeError) diff --git a/spec/ruby/core/enumerable/shared/find.rb b/spec/ruby/core/enumerable/shared/find.rb index 5c09750..3435ce3 100644 --- a/spec/ruby/core/enumerable/shared/find.rb +++ b/spec/ruby/core/enumerable/shared/find.rb @@ -49,6 +49,10 @@ describe :enumerable_find, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerable/shared/find.rb#L49 @empty.send(@method, fail_proc) {|e| true}.should == "yay" end + it "ignores the ifnone argument when nil" do + @numerous.send(@method, nil) {|e| false }.should == nil + end + it "passes through the values yielded by #each_with_index" do [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil } ScratchPad.recorded.should == [[:a, 0], [:b, 1]] diff --git a/spec/ruby/core/exception/backtrace_spec.rb b/spec/ruby/core/exception/backtrace_spec.rb index 70c75bd..5e140f8 100644 --- a/spec/ruby/core/exception/backtrace_spec.rb +++ b/spec/ruby/core/exception/backtrace_spec.rb @@ -65,4 +65,19 @@ describe "Exception#backtrace" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/exception/backtrace_spec.rb#L65 e.backtrace[0].should == "backtrace first" end end + + it "returns the same array after duping" do + begin + raise + rescue RuntimeError => err + bt = err.backtrace + err.dup.backtrace.should equal(bt) + + new_bt = ['hi'] + err.set_backtrace new_bt + + err.backtrace.should == new_bt + err.dup.backtrace.should equal(new_bt) + end + end end diff --git a/spec/ruby/core/exception/cause_spec.rb b/spec/ruby/core/exception/cause_spec.rb index 007df41..cf4aaeb 100644 --- a/spec/ruby/core/exception/cause_spec.rb +++ b/spec/ruby/core/exception/cause_spec.rb @@ -41,4 +41,16 @@ describe "Exception#cause" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/exception/cause_spec.rb#L41 e.cause.should equal(cause) } end + + it "is not set to the exception itself when it is re-raised" do + -> { + begin + raise RuntimeError + rescue RuntimeError => e + raise e + end + }.should raise_error(RuntimeError) { |e| + e.cause.should == nil + } + end end diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index 90aa44e..1d97202 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -225,6 +225,8 @@ platform_is_not :windows do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/expand_path_spec.rb#L225 user = ENV.delete("USER") begin Etc.getlogin != nil + rescue + false ensure ENV["USER"] = user end diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb index d32117b..14674a0 100644 --- a/spec/ruby/core/hash/constructor_spec.rb +++ b/spec/ruby/core/hash/constructor_spec.rb @@ -54,7 +54,7 @@ describe "Hash.[]" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/constructor_spec.rb#L54 end ruby_version_is "2.7" do - it "ignores elements that are not arrays" do + it "raises for elements that are not arrays" do -> { Hash[[:a]].should == {} }.should raise_error(ArgumentError) diff --git a/spec/ruby/core/hash/hash_spec.rb b/spec/ruby/core/hash/hash_spec.rb index 7c26f02..3649d4d 100644 --- a/spec/ruby/core/hash/hash_spec.rb +++ b/spec/ruby/core/hash/hash_spec.rb @@ -11,6 +11,14 @@ describe "Hash#hash" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/hash_spec.rb#L11 { 0=>2, 11=>1 }.hash.should == { 11=>1, 0=>2 }.hash end + it "returns a value in which element values do not cancel each other out" do + { a: 2, b: 2 }.hash.should_not == { a: 7, b: 7 }.hash + end + + it "returns a value in which element keys and values do not cancel each other out" do + { :a => :a }.hash.should_not == { :b => :b }.hash + end + it "generates a hash for recursive hash structures" do h = {} h[:a] = h diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb index e90beae..54abcb81 100644 --- a/spec/ruby/core/hash/merge_spec.rb +++ b/spec/ruby/core/hash/merge_spec.rb @@ -63,6 +63,24 @@ describe "Hash#merge" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/merge_spec.rb#L63 merge_pairs.should == each_pairs end + it "preserves the order of merged elements" do + h1 = { 1 => 2, 3 => 4, 5 => 6 } + h2 = { 1 => 7 } + merge_pairs = [] + h1.merge(h2).each_pair { |k, v| merge_pairs << [k, v] } + merge_pairs.should == [[1,7], [3, 4], [5, 6]] + end + + it "preserves the order of merged elements for large hashes" do + h1 = {} + h2 = {} + merge_pairs = [] + expected_pairs = [] + (1..100).each { |x| h1[x] = x; h2[101 - x] = x; expected_pairs << [x, 101 - x] } + h1.merge(h2).each_pair { |k, v| merge_pairs << [k, v] } + merge_pairs.should == expected_pairs + end + ruby_version_is "2.6" do it "accepts multiple hashes" do result = { a: 1 }.merge({ b: 2 }, { c: 3 }, { d: 4 }) diff --git a/spec/ruby/core/kernel/autoload_spec.rb b/spec/ruby/core/kernel/autoload_spec.rb index 3e7a63e..68732a6 100644 --- a/spec/ruby/core/kernel/autoload_spec.rb +++ b/spec/ruby/core/kernel/autoload_spec.rb @@ -57,7 +57,7 @@ describe "Kernel#autoload" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/autoload_spec.rb#L57 end describe "when Object is frozen" do - it "raises a FrozenError before defining the constant" do + it "raises a #{frozen_error_class} before defining the constant" do ruby_exe(fixture(__FILE__, "autoload_frozen.rb")).should == "#{frozen_error_class} - nil" end end diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb index b041a95..53a0b31 100644 --- a/spec/ruby/core/marshal/dump_spec.rb +++ b/spec/ruby/core/marshal/dump_spec.rb @@ -449,14 +449,13 @@ describe "Marshal.dump" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/marshal/dump_spec.rb#L449 zone = ":\tzoneI\"\bAST\x06:\x06EF" # Last is 'F' (US-ASCII) [ "#{base}#{offset}#{zone}", "#{base}#{zone}#{offset}" ].should include(dump) end - - it "dumps the zone, but not the offset if zone is UTC" do - dump = Marshal.dump(@utc) - zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII) - dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}" - end end + it "dumps the zone, but not the offset if zone is UTC" do + dump = Marshal.dump(@utc) + zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII) + dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}" + end end describe "with an Exception" do diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index 5b0fd88..d646843 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -15,13 +15,13 @@ describe "Module#name" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/name_spec.rb#L15 it "is not nil for a nested module created with the module keyword" do m = Module.new module m::N; end - m::N.name.should =~ /#<Module:0x[0-9a-f]+>::N/ + m::N.name.should =~ /\A#<Module:0x[0-9a-f]+>::N\z/ end it "changes when the module is reachable through a constant path" do m = Module.new module m::N; end - m::N.name.should =~ /#<Module:0x[0-9a-f]+>::N/ + m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ ModuleSpecs::Anonymous::WasAnnon = m::N m::N.name.should == "ModuleSpecs::Anonymous::WasAnnon" end @@ -42,7 +42,7 @@ describe "Module#name" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/name_spec.rb#L42 module m::Child; end child = m::Child m.send(:remove_const, :Child) - child.name.should =~ /#<Module:0x[0-9a-f]+>::Child/ + child.name.should =~ /\A#<Module:0x\h+>::Child\z/ end it "is set when opened with the module keyword" do diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index 7579bfe..60a7320 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -190,6 +190,17 @@ describe "Proc.new without a block" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/proc/new_spec.rb#L190 prc.call.should == "hello" end + + it "uses the implicit block from an enclosing method when called inside a block" do + def some_method + proc do |&block| + Proc.new + end.call { "failing" } + end + prc = some_method { "hello" } + + prc.call.should == "hello" + end end ruby (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/