[前][次][番号順一覧][スレッド一覧]

ruby-changes:54811

From: eregon <ko1@a...>
Date: Fri, 8 Feb 2019 01:35:43 +0900 (JST)
Subject: [ruby-changes:54811] eregon:r67030 (trunk): Update to ruby/spec@6cf8ebe

eregon	2019-02-08 01:35:33 +0900 (Fri, 08 Feb 2019)

  New Revision: 67030

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67030

  Log:
    Update to ruby/spec@6cf8ebe

  Modified files:
    trunk/spec/ruby/core/array/combination_spec.rb
    trunk/spec/ruby/core/array/fixtures/classes.rb
    trunk/spec/ruby/core/array/last_spec.rb
    trunk/spec/ruby/core/array/pack/shared/float.rb
    trunk/spec/ruby/core/array/product_spec.rb
    trunk/spec/ruby/core/array/rassoc_spec.rb
    trunk/spec/ruby/core/array/repeated_combination_spec.rb
    trunk/spec/ruby/core/array/sum_spec.rb
    trunk/spec/ruby/core/array/zip_spec.rb
    trunk/spec/ruby/core/dir/children_spec.rb
    trunk/spec/ruby/core/dir/entries_spec.rb
    trunk/spec/ruby/core/dir/shared/glob.rb
    trunk/spec/ruby/core/encoding/aliases_spec.rb
    trunk/spec/ruby/core/enumerable/fixtures/classes.rb
    trunk/spec/ruby/core/enumerable/zip_spec.rb
    trunk/spec/ruby/core/enumerator/chain/each_spec.rb
    trunk/spec/ruby/core/exception/signal_exception_spec.rb
    trunk/spec/ruby/core/file/expand_path_spec.rb
    trunk/spec/ruby/core/file/new_spec.rb
    trunk/spec/ruby/core/file/open_spec.rb
    trunk/spec/ruby/core/file/shared/fnmatch.rb
    trunk/spec/ruby/core/file/stat/dev_major_spec.rb
    trunk/spec/ruby/core/file/stat/dev_minor_spec.rb
    trunk/spec/ruby/core/file/stat/rdev_major_spec.rb
    trunk/spec/ruby/core/file/stat/rdev_minor_spec.rb
    trunk/spec/ruby/core/file/sticky_spec.rb
    trunk/spec/ruby/core/float/comparison_spec.rb
    trunk/spec/ruby/core/float/round_spec.rb
    trunk/spec/ruby/core/hash/shift_spec.rb
    trunk/spec/ruby/core/io/read_spec.rb
    trunk/spec/ruby/core/io/readlines_spec.rb
    trunk/spec/ruby/core/io/set_encoding_spec.rb
    trunk/spec/ruby/core/kernel/autoload_spec.rb
    trunk/spec/ruby/core/kernel/eval_spec.rb
    trunk/spec/ruby/core/kernel/throw_spec.rb
    trunk/spec/ruby/core/math/tan_spec.rb
    trunk/spec/ruby/core/module/attr_spec.rb
    trunk/spec/ruby/core/module/autoload_spec.rb
    trunk/spec/ruby/core/module/comparison_spec.rb
    trunk/spec/ruby/core/module/const_get_spec.rb
    trunk/spec/ruby/core/module/refine_spec.rb
    trunk/spec/ruby/core/numeric/step_spec.rb
    trunk/spec/ruby/core/process/getrlimit_spec.rb
    trunk/spec/ruby/core/process/spawn_spec.rb
    trunk/spec/ruby/core/process/wait_spec.rb
    trunk/spec/ruby/core/regexp/match_spec.rb
    trunk/spec/ruby/core/signal/signame_spec.rb
    trunk/spec/ruby/core/signal/trap_spec.rb
    trunk/spec/ruby/core/string/chomp_spec.rb
    trunk/spec/ruby/core/string/chop_spec.rb
    trunk/spec/ruby/core/string/element_set_spec.rb
    trunk/spec/ruby/core/string/setbyte_spec.rb
    trunk/spec/ruby/core/string/shared/codepoints.rb
    trunk/spec/ruby/core/string/shared/concat.rb
    trunk/spec/ruby/core/string/shared/equal_value.rb
    trunk/spec/ruby/core/string/to_r_spec.rb
    trunk/spec/ruby/core/string/unpack/c_spec.rb
    trunk/spec/ruby/core/string/upto_spec.rb
    trunk/spec/ruby/core/time/at_spec.rb
    trunk/spec/ruby/core/time/fixtures/classes.rb
    trunk/spec/ruby/core/time/getlocal_spec.rb
    trunk/spec/ruby/core/time/minus_spec.rb
    trunk/spec/ruby/core/time/new_spec.rb
    trunk/spec/ruby/core/time/plus_spec.rb
    trunk/spec/ruby/core/time/succ_spec.rb
    trunk/spec/ruby/core/tracepoint/enable_spec.rb
    trunk/spec/ruby/language/block_spec.rb
    trunk/spec/ruby/language/defined_spec.rb
    trunk/spec/ruby/language/optional_assignments_spec.rb
    trunk/spec/ruby/language/private_spec.rb
    trunk/spec/ruby/language/proc_spec.rb
    trunk/spec/ruby/language/regexp/escapes_spec.rb
    trunk/spec/ruby/language/regexp/modifiers_spec.rb
    trunk/spec/ruby/language/regexp/repetition_spec.rb
    trunk/spec/ruby/language/regexp_spec.rb
    trunk/spec/ruby/language/send_spec.rb
    trunk/spec/ruby/language/until_spec.rb
    trunk/spec/ruby/language/while_spec.rb
    trunk/spec/ruby/library/bigdecimal/divmod_spec.rb
    trunk/spec/ruby/library/bigdecimal/sqrt_spec.rb
    trunk/spec/ruby/library/cgi/rfc1123_date_spec.rb
    trunk/spec/ruby/library/datetime/to_date_spec.rb
    trunk/spec/ruby/library/datetime/to_s_spec.rb
    trunk/spec/ruby/library/datetime/to_time_spec.rb
    trunk/spec/ruby/library/delegate/delegator/frozen_spec.rb
    trunk/spec/ruby/library/getoptlong/terminate_spec.rb
    trunk/spec/ruby/library/logger/logger/new_spec.rb
    trunk/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb
    trunk/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb
    trunk/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb
    trunk/spec/ruby/library/net/ftp/quit_spec.rb
    trunk/spec/ruby/library/net/http/http/proxy_class_spec.rb
    trunk/spec/ruby/library/net/http/httpresponse/read_body_spec.rb
    trunk/spec/ruby/library/openstruct/frozen_spec.rb
    trunk/spec/ruby/library/rexml/attribute/initialize_spec.rb
    trunk/spec/ruby/library/securerandom/hex_spec.rb
    trunk/spec/ruby/library/set/enumerable/to_set_spec.rb
    trunk/spec/ruby/library/set/exclusion_spec.rb
    trunk/spec/ruby/library/set/sortedset/exclusion_spec.rb
    trunk/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
    trunk/spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb
    trunk/spec/ruby/library/socket/basicsocket/getsockname_spec.rb
    trunk/spec/ruby/library/socket/ipsocket/getaddress_spec.rb
    trunk/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
    trunk/spec/ruby/library/syslog/log_spec.rb
    trunk/spec/ruby/library/tempfile/initialize_spec.rb
    trunk/spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb
    trunk/spec/ruby/library/uri/plus_spec.rb
    trunk/spec/ruby/library/weakref/weakref_alive_spec.rb
    trunk/spec/ruby/library/yaml/parse_file_spec.rb
    trunk/spec/ruby/library/zlib/gzipreader/read_spec.rb
