ruby-changes:58462
From: Benoit <ko1@a...>
Date: Sun, 27 Oct 2019 03:54:34 +0900 (JST)
Subject: [ruby-changes:58462] 664e96b1de (master): Update to ruby/spec@28a728b
https://git.ruby-lang.org/ruby.git/commit/?id=664e96b1de From 664e96b1de816c813c29f61e16a2031a7af7ba86 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Sat, 26 Oct 2019 20:53:01 +0200 Subject: Update to ruby/spec@28a728b diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml index cc31ff5..77e4e78 100644 --- a/spec/ruby/.rubocop.yml +++ b/spec/ruby/.rubocop.yml @@ -77,6 +77,13 @@ Lint/NestedMethodDefinition: https://github.com/ruby/ruby/blob/trunk/spec/ruby/.rubocop.yml#L77 - language/def_spec.rb - language/fixtures/def.rb +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'core/binding/local_variables_spec.rb' + - 'core/kernel/local_variables_spec.rb' + - 'language/block_spec.rb' + - 'language/proc_spec.rb' + Lint/UnreachableCode: Exclude: - 'core/enumerator/lazy/fixtures/classes.rb' diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml index 261fde9..aac54f6 100644 --- a/spec/ruby/.rubocop_todo.yml +++ b/spec/ruby/.rubocop_todo.yml @@ -116,13 +116,6 @@ Lint/ShadowedArgument: https://github.com/ruby/ruby/blob/trunk/spec/ruby/.rubocop_todo.yml#L116 Exclude: - 'language/fixtures/super.rb' -# Offense count: 10 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'core/binding/local_variables_spec.rb' - - 'language/block_spec.rb' - - 'language/proc_spec.rb' - # Offense count: 2 # Cop supports --auto-correct. Lint/StringConversionInInterpolation: diff --git a/spec/ruby/core/enumerable/shared/collect.rb b/spec/ruby/core/enumerable/shared/collect.rb index 16bf3f0..05e9477 100644 --- a/spec/ruby/core/enumerable/shared/collect.rb +++ b/spec/ruby/core/enumerable/shared/collect.rb @@ -22,6 +22,12 @@ describe :enumerable_collect, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerable/shared/collect.rb#L22 multi.send(@method) {|e| e}.should == [1,3,6] end + it "only yields increasing values for a Range" do + (1..0).send(@method) { |x| x }.should == [] + (1..1).send(@method) { |x| x }.should == [1] + (1..2).send(@method) { |x| x }.should == [1, 2] + end + it "returns an enumerator when no block given" do enum = EnumerableSpecs::Numerous.new.send(@method) enum.should be_an_instance_of(Enumerator) diff --git a/spec/ruby/core/env/assoc_spec.rb b/spec/ruby/core/env/assoc_spec.rb index 853eca7..9946e32 100644 --- a/spec/ruby/core/env/assoc_spec.rb +++ b/spec/ruby/core/env/assoc_spec.rb @@ -1,8 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/assoc_spec.rb#L1 require_relative '../../spec_helper' describe "ENV.assoc" do + before :each do + @foo = ENV["foo"] + end + after :each do - ENV.delete("foo") + ENV["foo"] = @foo end it "returns an array of the key and value of the environment variable with the given key" do @@ -20,4 +24,8 @@ describe "ENV.assoc" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/assoc_spec.rb#L24 k.should_receive(:to_str).and_return("foo") ENV.assoc(k).should == ["foo", "bar"] end + + it "raises TypeError if the argument is not a String and does not respond to #to_str" do + -> { ENV.assoc(Object.new) }.should raise_error(TypeError) + end end diff --git a/spec/ruby/core/env/clear_spec.rb b/spec/ruby/core/env/clear_spec.rb index fd0984a..48b034b 100644 --- a/spec/ruby/core/env/clear_spec.rb +++ b/spec/ruby/core/env/clear_spec.rb @@ -4,7 +4,7 @@ describe "ENV.clear" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/clear_spec.rb#L4 it "deletes all environment variables" do orig = ENV.to_hash begin - ENV.clear + ENV.clear.should equal(ENV) # This used 'env' the helper before. That shells out to 'env' which # itself sets up certain environment variables before it runs, because diff --git a/spec/ruby/core/env/delete_if_spec.rb b/spec/ruby/core/env/delete_if_spec.rb index d644431..d2de51c 100644 --- a/spec/ruby/core/env/delete_if_spec.rb +++ b/spec/ruby/core/env/delete_if_spec.rb @@ -2,14 +2,31 @@ require_relative '../../spec_helper' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/delete_if_spec.rb#L2 require_relative '../enumerable/shared/enumeratorized' describe "ENV.delete_if" do + before :each do + @foo = ENV["foo"] + @bar = ENV["bar"] + + ENV["foo"] = "0" + ENV["bar"] = "1" + end + + after :each do + ENV["foo"] = @foo + ENV["bar"] = @bar + end + it "deletes pairs if the block returns true" do - ENV["foo"] = "bar" - ENV.delete_if { |k, v| k == "foo" } + ENV.delete_if { |k, v| ["foo", "bar"].include?(k) } ENV["foo"].should == nil + ENV["bar"].should == nil + end + + it "returns ENV when block given" do + ENV.delete_if { |k, v| ["foo", "bar"].include?(k) }.should equal(ENV) end it "returns ENV even if nothing deleted" do - ENV.delete_if { false }.should_not == nil + ENV.delete_if { false }.should equal(ENV) end it "returns an Enumerator if no block given" do @@ -17,10 +34,20 @@ describe "ENV.delete_if" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/delete_if_spec.rb#L34 end it "deletes pairs through enumerator" do - ENV["foo"] = "bar" enum = ENV.delete_if - enum.each { |k, v| k == "foo" } + enum.each { |k, v| ["foo", "bar"].include?(k) } ENV["foo"].should == nil + ENV["bar"].should == nil + end + + it "returns ENV from enumerator" do + enum = ENV.delete_if + enum.each { |k, v| ["foo", "bar"].include?(k) }.should equal(ENV) + end + + it "returns ENV from enumerator even if nothing deleted" do + enum = ENV.delete_if + enum.each { false }.should equal(ENV) end it_behaves_like :enumeratorized_with_origin_size, :delete_if, ENV diff --git a/spec/ruby/core/env/delete_spec.rb b/spec/ruby/core/env/delete_spec.rb index 1e677fb..e875df4 100644 --- a/spec/ruby/core/env/delete_spec.rb +++ b/spec/ruby/core/env/delete_spec.rb @@ -1,8 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/delete_spec.rb#L1 require_relative '../../spec_helper' describe "ENV.delete" do + before :each do + @saved_foo = ENV["foo"] + end after :each do - ENV.delete("foo") + ENV["foo"] = @saved_foo end it "removes the variable from the environment" do @@ -16,9 +19,18 @@ describe "ENV.delete" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/delete_spec.rb#L19 ENV.delete("foo").should == "bar" end + it "returns nil if the named environment variable does not exist and no block given" do + ENV.delete("foo") + ENV.delete("foo").should == nil + end + it "yields the name to the given block if the named environment variable does not exist" do ENV.delete("foo") ENV.delete("foo") { |name| ScratchPad.record name } ScratchPad.recorded.should == "foo" end + + it "raises TypeError if the argument is not a String and does not respond to #to_str" do + -> { ENV.delete(Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String") + end end diff --git a/spec/ruby/core/env/each_key_spec.rb b/spec/ruby/core/env/each_key_spec.rb index 294bf39..5c5cf4f 100644 --- a/spec/ruby/core/env/each_key_spec.rb +++ b/spec/ruby/core/env/each_key_spec.rb @@ -19,7 +19,9 @@ describe "ENV.each_key" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/each_key_spec.rb#L19 end it "returns an Enumerator if called without a block" do - ENV.each_key.should be_an_instance_of(Enumerator) + enum = ENV.each_key + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == ENV.keys end it "returns keys in the locale encoding" do diff --git a/spec/ruby/core/env/each_value_spec.rb b/spec/ruby/core/env/each_value_spec.rb index 88f4bc4..ea29b3a 100644 --- a/spec/ruby/core/env/each_value_spec.rb +++ b/spec/ruby/core/env/each_value_spec.rb @@ -19,7 +19,9 @@ describe "ENV.each_value" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/each_value_spec.rb#L19 end it "returns an Enumerator if called without a block" do - ENV.each_value.should be_an_instance_of(Enumerator) + enum = ENV.each_value + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == ENV.values end it "uses the locale encoding" do diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb index 59b53fc..7d2a2d7 100644 --- a/spec/ruby/core/env/element_reference_spec.rb +++ b/spec/ruby/core/env/element_reference_spec.rb @@ -19,6 +19,17 @@ describe "ENV.[]" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/element_reference_spec.rb#L19 ENV[@variable].frozen?.should == true end + it "coerces a non-string name with #to_str" do + ENV[@variable] = "bar" + k = mock('key') + k.should_receive(:to_str).and_return(@variable) + ENV[k].should == "bar" + end + + it "raises TypeError if the argument is not a String and does not respond to #to_str" do + -> { ENV[Object.new] }.should raise_error(TypeError, "no implicit conversion of Object into String") + end + platform_is :windows do it "looks up values case-insensitively" do ENV[@variable] = "bar" diff --git a/spec/ruby/core/env/fetch_spec.rb b/spec/ruby/core/env/fetch_spec.rb index eeaf290..ef8f0a4 100644 --- a/spec/ruby/core/env/fetch_spec.rb +++ b/spec/ruby/core/env/fetch_spec.rb @@ -2,14 +2,20 @@ require_relative '../../spec_helper' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/fetch_spec.rb#L2 require_relative '../../shared/hash/key_error' describe "ENV.fetch" do + before :each do + @foo_saved = ENV.delete("foo") + end + after :each do + ENV["foo"] = @saved_foo + end + it "returns a value" do ENV["foo"] = "bar" ENV.fetch("foo").should == "bar" - ENV.delete "foo" end it "raises a TypeError if the key is not a String" do - -> { ENV.fetch :should_never_be_set }.should raise_error(TypeError) + -> { ENV.fetch Object.new }.should raise_error(TypeError, "no impli (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/