ruby-changes:51086
From: eregon <ko1@a...>
Date: Sun, 29 Apr 2018 04:50:20 +0900 (JST)
Subject: [ruby-changes:51086] eregon:r63293 (trunk): Update to ruby/spec@6f38a82
eregon 2018-04-29 04:50:06 +0900 (Sun, 29 Apr 2018) New Revision: 63293 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63293 Log: Update to ruby/spec@6f38a82 Added files: trunk/spec/ruby/core/exception/backtrace_locations_spec.rb trunk/spec/ruby/core/exception/full_message_spec.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb trunk/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb trunk/spec/ruby/language/predefined/toplevel_binding_spec.rb trunk/spec/ruby/library/bigdecimal/BigDecimal_spec.rb trunk/spec/ruby/security/cve_2017_17742_spec.rb trunk/spec/ruby/security/cve_2018_6914_spec.rb trunk/spec/ruby/security/cve_2018_8778_spec.rb trunk/spec/ruby/security/cve_2018_8779_spec.rb trunk/spec/ruby/security/cve_2018_8780_spec.rb Removed files: trunk/spec/ruby/library/bigdecimal/new_spec.rb Modified files: trunk/spec/ruby/.rubocop_todo.yml trunk/spec/ruby/.travis.yml trunk/spec/ruby/README.md trunk/spec/ruby/command_line/dash_upper_i_spec.rb trunk/spec/ruby/command_line/frozen_strings_spec.rb trunk/spec/ruby/core/argf/close_spec.rb trunk/spec/ruby/core/argf/read_nonblock_spec.rb trunk/spec/ruby/core/argf/readpartial_spec.rb trunk/spec/ruby/core/array/bsearch_index_spec.rb trunk/spec/ruby/core/array/dig_spec.rb trunk/spec/ruby/core/array/flatten_spec.rb trunk/spec/ruby/core/array/pack/j_spec.rb trunk/spec/ruby/core/array/shared/delete_if.rb trunk/spec/ruby/core/array/shared/inspect.rb trunk/spec/ruby/core/comparable/equal_value_spec.rb trunk/spec/ruby/core/dir/close_spec.rb trunk/spec/ruby/core/dir/shared/glob.rb trunk/spec/ruby/core/enumerable/chunk_spec.rb trunk/spec/ruby/core/enumerable/chunk_while_spec.rb trunk/spec/ruby/core/enumerable/grep_v_spec.rb trunk/spec/ruby/core/enumerable/slice_before_spec.rb trunk/spec/ruby/core/enumerator/lazy/grep_v_spec.rb trunk/spec/ruby/core/enumerator/lazy/uniq_spec.rb trunk/spec/ruby/core/exception/fixtures/common.rb trunk/spec/ruby/core/exception/name_spec.rb trunk/spec/ruby/core/exception/receiver_spec.rb trunk/spec/ruby/core/file/mkfifo_spec.rb trunk/spec/ruby/core/file/open_spec.rb trunk/spec/ruby/core/file/shared/unlink.rb trunk/spec/ruby/core/file/stat/ino_spec.rb trunk/spec/ruby/core/hash/compare_by_identity_spec.rb trunk/spec/ruby/core/hash/dig_spec.rb trunk/spec/ruby/core/hash/fetch_values_spec.rb trunk/spec/ruby/core/hash/fixtures/classes.rb trunk/spec/ruby/core/hash/gt_spec.rb trunk/spec/ruby/core/hash/gte_spec.rb trunk/spec/ruby/core/hash/initialize_spec.rb trunk/spec/ruby/core/hash/lt_spec.rb trunk/spec/ruby/core/hash/lte_spec.rb trunk/spec/ruby/core/hash/shared/to_s.rb trunk/spec/ruby/core/hash/to_proc_spec.rb trunk/spec/ruby/core/io/binread_spec.rb trunk/spec/ruby/core/io/close_on_exec_spec.rb trunk/spec/ruby/core/io/close_read_spec.rb trunk/spec/ruby/core/io/close_spec.rb trunk/spec/ruby/core/io/close_write_spec.rb trunk/spec/ruby/core/io/each_codepoint_spec.rb trunk/spec/ruby/core/io/read_nonblock_spec.rb trunk/spec/ruby/core/io/write_nonblock_spec.rb trunk/spec/ruby/core/kernel/define_singleton_method_spec.rb trunk/spec/ruby/core/kernel/loop_spec.rb trunk/spec/ruby/core/kernel/require_relative_spec.rb trunk/spec/ruby/core/kernel/shared/require.rb trunk/spec/ruby/core/main/using_spec.rb trunk/spec/ruby/core/module/autoload_spec.rb trunk/spec/ruby/core/module/define_method_spec.rb trunk/spec/ruby/core/module/deprecate_constant_spec.rb trunk/spec/ruby/core/module/prepend_spec.rb trunk/spec/ruby/core/module/private_spec.rb trunk/spec/ruby/core/numeric/negative_spec.rb trunk/spec/ruby/core/numeric/positive_spec.rb trunk/spec/ruby/core/objectspace/each_object_spec.rb trunk/spec/ruby/core/process/status/exitstatus_spec.rb trunk/spec/ruby/core/process/status/termsig_spec.rb trunk/spec/ruby/core/random/urandom_spec.rb trunk/spec/ruby/core/signal/signame_spec.rb trunk/spec/ruby/core/string/crypt_spec.rb trunk/spec/ruby/core/string/new_spec.rb trunk/spec/ruby/core/string/shared/each_line.rb trunk/spec/ruby/core/string/uminus_spec.rb trunk/spec/ruby/core/string/unpack/j_spec.rb trunk/spec/ruby/core/string/uplus_spec.rb trunk/spec/ruby/core/struct/dig_spec.rb trunk/spec/ruby/core/thread/name_spec.rb trunk/spec/ruby/core/time/at_spec.rb trunk/spec/ruby/core/tracepoint/disable_spec.rb trunk/spec/ruby/core/tracepoint/enable_spec.rb trunk/spec/ruby/core/tracepoint/new_spec.rb trunk/spec/ruby/language/block_spec.rb trunk/spec/ruby/language/class_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/fixtures/super.rb trunk/spec/ruby/language/heredoc_spec.rb trunk/spec/ruby/language/optional_assignments_spec.rb trunk/spec/ruby/language/rescue_spec.rb trunk/spec/ruby/language/safe_navigator_spec.rb trunk/spec/ruby/language/string_spec.rb trunk/spec/ruby/language/super_spec.rb trunk/spec/ruby/language/yield_spec.rb trunk/spec/ruby/library/base64/urlsafe_decode64_spec.rb trunk/spec/ruby/library/base64/urlsafe_encode64_spec.rb trunk/spec/ruby/library/bigdecimal/divmod_spec.rb trunk/spec/ruby/library/bigdecimal/inspect_spec.rb trunk/spec/ruby/library/bigdecimal/limit_spec.rb trunk/spec/ruby/library/bigdecimal/shared/eql.rb trunk/spec/ruby/library/bigdecimal/shared/modulo.rb trunk/spec/ruby/library/bigdecimal/to_r_spec.rb trunk/spec/ruby/library/bigdecimal/to_s_spec.rb trunk/spec/ruby/library/coverage/peek_result_spec.rb trunk/spec/ruby/library/date/minus_month_spec.rb trunk/spec/ruby/library/net/ftp/default_passive_spec.rb trunk/spec/ruby/library/net/ftp/passive_spec.rb trunk/spec/ruby/library/net/http/http/open_timeout_spec.rb trunk/spec/ruby/library/rexml/element/namespaces_spec.rb trunk/spec/ruby/library/securerandom/random_number_spec.rb trunk/spec/ruby/library/socket/basicsocket/recv_spec.rb trunk/spec/ruby/library/socket/shared/recv_nonblock.rb trunk/spec/ruby/library/socket/socket/accept_nonblock_spec.rb trunk/spec/ruby/library/socket/socket/connect_nonblock_spec.rb trunk/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb trunk/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb trunk/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb trunk/spec/ruby/library/stringio/close_read_spec.rb trunk/spec/ruby/library/stringio/close_spec.rb trunk/spec/ruby/library/stringio/close_write_spec.rb trunk/spec/ruby/library/stringio/external_encoding_spec.rb trunk/spec/ruby/library/stringio/read_nonblock_spec.rb trunk/spec/ruby/library/thread/queue/close_spec.rb trunk/spec/ruby/library/thread/queue/closed_spec.rb trunk/spec/ruby/library/thread/sizedqueue/close_spec.rb trunk/spec/ruby/library/thread/sizedqueue/closed_spec.rb trunk/spec/ruby/optional/capi/class_spec.rb trunk/spec/ruby/optional/capi/time_spec.rb trunk/spec/ruby/security/cve_2014_8080_spec.rb trunk/spec/ruby/shared/basicobject/method_missing.rb Index: spec/ruby/core/array/dig_spec.rb =================================================================== --- spec/ruby/core/array/dig_spec.rb (revision 63292) +++ spec/ruby/core/array/dig_spec.rb (revision 63293) @@ -1,54 +1,52 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/dig_spec.rb#L1 require_relative '../../spec_helper' -ruby_version_is '2.3' do - describe "Array#dig" do +describe "Array#dig" do - it "returns #at with one arg" do - ['a'].dig(0).should == 'a' - ['a'].dig(1).should be_nil - end - - it "recurses array elements" do - a = [ [ 1, [2, '3'] ] ] - a.dig(0, 0).should == 1 - a.dig(0, 1, 1).should == '3' - a.dig(0, -1, 0).should == 2 - end - - it "returns the nested value specified if the sequence includes a key" do - a = [42, { foo: :bar }] - a.dig(1, :foo).should == :bar - end - - it "raises a TypeError for a non-numeric index" do - lambda { - ['a'].dig(:first) - }.should raise_error(TypeError) - end - - it "raises a TypeError if any intermediate step does not respond to #dig" do - a = [1, 2] - lambda { - a.dig(0, 1) - }.should raise_error(TypeError) - end - - it "raises an ArgumentError if no arguments provided" do - lambda { - [10].dig() - }.should raise_error(ArgumentError) - end - - it "returns nil if any intermediate step is nil" do - a = [[1, [2, 3]]] - a.dig(1, 2, 3).should == nil - end - - it "calls #dig on the result of #at with the remaining arguments" do - h = [[nil, [nil, nil, 42]]] - h[0].should_receive(:dig).with(1, 2).and_return(42) - h.dig(0, 1, 2).should == 42 - end + it "returns #at with one arg" do + ['a'].dig(0).should == 'a' + ['a'].dig(1).should be_nil + end + + it "recurses array elements" do + a = [ [ 1, [2, '3'] ] ] + a.dig(0, 0).should == 1 + a.dig(0, 1, 1).should == '3' + a.dig(0, -1, 0).should == 2 + end + + it "returns the nested value specified if the sequence includes a key" do + a = [42, { foo: :bar }] + a.dig(1, :foo).should == :bar + end + + it "raises a TypeError for a non-numeric index" do + lambda { + ['a'].dig(:first) + }.should raise_error(TypeError) + end + it "raises a TypeError if any intermediate step does not respond to #dig" do + a = [1, 2] + lambda { + a.dig(0, 1) + }.should raise_error(TypeError) end + + it "raises an ArgumentError if no arguments provided" do + lambda { + [10].dig() + }.should raise_error(ArgumentError) + end + + it "returns nil if any intermediate step is nil" do + a = [[1, [2, 3]]] + a.dig(1, 2, 3).should == nil + end + + it "calls #dig on the result of #at with the remaining arguments" do + h = [[nil, [nil, nil, 42]]] + h[0].should_receive(:dig).with(1, 2).and_return(42) + h.dig(0, 1, 2).should == 42 + end + end Index: spec/ruby/core/array/bsearch_index_spec.rb =================================================================== --- spec/ruby/core/array/bsearch_index_spec.rb (revision 63292) +++ spec/ruby/core/array/bsearch_index_spec.rb (revision 63293) @@ -1,86 +1,84 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/bsearch_index_spec.rb#L1 require_relative '../../spec_helper' require_relative '../enumerable/shared/enumeratorized' -ruby_version_is "2.3" do - describe "Array#bsearch_index" do - context "when not passed a block" do - before :each do - @enum = [1, 2, 42, 100, 666].bsearch_index - end +describe "Array#bsearch_index" do + context "when not passed a block" do + before :each do + @enum = [1, 2, 42, 100, 666].bsearch_index + end - it "returns an Enumerator" do - @enum.should be_an_instance_of(Enumerator) - end + it "returns an Enumerator" do + @enum.should be_an_instance_of(Enumerator) + end - it "returns an Enumerator with unknown size" do - @enum.size.should be_nil - end + it "returns an Enumerator with unknown size" do + @enum.size.should be_nil + end - it "returns index of element when block condition is satisfied" do - @enum.each { |x| x >= 33 }.should == 2 - end + it "returns index of element when block condition is satisfied" do + @enum.each { |x| x >= 33 }.should == 2 end + end + + it "raises a TypeError when block returns a String" do + lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError) + end - it "raises a TypeError when block returns a String" do - lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError) + it "returns nil when block is empty" do + [1, 2, 3].bsearch_index {}.should be_nil + end + + context "minimum mode" do + before :each do + @array = [0, 4, 7, 10, 12] end - it "returns nil when block is empty" do - [1, 2, 3].bsearch_index {}.should be_nil + it "returns index of first element which satisfies the block" do + @array.bsearch_index { |x| x >= 4 }.should == 1 + @array.bsearch_index { |x| x >= 6 }.should == 2 + @array.bsearch_index { |x| x >= -1 }.should == 0 end - context "minimum mode" do - before :each do - @array = [0, 4, 7, 10, 12] - end + it "returns nil when block condition is never satisfied" do + @array.bsearch_index { false }.should be_nil + @array.bsearch_index { |x| x >= 100 }.should be_nil + end + end - it "returns index of first element which satisfies the block" do - @array.bsearch_index { |x| x >= 4 }.should == 1 - @array.bsearch_index { |x| x >= 6 }.should == 2 - @array.bsearch_index { |x| x >= -1 }.should == 0 - end + context "find any mode" do + before :each do + @array = [0, 4, 7, 10, 12] + end - it "returns nil when block condition is never satisfied" do - @array.bsearch_index { false }.should be_nil - @array.bsearch_index { |x| x >= 100 }.should be_nil - end + it "returns the index of any matched elements where element is between 4 <= x < 8" do + [1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 }) end - context "find any mode" do - before :each do - @array = [0, 4, 7, 10, 12] - end + it "returns the index of any matched elements where element is between 8 <= x < 10" do + @array.bsearch_index { |x| 4 - x / 2 }.should be_nil + end - it "returns the index of any matched elements where element is between 4 <= x < 8" do - [1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 }) - end + it "returns nil when block never returns 0" do + @array.bsearch_index { |x| 1 }.should be_nil + @array.bsearch_index { |x| -1 }.should be_nil + end - it "returns the index of any matched elements where element is between 8 <= x < 10" do - @array.bsearch_index { |x| 4 - x / 2 }.should be_nil - end + it "returns the middle element when block always returns zero" do + @array.bsearch_index { |x| 0 }.should == 2 + end - it "returns nil when block never returns 0" do - @array.bsearch_index { |x| 1 }.should be_nil - @array.bsearch_index { |x| -1 }.should be_nil + context "magnitude does not effect the result" do + it "returns the index of any matched elements where element is between 4n <= xn < 8n" do + [1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) }) end - it "returns the middle element when block always returns zero" do - @array.bsearch_index { |x| 0 }.should == 2 + it "returns nil when block never returns 0" do + @array.bsearch_index { |x| 1 * (2**100) }.should be_nil + @array.bsearch_index { |x| (-1) * (2**100) }.should be_nil end - context "magnitude does not effect the result" do - it "returns the index of any matched elements where element is between 4n <= xn < 8n" do - [1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) }) - end - - it "returns nil when block never returns 0" do - @array.bsearch_index { |x| 1 * (2**100) }.should be_nil - @array.bsearch_index { |x| (-1) * (2**100) }.should be_nil - end - - it "handles values from Bignum#coerce" do - [1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first }) - end + it "handles values from Bignum#coerce" do + [1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first }) end end end Index: spec/ruby/core/process/status/termsig_spec.rb =================================================================== --- spec/ruby/core/process/status/termsig_spec.rb (revision 63292) +++ spec/ruby/core/process/status/termsig_spec.rb (revision 63293) @@ -13,6 +13,18 @@ describe "Process::Status#termsig" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/status/termsig_spec.rb#L13 end end + describe "for a child that raised SignalException" do + before :each do + ruby_exe("raise SignalException, 'SIGTERM'") + end + + platform_is_not :windows do + it "returns the signal" do + $?.termsig.should == Signal.list["TERM"] + end + end + end + describe "for a child that was sent a signal" do before :each do Index: spec/ruby/core/file/stat/ino_spec.rb =================================================================== --- spec/ruby/core/file/stat/ino_spec.rb (revision 63292) +++ spec/ruby/core/file/stat/ino_spec.rb (revision 63293) @@ -19,20 +19,10 @@ describe "File::Stat#ino" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/stat/ino_spec.rb#L19 end platform_is :windows do - ruby_version_is ""..."2.3" do - it "returns 0" do - st = File.stat(@file) - st.ino.should be_kind_of(Integer) - st.ino.should == 0 - end - end - - ruby_version_is "2.3" do - it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do - st = File.stat(@file) - st.ino.should be_kind_of(Integer) - st.ino.should > 0 - end + it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do + st = File.stat(@file) + st.ino.should be_kind_of(Integer) + st.ino.should > 0 end end end Index: spec/ruby/language/fixtures/super.rb =================================================================== --- spec/ruby/language/fixtures/super.rb (revision 63292) +++ spec/ruby/language/fixtures/super.rb (revision 63293) @@ -455,6 +455,38 @@ module Super https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/fixtures/super.rb#L455 end end + module ZSuperWithRestReassigned + class A + def a(*args) + args + end + end + + class B < A + def a(*args) + args = ["foo"] + + super + end + end + end + + module ZSuperWithRestReassignedWithScalar + class A + def a(*args) + args + end + end + + class B < A + def a(*args) + args = "foo" + + super + end + end + end + module ZSuperWithUnderscores class A def m(*args) Index: spec/ruby/language/fixtures/ensure.rb =================================================================== --- spec/ruby/language/fixtures/ensure.rb (revision 63292) +++ spec/ruby/language/fixtures/ensure.rb (revision 63293) @@ -40,6 +40,50 @@ module EnsureSpec https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/fixtures/ensure.rb#L40 ensure return :ensure end + + def explicit_return_in_rescue_and_explicit_return_in_ensure + raise + rescue + return 2 + ensure + return "returned in ensure" + end + + def explicit_return_in_rescue_and_implicit_return_in_ensure + raise + rescue + return "returned in rescue" + ensure + 3 + end + + def raise_and_explicit_return_in_ensure + raise + ensure + return "returned in ensure" + end + + def raise_in_rescue_and_explicit_return_in_ensure + raise + rescue + raise + ensure + return "returned in ensure" + end + + def raise_in_rescue_and_raise_in_ensure + raise + rescue + raise "raised in rescue" + ensure + raise "raised in ensure" + end + + def raise_in_method_and_raise_in_ensure + raise + ensure + raise "raised in ensure" + end end end Index: spec/ruby/language/string_spec.rb =================================================================== --- spec/ruby/language/string_spec.rb (revision 63292) +++ spec/ruby/language/string_spec.rb (revision 63293) @@ -233,27 +233,25 @@ describe "Ruby String literals" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/string_spec.rb#L233 long_string_literals.should == "Beautiful is better than ugly.Explicit is better than implicit." end - ruby_version_is "2.3" do - describe "with a magic frozen comment" do - it "produce the same object each time" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true" - end - - it "produce the same object for literals with the same content" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true" - end - - it "produce the same object for literals with the same content in different files" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true" - end - - it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true" - end - - it "produce different objects for literals with the same content in different files if they have different encodings" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true" - end + describe "with a magic frozen comment" do + it "produce the same object each time" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true" + end + + it "produce the same object for literals with the same content" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true" + end + + it "produce the same object for literals with the same content in different files" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true" + end + + it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true" + end + + it "produce different objects for literals with the same content in different files if they have different encodings" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true" end end Index: spec/ruby/language/rescue_spec.rb =================================================================== --- spec/ruby/language/rescue_spec.rb (revision 63292) +++ spec/ruby/language/rescue_spec.rb (revision 63293) @@ -371,11 +371,23 @@ describe "The rescue keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/rescue_spec.rb#L371 end it "evaluates rescue expressions only when needed" do - invalid_rescuer = Object.new begin - :foo - rescue invalid_rescuer - end.should == :foo + ScratchPad << :foo + rescue -> { ScratchPad << :bar; StandardError }.call + end + + ScratchPad.recorded.should == [:foo] + end + + it "suppresses exception from block when raises one from rescue expression" do + -> { + begin + raise "from block" + rescue (raise "from rescue expression") + end + }.should raise_error(RuntimeError, "from rescue expression") do |e| + e.cause.message.should == "from block" + end end it "should splat the handling Error classes" do Index: spec/ruby/language/safe_navigator_spec.rb =================================================================== --- spec/ruby/language/safe_navigator_spec.rb (revision 63292) +++ spec/ruby/language/safe_navigator_spec.rb (revision 63293) @@ -1,101 +1,99 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/safe_navigator_spec.rb#L1 require_relative '../spec_helper' -ruby_version_is "2.3" do - describe "Safe navigator" do - it "requires a method name to be provided" do - lambda { eval("obj&. {}") }.should raise_error(SyntaxError) - end +describe "Safe navigator" do + it "requires a method name to be provided" do + lambda { eval("obj&. {}") }.should raise_error(SyntaxError) + end - context "when context is nil" do - it "always returns nil" do - eval("nil&.unknown").should == nil - eval("[][10]&.unknown").should == nil - end + context "when context is nil" do + it "always returns nil" do + eval("nil&.unknown").should == nil + eval("[][10]&.unknown").should == nil + end - it "can be chained" do - eval("nil&.one&.two&.three").should == nil - end + it "can be chained" do + eval("nil&.one&.two&.three").should == nil + end - it "doesn't evaluate arguments" do - obj = Object.new - obj.should_not_receive(:m) - eval("nil&.unknown(obj.m) { obj.m }") - end + it "doesn't evaluate arguments" do + obj = Object.new + obj.should_not_receive(:m) + eval("nil&.unknown(obj.m) { obj.m }") end + end - context "when context is false" do - it "calls the method" do - eval("false&.to_s").should == "false" + context "when context is false" do + it "calls the method" do + eval("false&.to_s").should == "false" - lambda { eval("false&.unknown") }.should raise_error(NoMethodError) - end + lambda { eval("false&.unknown") }.should raise_error(NoMethodError) end + end - context "when context is truthy" do - it "calls the method" do - eval("1&.to_s").should == "1" + context "when context is truthy" do + it "calls the method" do + eval("1&.to_s").should == "1" - lambda { eval("1&.unknown") }.should raise_error(NoMethodError) - end + lambda { eval("1&.unknown") }.should raise_error(NoMethodError) end + end - it "takes a list of arguments" do - eval("[1,2,3]&.first(2)").should == [1,2] - end + it "takes a list of arguments" do + eval("[1,2,3]&.first(2)").should == [1,2] + end - it "takes a block" do - eval("[1,2]&.map { |i| i * 2 }").should == [2, 4] - end + it "takes a block" do + eval("[1,2]&.map { |i| i * 2 }").should == [2, 4] + end - it "allows assignment methods" do - klass = Class.new do - attr_reader :foo - def foo=(val) - @foo = val - 42 - end + it "allows assignment methods" do + klass = Class.new do + attr_reader :foo + def foo=(val) + @foo = val + 42 end - obj = klass.new + end + obj = klass.new - eval("obj&.foo = 3").should == 3 - obj.foo.should == 3 + eval("obj&.foo = 3").should == 3 + obj.foo.should == 3 - obj = nil - eval("obj&.foo = 3").should == nil - end + obj = nil + eval("obj&.foo = 3").should == nil + end - it "allows assignment operators" do - klass = Class.new do - attr_accessor :m + it "allows assignment operators" do + klass = Class.new do + attr_accessor :m - def initialize - @m = 0 - end + def initialize + (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/