Index: spec/ruby/core/time/getlocal_spec.rb
===================================================================
--- spec/ruby/core/time/getlocal_spec.rb	(revision 67029)
+++ spec/ruby/core/time/getlocal_spec.rb	(revision 67030)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/getlocal_spec.rb#L1
 require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
 
 describe "Time#getlocal" do
   it "returns a new time which is the local representation of time" do
@@ -99,15 +100,69 @@ describe "Time#getlocal" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/getlocal_spec.rb#L100
   ruby_version_is "2.6" do
     describe "with a timezone argument" do
       it "returns a Time in the timezone" do
-        zone = mock('timezone')
-        zone.should_receive(:utc_to_local).and_return(Time.utc(2000, 1, 1, 17, 30, 0))
-        t = Time.utc(2000, 1, 1, 12, 0, 0)
-        tv = t.to_i
-        t = t.getlocal(zone)
-        t.to_a[0, 6].should == [0, 30, 17, 1, 1, 2000]
-        t.utc_offset.should == 19800
-        t.to_i.should == tv
-        t.zone.should == zone
+        zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+        time = Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
+
+        time.zone.should == zone
+        time.utc_offset.should == 5*3600+30*60
+      end
+
+      it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do
+        zone = Object.new
+        def zone.utc_to_local(time)
+          time
+        end
+        def zone.local_to_utc(time)
+          time
+        end
+
+        lambda {
+          Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
+        }.should_not raise_error
+      end
+
+      it "raises TypeError if timezone does not implement #utc_to_local method" do
+        zone = Object.new
+        def zone.local_to_utc(time)
+          time
+        end
+
+        lambda {
+          Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
+        }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
+      end
+
+      it "does not raise exception if timezone does not implement #local_to_utc method" do
+        zone = Object.new
+        def zone.utc_to_local(time)
+          time
+        end
+
+        lambda {
+          Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
+        }.should_not raise_error
+      end
+
+      context "subject's class implements .find_timezone method" do
+        it "calls .find_timezone to build a time object if passed zone name as a timezone argument" do
+          time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0).getlocal("Asia/Colombo")
+          time.zone.should be_kind_of TimeSpecs::TimezoneWithName
+          time.zone.name.should == "Asia/Colombo"
+
+          time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0).getlocal("some invalid zone name")
+          time.zone.should be_kind_of TimeSpecs::TimezoneWithName
+          time.zone.name.should == "some invalid zone name"
+        end
+
+        it "does not call .find_timezone if passed any not string/numeric/timezone timezone argument" do
+          [Object.new, [], {}, :"some zone"].each do |zone|
+            time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0)
+
+            lambda {
+              time.getlocal(zone)
+            }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
+          end
+        end
       end
     end
   end
