ruby-changes:49203
From: eregon <ko1@a...>
Date: Mon, 18 Dec 2017 16:14:03 +0900 (JST)
Subject: [ruby-changes:49203] eregon:r61285 (trunk): Update to ruby/spec@595645f
eregon 2017-12-16 02:44:37 +0900 (Sat, 16 Dec 2017) New Revision: 61285 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61285 Log: Update to ruby/spec@595645f Added files: trunk/spec/ruby/core/dir/children_spec.rb trunk/spec/ruby/core/dir/each_child_spec.rb trunk/spec/ruby/core/hash/slice_spec.rb trunk/spec/ruby/core/hash/transform_keys_spec.rb trunk/spec/ruby/core/string/delete_prefix_spec.rb trunk/spec/ruby/core/string/delete_suffix_spec.rb trunk/spec/ruby/library/set/case_compare_spec.rb trunk/spec/ruby/library/set/shared/inspect.rb trunk/spec/ruby/library/set/to_s_spec.rb Modified files: trunk/spec/ruby/.rubocop.yml trunk/spec/ruby/.rubocop_todo.yml trunk/spec/ruby/.travis.yml trunk/spec/ruby/README.md trunk/spec/ruby/core/encoding/locale_charmap_spec.rb trunk/spec/ruby/core/enumerable/all_spec.rb trunk/spec/ruby/core/enumerable/none_spec.rb trunk/spec/ruby/core/enumerable/one_spec.rb trunk/spec/ruby/core/file/chown_spec.rb trunk/spec/ruby/core/file/shared/read.rb trunk/spec/ruby/core/file/stat/inspect_spec.rb trunk/spec/ruby/core/hash/transform_values_spec.rb trunk/spec/ruby/core/kernel/autoload_spec.rb trunk/spec/ruby/core/module/included_modules_spec.rb trunk/spec/ruby/core/module/refine_spec.rb trunk/spec/ruby/core/process/setsid_spec.rb trunk/spec/ruby/core/process/spawn_spec.rb trunk/spec/ruby/core/string/start_with_spec.rb trunk/spec/ruby/core/struct/new_spec.rb trunk/spec/ruby/core/time/at_spec.rb trunk/spec/ruby/language/constants_spec.rb trunk/spec/ruby/language/ensure_spec.rb trunk/spec/ruby/language/fixtures/ensure.rb trunk/spec/ruby/language/rescue_spec.rb trunk/spec/ruby/library/date/shared/valid_jd.rb trunk/spec/ruby/library/matrix/build_spec.rb trunk/spec/ruby/library/set/inspect_spec.rb trunk/spec/ruby/library/set/shared/include.rb trunk/spec/ruby/library/socket/udpsocket/new_spec.rb trunk/spec/ruby/library/stringio/pos_spec.rb Index: spec/ruby/core/hash/transform_values_spec.rb =================================================================== --- spec/ruby/core/hash/transform_values_spec.rb (revision 61284) +++ spec/ruby/core/hash/transform_values_spec.rb (revision 61285) @@ -16,6 +16,13 @@ ruby_version_is "2.4" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/transform_values_spec.rb#L16 @hash.transform_values(&:succ).should == { a: 2, b: 3, c: 4 } end + it "makes both hashes to share keys" do + key = [1, 2, 3] + new_hash = { key => 1 }.transform_values(&:succ) + new_hash[key].should == 2 + new_hash.keys[0].should equal(key) + end + context "when no block is given" do it "returns a sized Enumerator" do enumerator = @hash.transform_values @@ -47,7 +54,7 @@ ruby_version_is "2.4" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/transform_values_spec.rb#L54 it "updates self as transformed values with the given block" do @hash.transform_values!(&:succ) - @hash.should == { a: 2, b: 3, c: 4 } + @hash.should == { a: 2, b: 3, c: 4 } end it "partially modifies the contents if we broke from the block" do Index: spec/ruby/core/encoding/locale_charmap_spec.rb =================================================================== --- spec/ruby/core/encoding/locale_charmap_spec.rb (revision 61284) +++ spec/ruby/core/encoding/locale_charmap_spec.rb (revision 61285) @@ -16,7 +16,7 @@ with_feature :encoding do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/encoding/locale_charmap_spec.rb#L16 end end - platform_is :freebsd, :darwin do + platform_is :freebsd, :openbsd, :darwin do it "returns a value based on the LC_ALL environment variable" do old_lc_all = ENV['LC_ALL'] ENV['LC_ALL'] = 'C' @@ -25,7 +25,7 @@ with_feature :encoding do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/encoding/locale_charmap_spec.rb#L25 end end - platform_is :netbsd, :openbsd do + platform_is :netbsd do it "returns a value based on the LC_ALL environment variable" do old_lc_all = ENV['LC_ALL'] ENV['LC_ALL'] = 'C' Index: spec/ruby/library/stringio/pos_spec.rb =================================================================== --- spec/ruby/library/stringio/pos_spec.rb (revision 61284) +++ spec/ruby/library/stringio/pos_spec.rb (revision 61285) @@ -17,7 +17,7 @@ describe "StringIO#pos=" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/pos_spec.rb#L17 end it "raises an EINVAL if given a negative argument" do - lambda { @io.pos = -10 }.should raise_error(Errno::EINVAL) + lambda { @io.pos = -10 }.should raise_error(Errno::EINVAL) end it "updates the current byte offset after reaching EOF" do Index: spec/ruby/library/set/shared/inspect.rb =================================================================== --- spec/ruby/library/set/shared/inspect.rb (nonexistent) +++ spec/ruby/library/set/shared/inspect.rb (revision 61285) @@ -0,0 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/set/shared/inspect.rb#L1 +describe "set_inspect", shared: true do + it "returns a String representation of self" do + Set[].send(@method).should be_kind_of(String) + Set[nil, false, true].send(@method).should be_kind_of(String) + Set[1, 2, 3].send(@method).should be_kind_of(String) + Set["1", "2", "3"].send(@method).should be_kind_of(String) + Set[:a, "b", Set[?c]].send(@method).should be_kind_of(String) + end + + it "correctly handles self-references" do + (set = Set[]) << set + set.send(@method).should be_kind_of(String) + set.send(@method).should include("#<Set: {...}>") + end +end Property changes on: spec/ruby/library/set/shared/inspect.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: spec/ruby/library/set/inspect_spec.rb =================================================================== --- spec/ruby/library/set/inspect_spec.rb (revision 61284) +++ spec/ruby/library/set/inspect_spec.rb (revision 61285) @@ -1,18 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/set/inspect_spec.rb#L1 require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/inspect', __FILE__) require 'set' describe "Set#inspect" do - it "returns a String representation of self" do - Set[].inspect.should be_kind_of(String) - Set[nil, false, true].inspect.should be_kind_of(String) - Set[1, 2, 3].inspect.should be_kind_of(String) - Set["1", "2", "3"].inspect.should be_kind_of(String) - Set[:a, "b", Set[?c]].inspect.should be_kind_of(String) - end - - it "correctly handles self-references" do - (set = Set[]) << set - set.inspect.should be_kind_of(String) - set.inspect.should include("#<Set: {...}>") - end + it_behaves_like :set_inspect, :inspect end Index: spec/ruby/library/date/shared/valid_jd.rb =================================================================== --- spec/ruby/library/date/shared/valid_jd.rb (revision 61284) +++ spec/ruby/library/date/shared/valid_jd.rb (revision 61285) @@ -1,8 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/date/shared/valid_jd.rb#L1 describe :date_valid_jd?, shared: true do it "returns true if passed any value other than nil" do Date.send(@method, -100).should be_true - Date.send(@method, :number).should be_true - Date.send(@method, Rational(1,2)).should be_true + Date.send(@method, :number).should be_true + Date.send(@method, Rational(1,2)).should be_true end it "returns false if passed nil" do Index: spec/ruby/library/set/case_compare_spec.rb =================================================================== --- spec/ruby/library/set/case_compare_spec.rb (nonexistent) +++ spec/ruby/library/set/case_compare_spec.rb (revision 61285) @@ -0,0 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/set/case_compare_spec.rb#L1 +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/include', __FILE__) +require 'set' + +ruby_version_is "2.5" do + describe "Set#===" do + it_behaves_like :set_include, :=== + + it "is an alias for include?" do + set = Set.new + set.method(:===).should == set.method(:include?) + end + end +end + Property changes on: spec/ruby/library/set/case_compare_spec.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: spec/ruby/library/socket/udpsocket/new_spec.rb =================================================================== --- spec/ruby/library/socket/udpsocket/new_spec.rb (revision 61284) +++ spec/ruby/library/socket/udpsocket/new_spec.rb (revision 61285) @@ -26,7 +26,9 @@ describe 'UDPSocket.new' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/udpsocket/new_spec.rb#L26 @socket.should be_an_instance_of(UDPSocket) end - it 'raises Errno::EAFNOSUPPORT if unsupported family passed' do - lambda { UDPSocket.new(-1) }.should raise_error(Errno::EAFNOSUPPORT) + it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT if unsupported family passed' do + lambda { UDPSocket.new(-1) }.should raise_error(SystemCallError) { |e| + [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) + } end end Index: spec/ruby/language/fixtures/ensure.rb =================================================================== --- spec/ruby/language/fixtures/ensure.rb (revision 61284) +++ spec/ruby/language/fixtures/ensure.rb (revision 61285) @@ -8,7 +8,7 @@ module EnsureSpec https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/fixtures/ensure.rb#L8 def raise_in_method_with_ensure @executed << :method - raise "An Exception" + raise EnsureSpec::Error ensure @executed << :ensure end @@ -70,3 +70,8 @@ module EnsureSpec https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/fixtures/ensure.rb#L70 end end end + +module EnsureSpec + class Error < RuntimeError + end +end Index: spec/ruby/language/constants_spec.rb =================================================================== --- spec/ruby/language/constants_spec.rb (revision 61284) +++ spec/ruby/language/constants_spec.rb (revision 61285) @@ -425,6 +425,28 @@ describe "Constant resolution within a s https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/constants_spec.rb#L425 end end +describe "top-level constant lookup" do + context "on a class" do + ruby_version_is "" ... "2.5" do + it "searches Object successfully after searching other scopes" do + ->() { + String::Hash.should == Hash + }.should complain(/toplevel constant Hash referenced by/) + end + end + + ruby_version_is "2.5" do + it "does not search Object after searching other scopes" do + ->() { String::Hash }.should raise_error(NameError) + end + end + end + + it "searches Object unsuccessfully when searches on a module" do + ->() { Enumerable::Hash }.should raise_error(NameError) + end +end + describe "Module#private_constant marked constants" do it "remain private even when updated" do Index: spec/ruby/language/rescue_spec.rb =================================================================== --- spec/ruby/language/rescue_spec.rb (revision 61284) +++ spec/ruby/language/rescue_spec.rb (revision 61285) @@ -31,6 +31,28 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L31 end end + it "returns value from `rescue` if an exception was raised" do + begin + raise + rescue + :caught + end.should == :caught + end + + it "returns value from `else` section if no exceptions were raised" do + result = begin + :begin + rescue + :rescue + else + :else + ensure + :ensure + end + + result.should == :else + end + it "can rescue multiple raised exceptions with a single rescue block" do [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].map do |block| begin @@ -94,6 +116,32 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L116 end.should raise_error(OtherCustomException) end + it "can rescue different types of exceptions in different ways" do + begin + raise Exception + rescue RuntimeError + rescue StandardError + rescue Exception + ScratchPad << :exception + end + + ScratchPad.recorded.should == [:exception] + end + + it "rescues exception within the first suitable section in order of declaration" do + begin + raise StandardError + rescue RuntimeError + ScratchPad << :runtime_error + rescue StandardError + ScratchPad << :standard_error + rescue Exception + ScratchPad << :exception + end + + ScratchPad.recorded.should == [:standard_error] + end + it "will execute an else block only if no exceptions were raised" do result = begin ScratchPad << :one @@ -147,6 +195,20 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L195 ScratchPad.recorded.should == [:one, :else_ran, :ensure_ran, :outside_begin] end + it "will execute an else block even without rescue and ensure" do + lambda { + eval <<-ruby + begin + ScratchPad << :begin + else + ScratchPad << :else + end + ruby + }.should complain(/else without rescue is useless/) + + ScratchPad.recorded.should == [:begin, :else] + end + it "will not execute an else block if an exception was raised" do result = begin ScratchPad << :one @@ -223,14 +285,31 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L285 a.should == 'ac' end - it "without classes will not rescue Exception" do - lambda do + context "without rescue expression" do + it "will rescue only StandardError and its subclasses" do begin - raise Exception + raise StandardError rescue - 'Exception wrongly rescued' + ScratchPad << :caught + end + + ScratchPad.recorded.should == [:caught] + end + + it "will not rescue exceptions except StandardError" do + [ Exception.new, NoMemoryError.new, ScriptError.new, SecurityError.new, + SignalException.new('INT'), SystemExit.new, SystemStackError.new + ].each do |exception| + lambda { + begin + raise exception + rescue + ScratchPad << :caught + end + }.should raise_error(exception.class) end - end.should raise_error(Exception) + ScratchPad.recorded.should == [] + end end it "uses === to compare against rescued classes" do @@ -279,7 +358,7 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L358 invalid_rescuer = Object.new begin :foo - rescue rescuer + rescue invalid_rescuer end.should == :foo end @@ -291,6 +370,44 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L370 end.should == :expected end + it "allows rescue in class" do + eval <<-ruby + class RescueInClassExample + raise SpecificExampleException + rescue SpecificExampleException + ScratchPad << :caught + end + ruby + + ScratchPad.recorded.should == [:caught] + end + + it "does not allow rescue in {} block" do + lambda { + eval <<-ruby + lambda { + raise SpecificExampleException + rescue SpecificExampleException + :caught + } + ruby + }.should raise_error(SyntaxError) + end + + ruby_version_is "2.5" do + it "allows rescue in 'do end' block" do + lambda = eval <<-ruby + lambda do + raise SpecificExampleException + rescue SpecificExampleException + ScratchPad << :caught + end.call + ruby + + ScratchPad.recorded.should == [:caught] + end + end + ruby_version_is ""..."2.4" do it "fails when using 'rescue' in method arguments" do lambda { eval '1.+ (1 rescue 1)' }.should raise_error(SyntaxError) @@ -305,6 +422,31 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L422 it "requires the 'rescue' in method arguments to be wrapped in parens" do lambda { eval '1.+(1 rescue 1)' }.should raise_error(SyntaxError) + eval('1.+((1 rescue 1))').should == 2 + end + end + + describe "inline form" do + it "can be inlined" do + a = 1/0 rescue 1 + a.should == 1 + end + + it "doesn't except rescue expression" do + lambda { + eval <<-ruby + a = 1 rescue RuntimeError 2 + ruby + }.should raise_error(SyntaxError) + end + + it "rescues only StandardError and its subclasses" do + a = raise(StandardError) rescue 1 + a.should == 1 + + lambda { + a = raise(Exception) rescue 1 + }.should raise_error(Exception) end end end Index: spec/ruby/language/ensure_spec.rb =================================================================== --- spec/ruby/language/ensure_spec.rb (revision 61284) +++ spec/ruby/language/ensure_spec.rb (revision 61285) @@ -7,50 +7,44 @@ describe "An ensure block inside a begin https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/ensure_spec.rb#L7 end it "is executed when an exception is raised in it's corresponding begin block" do - begin - lambda { - begin - ScratchPad << :begin - raise "An exception occurred!" - ensure - ScratchPad << :ensure - end - }.should raise_error(RuntimeError) + lambda { + begin + ScratchPad << :begin + raise EnsureSpec::Error + ensure + ScratchPad << :ensure + end + }.should raise_error(EnsureSpec::Error) - ScratchPad.recorded.should == [:begin, :ensure] - end + ScratchPad.recorded.should == [:begin, :ensure] end it "is executed when an exception is raised and rescued in it's corresponding begin block" do begin + ScratchPad << :begin + raise "An exception occurred!" + rescue + ScratchPad << :rescue + ensure + ScratchPad << :ensure + end + + ScratchPad.recorded.should == [:begin, :rescue, :ensure] + end + + it "is executed even when a symbol is thrown in it's corresponding begin block" do + catch(:symbol) do begin ScratchPad << :begin - raise "An exception occurred!" + throw(:symbol) rescue ScratchPad << :rescue ensure ScratchPad << :ensure end - - ScratchPad.recorded.should == [:begin, :rescue, :ensure] end - end - it "is executed even when a symbol is thrown in it's corresponding begin block" do - begin - catch(:symbol) do - begin - ScratchPad << :begin - throw(:symbol) - rescue - ScratchPad << :rescue - ensure - ScratchPad << :ensure - end - end - - ScratchPad.recorded.should == [:begin, :ensure] - end + ScratchPad.recorded.should == [:begin, :ensure] end it "is executed when nothing is raised or thrown in it's corresponding begin block" do @@ -102,7 +96,7 @@ describe "An ensure block inside a metho https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/ensure_spec.rb#L96 end it "is executed when an exception is raised in the method" do - lambda { @obj.raise_in_method_with_ensure }.should raise_error(RuntimeError) + lambda { @obj.raise_in_method_with_ensure }.should raise_error(EnsureSpec::Error) @obj.executed.should == [:method, :ensure] end @@ -124,3 +118,176 @@ describe "An ensure block inside a metho https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/ensure_spec.rb#L118 @obj.explicit_return_in_method_with_ensure.should == :ensure end end + +describe "An ensure block inside a class" do + before :each do + ScratchPad.record [] + end + + it "is executed when an exception is raised" do + lambda { + eval <<-ruby + class EnsureInClassExample + ScratchPad << :class + raise EnsureSpec::Error + ensure + ScratchPad << :ensure + end + ruby + }.should raise_error(EnsureSpec::Error) + + ScratchPad.recorded.should == [:class, :ensure] + end + + it "is executed when an exception is raised and rescued" do + eval <<-ruby + class EnsureInClassExample + ScratchPad << :class + raise + rescue + ScratchPad << :rescue + ensure + ScratchPad << :ensure + end + ruby + + ScratchPad.recorded.should == [:class, :rescue, :ensure] + end + + it "is executed even when a symbol is thrown" do + catch(:symbol) do + eval <<-ruby + class EnsureInClassExample + ScratchPad << :class + throw(:symbol) + rescue + ScratchPad << :rescue + ensure + ScratchPad << :ensure + end + ruby + end + + ScratchPad.recorded.should == [:class, :ensure] + end + + it "is executed when nothing is raised or thrown" do + eval <<-ruby + class EnsureInClassExample + ScratchPad << :class + rescue + ScratchPad << :rescue + ensure + ScratchPad << :ensure + end + ruby + + ScratchPad.recorded.should == [:class, :ensure] + end + + it "has no return value" do + result = eval <<-ruby + cla (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/