Index: spec/ruby/core/time/plus_spec.rb
===================================================================
--- spec/ruby/core/time/plus_spec.rb	(revision 67029)
+++ spec/ruby/core/time/plus_spec.rb	(revision 67030)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/plus_spec.rb#L1
 require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
 
 describe "Time#+" do
   it "increments the time by the specified amount" do
@@ -47,16 +48,22 @@ describe "Time#+" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/plus_spec.rb#L48
     (Time.new(2012, 1, 1, 0, 0, 0, 3600) + 10).utc_offset.should == 3600
   end
 
+  it "preserves time zone" do
+    time_with_zone = Time.now.utc
+    time_with_zone.zone.should == (time_with_zone + 60*60).zone
+
+    time_with_zone = Time.now
+    time_with_zone.zone.should == (time_with_zone + 60*60).zone
+  end
+
   ruby_version_is "2.6" do
-    it "returns a time with the same timezone as self" do
-      zone = mock("timezone")
-      zone.should_receive(:local_to_utc).and_return(Time.utc(2012, 1, 1, 6, 30, 0))
-      zone.should_receive(:utc_to_local).and_return(Time.utc(2012, 1, 1, 12, 0, 10))
-      t = Time.new(2012, 1, 1, 12, 0, 0, zone) + 10
-      t.zone.should == zone
-      t.utc_offset.should == 19800
-      t.to_a[0, 6].should == [10, 0, 12, 1, 1, 2012]
-      t.should == Time.utc(2012, 1, 1, 6, 30, 10)
+    context "zone is a timezone object" do
+      it "preserves time zone" do
+        zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+        time = Time.new(2012, 1, 1, 12, 0, 0, zone) + 60*60
+
+        time.zone.should == zone
+      end
     end
   end
 
Index: spec/ruby/core/time/minus_spec.rb
===================================================================
--- spec/ruby/core/time/minus_spec.rb	(revision 67029)
+++ spec/ruby/core/time/minus_spec.rb	(revision 67030)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/minus_spec.rb#L1
 require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
 
 describe "Time#-" do
   it "decrements the time by the specified amount" do
@@ -89,6 +90,25 @@ describe "Time#-" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/minus_spec.rb#L90
     (Time.new(2012, 1, 1, 0, 0, 0, 3600) - 10).utc_offset.should == 3600
   end
 
+  it "preserves time zone" do
+    time_with_zone = Time.now.utc
+    time_with_zone.zone.should == (time_with_zone - 60*60).zone
+
+    time_with_zone = Time.now
+    time_with_zone.zone.should == (time_with_zone - 60*60).zone
+  end
+
+  ruby_version_is "2.6" do
+    context "zone is a timezone object" do
+      it "preserves time zone" do
+        zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+        time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 60*60
+
+        time.zone.should == zone
+      end
+    end
+  end
+
   it "does not return a subclass instance" do
     c = Class.new(Time)
     x = c.now + 1
Index: spec/ruby/core/tracepoint/enable_spec.rb
===================================================================
--- spec/ruby/core/tracepoint/enable_spec.rb	(revision 67029)
+++ spec/ruby/core/tracepoint/enable_spec.rb	(revision 67030)
@@ -99,4 +99,416 @@ describe 'TracePoint#enable' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/tracepoint/enable_spec.rb#L99
       trace.enabled?.should be_false
     end
   end
+
+  ruby_version_is "2.6" do
+    describe 'target: option' do
+      before :each do
+        ScratchPad.record []
+      end
+
+      it 'enables trace point for specific location' do
+        trace = TracePoint.new(:call) do |tp|
+          ScratchPad << tp.method_id
+        end
+
+        obj = Object.new
+        def obj.foo; end
+        def obj.bar; end
+
+        trace.enable(target: obj.method(:foo)) do
+          obj.foo
+          obj.bar
+        end
+
+        ScratchPad.recorded.should == [:foo]
+      end
+
+      it 'traces all the events triggered in specified location' do
+        trace = TracePoint.new(:line, :call, :return, :b_call, :b_return) do |tp|
+          ScratchPad << tp.event
+        end
+
+        obj = Object.new
+        def obj.foo
+          bar
+          -> {}.call
+        end
+        def obj.bar; end
+
+        trace.enable(target: obj.method(:foo)) do
+          obj.foo
+        end
+
+        ScratchPad.recorded.uniq.sort.should == [:call, :return, :b_call, :b_return, :line].sort
+      end
+
+      it 'does not trace events in nested locations' do
+        trace = TracePoint.new(:call) do |tp|
+          ScratchPad << tp.method_id
+        end
+
+        obj = Object.new
+        def obj.foo
+          bar
+        end
+        def obj.bar
+          baz
+        end
+        def obj.baz
+        end
+
+        trace.enable(target: obj.method(:foo)) do
+          obj.foo
+        end
+
+        ScratchPad.recorded.should == [:foo]
+      end
+
+      it "traces some events in nested blocks" do
+        klass = Class.new do
+          def foo
+            1.times do
+              1.times do
+                bar do
+                end
+              end
+            end
+          end
+
+          def bar(&blk)
+            blk.call
+          end
+        end
+
+        trace = TracePoint.new(:b_call) do |tp|
+          ScratchPad << tp.lineno
+        end
+
+        obj = klass.new
+        _, lineno = obj.method(:foo).source_location
+
+        trace.enable(target: obj.method(:foo)) do
+          obj.foo
+        end
+
+        ScratchPad.recorded.should == (lineno+1..lineno+3).to_a
+      end
+
+      describe 'option value' do
+        it 'excepts Method' do
+          trace = TracePoint.new(:call) do |tp|
+            ScratchPad << tp.method_id
+          end
+
+          obj = Object.new
+          def obj.foo; end
+
+          trace.enable(target: obj.method(:foo)) do
+            obj.foo
+          end
+
+          ScratchPad.recorded.should == [:foo]
+        end
+
+        it 'excepts UnboundMethod' do
+          trace = TracePoint.new(:call) do |tp|
+            ScratchPad << tp.method_id
+          end
+
+          klass = Class.new do
+            def foo; end
+          end
+
+          unbound_method = klass.instance_method(:foo)
+          trace.enable(target: unbound_method) do
+            klass.new.foo
+          end
+
+          ScratchPad.recorded.should == [:foo]
+        end
+
+        it 'excepts Proc' do
+          trace = TracePoint.new(:b_call) do |tp|
+            ScratchPad << tp.lineno
+          end
+
+          block = proc {}
+          _, lineno = block.source_location
+
+          trace.enable(target: block) do
+            block.call
+          end
+
+          ScratchPad.recorded.should == [lineno]
+          lineno.should be_kind_of(Integer)
+        end
+
+        it 'excepts RubyVM::InstructionSequence' do
+          trace = TracePoint.new(:call) do |tp|
+            ScratchPad << tp.method_id
+          end
+
+          obj = Object.new
+          def obj.foo; end
+
+          iseq = RubyVM::InstructionSequence.of(obj.method(:foo))
+          trace.enable(target: iseq) do
+            obj.foo
+          end
+
+          ScratchPad.recorded.should == [:foo]
+        end
+      end
+
+      it "raises ArgumentError when passed object isn't consisted of InstructionSequence (iseq)" do
+        trace = TracePoint.new(:call) do |tp|
+          ScratchPad << tp.method_id
+        end
+
+        core_method = 'foo bar'.method(:bytes)
+        RubyVM::InstructionSequence.of(core_method).should == nil
+
+        lambda {
+          trace.enable(target: core_method) do
+          end
+        }.should raise_error(ArgumentError, /specified target is not supported/)
+      end
+
+      it "raises ArgumentError if target object cannot trigger specified event" do
+        trace = TracePoint.new(:call) do |tp|
+          ScratchPad << tp.method_id
+        end
+
+        block = proc {}
+
+        lambda {
+          trace.enable(target: block) do
+            block.call # triggers :b_call and :b_return events
+          end
+        }.should raise_error(ArgumentError, /can not enable any hooks/)
+      end
+
+      it "raises ArgumentError if passed not Method/UnboundMethod/Proc/RubyVM::InstructionSequence" do
+        trace = TracePoint.new(:call) do |tp|
+        end
+
+        lambda {
+          trace.enable(target: Object.new) do
+          end
+        }.should raise_error(ArgumentError, /specified target is not supported/)
+      end
+
+      context "nested enabling and disabling" do
+        it "raises ArgumentError if trace point already enabled with target is re-enabled with target" do
+          trace = TracePoint.new(:b_call) do
+          end
+
+          lambda {
+            trace.enable(target: -> {}) do
+              trace.enable(target: -> {}) do
+              end
+            end
+          }.should raise_error(ArgumentError, /can't nest-enable a targetting TracePoint/)
+        end
+
+        it "raises ArgumentError if trace point already enabled without target is re-enabled with target" do
+          trace = TracePoint.new(:b_call) do
+          end
+
+          lambda {
+            trace.enable do
+              trace.enable(target: -> {}) do
+              end
+            end
+          }.should raise_error(ArgumentError, /can't nest-enable a targetting TracePoint/)
+        end
+
+        it "raises ArgumentError if trace point already enabled with target is re-enabled without target" do
+          trace = TracePoint.new(:b_call) do
+          end
+
+          lambda {
+            trace.enable(target: -> {}) do
+              trace.enable do
+              end
+            end
+          }.should raise_error(ArgumentError, /can't nest-enable a targetting TracePoint/)
+        end
+
+        it "raises ArgumentError if trace point already enabled with target is disabled with block" do
+          trace = TracePoint.new(:b_call) do
+          end
+
+          lambda {
+            trace.enable(target: -> {}) do
+              trace.disable do
+              end
+            end
+          }.should raise_error(ArgumentError, /can't disable a targetting TracePoint in a block/)
+        end
+
+        it "traces events when trace point with target is enabled in another trace point enabled without target" do
+          trace_outer = TracePoint.new(:b_call) do |tp|
+            ScratchPad << :outer
+          end
+
+          trace_inner = TracePoint.new(:b_call) do |tp|
+            ScratchPad << :inner
+          end
+
+          target = -> {}
+
+          trace_outer.enable do
+            trace_inner.enable(target: target) do
+              target.call
+            end
+          end
+
+          ScratchPad.recorded.should == [:outer, :outer, :outer, :inner]
+        end
+
+        it "traces events when trace point with target is enabled in another trace point enabled with target" do
+          trace_outer = TracePoint.new(:b_call) do |tp|
+            ScratchPad << :outer
+          end
+
+          trace_inner = TracePoint.new(:b_call) do |tp|
+            ScratchPad << :inner
+          end
+
+          target = -> {}
+
+          trace_outer.enable(target: target) do
+            trace_inner.enable(target: target) do
+              target.call
+            end
+          end
+
+          ScratchPad.recorded.should == [:inner, :outer]
+        end
+
+        it "traces events when trace point without target is enabled in another trace point enabled with target" do
+          trace_outer = TracePoint.new(:b_call) do |tp|
+            ScratchPad << :outer
+          end
+
+          trace_inner = TracePoint.new(:b_call) do |tp|
+            ScratchPad << :inner
+          end
+
+          target = -> {}
+
+          trace_outer.enable(target: target) do
+            trace_inner.enable do
+              target.call
+            end
+          end
+
+          ScratchPad.recorded.should == [:inner, :inner, :outer]
+        end
+      end
+    end
+
+    describe 'target_line: option' do
+      before :each do
+        ScratchPad.record []
+      end
+
+      it "traces :line events only on specified line of code" do
+        trace = TracePoint.new(:line) do |tp|
+          ScratchPad << tp.lineno
+        end
+
+        target = -> {
+          x = 1
+          y = 2      # <= this line is target
+          z = x + y
+        }
+        _, lineno = target.source_location
+        target_line = lineno + 2
+
+        trace.enable(target_line: target_line, target: target) do
+          target.call
+        end
+
+        ScratchPad.recorded.should == [target_line]
+      end
+
+      it "raises ArgumentError if :target option isn't specified" do
+        trace = TracePoint.new(:line) do |tp|
+        end
+
+        lambda {
+          trace.enable(target_line: 67) do
+          end
+        }.should raise_error(ArgumentError, /only target_line is specified/)
+      end
+
+      it "raises ArgumentError if :line event isn't registered" do
+        trace = TracePoint.new(:call) do |tp|
+        end
+
+        target = -> {
+          x = 1
+          y = 2     # <= this line is target
+          z = x + y
+        }
+        _, lineno = target.source_location
+        target_line = lineno + 2
+
+        lambda {
+          trace.enable(target_line: target_line, target: target) do
+          end
+        }.should raise_error(ArgumentError, /target_line is specified, but line event is not specified/)
+      end
+
+      it "raises ArgumentError if :target_line value is out of target code lines range" do
+        trace = TracePoint.new(:line) do |tp|
+        end
+
+        lambda {
+          trace.enable(target_line: 1, target: -> { }) do
+          end
+        }.should raise_error(ArgumentError, /can not enable any hooks/)
+      end
+
+      it "raises TypeError if :target_line value couldn't be coerced to Integer" do
+        trace = TracePoint.new(:line) do |tp|
+        end
+
+        lambda {
+          trace.enable(target_line: Object.new, target: -> { }) do
+          end
+        }.should raise_error(TypeError, /no implicit conversion of \w+? into Integer/)
+      end
+
+      it "raises ArgumentError if :target_line value is negative" do
+        trace = TracePoint.new(:line) do |tp|
+        end
+
+        lambda {
+          trace.enable(target_line: -2, target: -> { }) do
+          end
+        }.should raise_error(ArgumentError, /can not enable any hooks/)
+      end
+
+      it "excepts value that could be coerced to Integer" do
+        trace = TracePoint.new(:line) do |tp|
+          ScratchPad << tp.lineno
+        end
+
+        target = -> {
+          x = 1         #  <= this line is target
+        }
+        _, lineno = target.source_location
+        target_line = lineno + 1
+
+        trace.enable(target_line: target_line.to_r, target: target) do
+          target.call
+        end
+
+        ScratchPad.recorded.should == [target_line]
+      end
+    end
+  end
 end
Index: spec/ruby/core/dir/children_spec.rb
===================================================================
--- spec/ruby/core/dir/children_spec.rb	(revision 67029)
+++ spec/ruby/core/dir/children_spec.rb	(revision 67030)
@@ -65,7 +65,7 @@ ruby_version_is "2.5" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/children_spec.rb#L65
       children.first.encoding.should equal(Encoding::EUC_KR)
     end
 
-    it "raises a SystemCallError if called with a nonexistent diretory" do
+    it "raises a SystemCallError if called with a nonexistent directory" do
       lambda { Dir.children DirSpecs.nonexistent }.should raise_error(SystemCallError)
     end
   end
Index: spec/ruby/core/dir/entries_spec.rb
===================================================================
--- spec/ruby/core/dir/entries_spec.rb	(revision 67029)
+++ spec/ruby/core/dir/entries_spec.rb	(revision 67030)
@@ -64,7 +64,7 @@ describe "Dir.entries" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/entries_spec.rb#L64
     entries.first.encoding.should equal(Encoding::EUC_KR)
   end
 
-  it "raises a SystemCallError if called with a nonexistent diretory" do
+  it "raises a SystemCallError if called with a nonexistent directory" do
     lambda { Dir.entries DirSpecs.nonexistent }.should raise_error(SystemCallError)
   end
 end
Index: spec/ruby/core/kernel/autoload_spec.rb
===================================================================
--- spec/r (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]