summaryrefslogtreecommitdiff
path: root/spec/ruby/core/tracepoint
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/tracepoint')
-rw-r--r--spec/ruby/core/tracepoint/allow_reentry_spec.rb30
-rw-r--r--spec/ruby/core/tracepoint/binding_spec.rb2
-rw-r--r--spec/ruby/core/tracepoint/defined_class_spec.rb10
-rw-r--r--spec/ruby/core/tracepoint/enable_spec.rb560
-rw-r--r--spec/ruby/core/tracepoint/eval_script_spec.rb30
-rw-r--r--spec/ruby/core/tracepoint/event_spec.rb6
-rw-r--r--spec/ruby/core/tracepoint/inspect_spec.rb48
-rw-r--r--spec/ruby/core/tracepoint/lineno_spec.rb2
-rw-r--r--spec/ruby/core/tracepoint/method_id_spec.rb2
-rw-r--r--spec/ruby/core/tracepoint/new_spec.rb22
-rw-r--r--spec/ruby/core/tracepoint/parameters_spec.rb42
-rw-r--r--spec/ruby/core/tracepoint/path_spec.rb4
-rw-r--r--spec/ruby/core/tracepoint/raised_exception_spec.rb18
-rw-r--r--spec/ruby/core/tracepoint/self_spec.rb4
14 files changed, 415 insertions, 365 deletions
diff --git a/spec/ruby/core/tracepoint/allow_reentry_spec.rb b/spec/ruby/core/tracepoint/allow_reentry_spec.rb
new file mode 100644
index 0000000000..475cca29a9
--- /dev/null
+++ b/spec/ruby/core/tracepoint/allow_reentry_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint.allow_reentry' do
+ it 'allows the reentrance in a given block' do
+ event_lines = []
+ l1 = l2 = l3 = l4 = nil
+ TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+
+ event_lines << tp.lineno
+ next if (__LINE__ + 2 .. __LINE__ + 4).cover?(tp.lineno)
+ TracePoint.allow_reentry do
+ a = 1; l3 = __LINE__
+ b = 2; l4 = __LINE__
+ end
+ end.enable do
+ c = 3; l1 = __LINE__
+ d = 4; l2 = __LINE__
+ end
+
+ event_lines.should == [l1, l3, l4, l2, l3, l4]
+ end
+
+ it 'raises RuntimeError when not called inside a TracePoint' do
+ -> {
+ TracePoint.allow_reentry{}
+ }.should.raise(RuntimeError)
+ end
+end
diff --git a/spec/ruby/core/tracepoint/binding_spec.rb b/spec/ruby/core/tracepoint/binding_spec.rb
index 6a7ef5f85a..6de6e47d7d 100644
--- a/spec/ruby/core/tracepoint/binding_spec.rb
+++ b/spec/ruby/core/tracepoint/binding_spec.rb
@@ -15,7 +15,7 @@ describe 'TracePoint#binding' do
test
}
bindings.size.should == 1
- bindings[0].should be_kind_of(Binding)
+ bindings[0].should.is_a?(Binding)
bindings[0].local_variables.should == [:secret]
end
end
diff --git a/spec/ruby/core/tracepoint/defined_class_spec.rb b/spec/ruby/core/tracepoint/defined_class_spec.rb
index 4593db6d1f..53c86a8210 100644
--- a/spec/ruby/core/tracepoint/defined_class_spec.rb
+++ b/spec/ruby/core/tracepoint/defined_class_spec.rb
@@ -9,19 +9,19 @@ describe 'TracePoint#defined_class' do
last_class_name = tp.defined_class
end.enable do
TracePointSpec::B.new.foo
- last_class_name.should equal(TracePointSpec::B)
+ last_class_name.should.equal?(TracePointSpec::B)
TracePointSpec::B.new.bar
- last_class_name.should equal(TracePointSpec::A)
+ last_class_name.should.equal?(TracePointSpec::A)
c = TracePointSpec::C.new
- last_class_name.should equal(TracePointSpec::C)
+ last_class_name.should.equal?(TracePointSpec::C)
c.foo
- last_class_name.should equal(TracePointSpec::B)
+ last_class_name.should.equal?(TracePointSpec::B)
c.bar
- last_class_name.should equal(TracePointSpec::A)
+ last_class_name.should.equal?(TracePointSpec::A)
end
end
end
diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb
index 50fded90e4..bf61c35154 100644
--- a/spec/ruby/core/tracepoint/enable_spec.rb
+++ b/spec/ruby/core/tracepoint/enable_spec.rb
@@ -54,10 +54,10 @@ describe 'TracePoint#enable' do
TracePoint.new(:line) do |tp|
next unless TracePointSpec.target_thread?
event_name = tp.event
- end.enable { event_name.should equal(:line) }
+ end.enable { event_name.should.equal?(:line) }
end
- it 'enables the trace object for any thread' do
+ it 'enables the trace object only for the current thread' do
threads = []
trace = TracePoint.new(:line) do |tp|
# Runs on purpose on any Thread
@@ -75,7 +75,7 @@ describe 'TracePoint#enable' do
threads = threads.uniq
threads.should.include?(Thread.current)
- threads.should.include?(thread)
+ threads.should_not.include?(thread)
end
it 'can accept arguments within a block but it should not yield arguments' do
@@ -85,7 +85,7 @@ describe 'TracePoint#enable' do
event_name = tp.event
end
trace.enable do |*args|
- event_name.should equal(:line)
+ event_name.should.equal?(:line)
args.should == []
end
trace.should_not.enabled?
@@ -124,13 +124,7 @@ describe 'TracePoint#enable' do
describe "when nested" do
before do
- ruby_version_is ""..."3.0" do
- @path_prefix = '@'
- end
-
- ruby_version_is "3.0" do
- @path_prefix = ' '
- end
+ @path_prefix = ' '
end
it "enables both TracePoints but only calls the respective callbacks" do
@@ -161,65 +155,112 @@ describe 'TracePoint#enable' do
end
end
- ruby_version_is "2.6" do
- describe 'target: option' do
- before :each do
- ScratchPad.record []
+ describe 'target: option' do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it 'enables trace point for specific location' do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
end
- it 'enables trace point for specific location' do
- trace = TracePoint.new(:call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << tp.method_id
- end
+ obj = Object.new
+ def obj.foo; end
+ def obj.bar; end
- obj = Object.new
- def obj.foo; end
- def obj.bar; end
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
+ obj.bar
+ end
- trace.enable(target: obj.method(:foo)) do
- obj.foo
- obj.bar
- end
+ ScratchPad.recorded.should == [:foo]
+ end
- ScratchPad.recorded.should == [:foo]
+ it 'traces all the events triggered in specified location' do
+ trace = TracePoint.new(:line, :call, :return, :b_call, :b_return) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.event
end
- it 'traces all the events triggered in specified location' do
- trace = TracePoint.new(:line, :call, :return, :b_call, :b_return) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << tp.event
- end
+ obj = Object.new
+ def obj.foo
+ bar
+ -> {}.call
+ end
+ def obj.bar; end
- obj = Object.new
- def obj.foo
- bar
- -> {}.call
+ 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|
+ next unless TracePointSpec.target_thread?
+ 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 obj.bar; end
- trace.enable(target: obj.method(:foo)) do
- obj.foo
+ def bar(&blk)
+ blk.call
end
+ end
+
+ trace = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
+ end
+
+ obj = klass.new
+ _, lineno = obj.method(:foo).source_location
- ScratchPad.recorded.uniq.sort.should == [:call, :return, :b_call, :b_return, :line].sort
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
end
- it 'does not trace events in nested locations' do
+ ScratchPad.recorded.should == (lineno+1..lineno+3).to_a
+ end
+
+ describe 'option value' do
+ it 'accepts Method' do
trace = TracePoint.new(:call) do |tp|
next unless TracePointSpec.target_thread?
ScratchPad << tp.method_id
end
obj = Object.new
- def obj.foo
- bar
- end
- def obj.bar
- baz
- end
- def obj.baz
- end
+ def obj.foo; end
trace.enable(target: obj.method(:foo)) do
obj.foo
@@ -228,324 +269,275 @@ describe 'TracePoint#enable' do
ScratchPad.recorded.should == [:foo]
end
- it "traces some events in nested blocks" do
+ it 'accepts UnboundMethod' do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
+
klass = Class.new do
- def foo
- 1.times do
- 1.times do
- bar do
- end
- end
- end
- end
+ def foo; end
+ end
- def bar(&blk)
- blk.call
- end
+ unbound_method = klass.instance_method(:foo)
+ trace.enable(target: unbound_method) do
+ klass.new.foo
end
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it 'accepts Proc' do
trace = TracePoint.new(:b_call) do |tp|
next unless TracePointSpec.target_thread?
ScratchPad << tp.lineno
end
- obj = klass.new
- _, lineno = obj.method(:foo).source_location
+ block = proc {}
+ _, lineno = block.source_location
- trace.enable(target: obj.method(:foo)) do
- obj.foo
+ trace.enable(target: block) do
+ block.call
end
- ScratchPad.recorded.should == (lineno+1..lineno+3).to_a
+ ScratchPad.recorded.should == [lineno]
+ lineno.should.is_a?(Integer)
end
+ end
- describe 'option value' do
- it 'accepts Method' do
- trace = TracePoint.new(:call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << tp.method_id
- end
-
- obj = Object.new
- def obj.foo; end
+ it "raises ArgumentError if target object cannot trigger specified event" do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
- trace.enable(target: obj.method(:foo)) do
- obj.foo
- end
+ block = proc {}
- ScratchPad.recorded.should == [:foo]
+ -> {
+ trace.enable(target: block) do
+ block.call # triggers :b_call and :b_return events
end
+ }.should.raise(ArgumentError, /can not enable any hooks/)
+ end
- it 'accepts UnboundMethod' do
- trace = TracePoint.new(:call) do |tp|
- next unless TracePointSpec.target_thread?
- 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
+ it "raises ArgumentError if passed not Method/UnboundMethod/Proc" do
+ trace = TracePoint.new(:call) {}
- ScratchPad.recorded.should == [:foo]
+ -> {
+ trace.enable(target: Object.new) do
end
+ }.should.raise(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) {}
- it 'accepts Proc' do
- trace = TracePoint.new(:b_call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << tp.lineno
+ -> {
+ trace.enable(target: -> {}) do
+ trace.enable(target: -> {}) do
+ end
end
+ }.should.raise(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ end
- block = proc {}
- _, lineno = block.source_location
+ it "raises ArgumentError if trace point already enabled without target is re-enabled with target" do
+ trace = TracePoint.new(:b_call) {}
- trace.enable(target: block) do
- block.call
+ -> {
+ trace.enable do
+ trace.enable(target: -> {}) do
+ end
end
-
- ScratchPad.recorded.should == [lineno]
- lineno.should be_kind_of(Integer)
- end
+ }.should.raise(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
end
- it "raises ArgumentError if target object cannot trigger specified event" do
- trace = TracePoint.new(:call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << tp.method_id
- end
-
- block = proc {}
+ it "raises ArgumentError if trace point already enabled with target is re-enabled without target" do
+ trace = TracePoint.new(:b_call) {}
-> {
- trace.enable(target: block) do
- block.call # triggers :b_call and :b_return events
+ trace.enable(target: -> {}) do
+ trace.enable do
+ end
end
- }.should raise_error(ArgumentError, /can not enable any hooks/)
+ }.should.raise(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
end
- it "raises ArgumentError if passed not Method/UnboundMethod/Proc" do
- trace = TracePoint.new(:call) {}
+ it "raises ArgumentError if trace point already enabled with target is disabled with block" do
+ trace = TracePoint.new(:b_call) {}
-> {
- trace.enable(target: Object.new) do
+ trace.enable(target: -> {}) do
+ trace.disable do
+ end
end
- }.should raise_error(ArgumentError, /specified target is not supported/)
+ }.should.raise(ArgumentError, /can't disable a targett?ing TracePoint in a block/)
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) {}
+ 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|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :outer
+ end
- -> {
- trace.enable(target: -> {}) do
- trace.enable(target: -> {}) do
- end
- end
- }.should raise_error(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ trace_inner = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :inner
end
- it "raises ArgumentError if trace point already enabled without target is re-enabled with target" do
- trace = TracePoint.new(:b_call) {}
+ target = -> {}
- -> {
- trace.enable do
- trace.enable(target: -> {}) do
- end
- end
- }.should raise_error(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ trace_outer.enable do
+ trace_inner.enable(target: target) do
+ target.call
+ end
end
- it "raises ArgumentError if trace point already enabled with target is re-enabled without target" do
- trace = TracePoint.new(:b_call) {}
+ ScratchPad.recorded.should == [:outer, :outer, :outer, :inner]
+ end
- -> {
- trace.enable(target: -> {}) do
- trace.enable do
- end
- end
- }.should raise_error(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ 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|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :outer
end
- it "raises ArgumentError if trace point already enabled with target is disabled with block" do
- trace = TracePoint.new(:b_call) {}
-
- -> {
- trace.enable(target: -> {}) do
- trace.disable do
- end
- end
- }.should raise_error(ArgumentError, /can't disable a targett?ing TracePoint in a block/)
+ trace_inner = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :inner
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|
- next unless TracePointSpec.target_thread?
- ScratchPad << :outer
- end
+ target = -> {}
- trace_inner = TracePoint.new(:b_call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << :inner
+ trace_outer.enable(target: target) do
+ trace_inner.enable(target: target) do
+ target.call
end
+ end
- target = -> {}
-
- trace_outer.enable do
- trace_inner.enable(target: target) do
- target.call
- end
- end
+ ScratchPad.recorded.should == [:inner, :outer]
+ end
- ScratchPad.recorded.should == [:outer, :outer, :outer, :inner]
+ 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|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :outer
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|
- next unless TracePointSpec.target_thread?
- ScratchPad << :outer
- end
-
- trace_inner = TracePoint.new(:b_call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << :inner
- end
+ trace_inner = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :inner
+ end
- target = -> {}
+ target = -> {}
- trace_outer.enable(target: target) do
- trace_inner.enable(target: target) do
- target.call
- end
+ trace_outer.enable(target: target) do
+ trace_inner.enable do
+ target.call
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|
- next unless TracePointSpec.target_thread?
- ScratchPad << :outer
- end
+ ScratchPad.recorded.should == [:inner, :inner, :outer]
+ end
+ end
+ end
- trace_inner = TracePoint.new(:b_call) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << :inner
- end
+ describe 'target_line: option' do
+ before :each do
+ ScratchPad.record []
+ end
- target = -> {}
+ it "traces :line events only on specified line of code" do
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
+ end
- trace_outer.enable(target: target) do
- trace_inner.enable do
- target.call
- end
- end
+ target = -> {
+ x = 1
+ y = 2 # <= this line is target
+ z = x + y
+ }
+ _, lineno = target.source_location
+ target_line = lineno + 2
- ScratchPad.recorded.should == [:inner, :inner, :outer]
- end
+ trace.enable(target_line: target_line, target: target) do
+ target.call
end
+
+ ScratchPad.recorded.should == [target_line]
end
- describe 'target_line: option' do
- before :each do
- ScratchPad.record []
- end
+ it "raises ArgumentError if :target option isn't specified" do
+ trace = TracePoint.new(:line) {}
- it "traces :line events only on specified line of code" do
- trace = TracePoint.new(:line) do |tp|
- next unless TracePointSpec.target_thread?
- ScratchPad << tp.lineno
+ -> {
+ trace.enable(target_line: 67) do
end
+ }.should.raise(ArgumentError, /only target_line is specified/)
+ end
+
+ it "raises ArgumentError if :line event isn't registered" do
+ trace = TracePoint.new(:call) {}
- target = -> {
- x = 1
- y = 2 # <= this line is target
- z = x + y
- }
- _, lineno = target.source_location
- target_line = lineno + 2
+ 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
+ }.should.raise(ArgumentError, /target_line is specified, but line event is not specified/)
+ end
- ScratchPad.recorded.should == [target_line]
- end
-
- it "raises ArgumentError if :target option isn't specified" do
- trace = TracePoint.new(:line) {}
-
- -> {
- 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) {}
+ it "raises ArgumentError if :target_line value is out of target code lines range" do
+ trace = TracePoint.new(:line) {}
- target = -> {
- x = 1
- y = 2 # <= this line is target
- z = x + y
- }
- _, lineno = target.source_location
- target_line = lineno + 2
+ -> {
+ trace.enable(target_line: 1, target: -> { }) do
+ end
+ }.should.raise(ArgumentError, /can not enable any hooks/)
+ end
- -> {
- 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 TypeError if :target_line value couldn't be coerced to Integer" do
+ trace = TracePoint.new(:line) {}
- it "raises ArgumentError if :target_line value is out of target code lines range" do
- trace = TracePoint.new(:line) {}
+ -> {
+ trace.enable(target_line: Object.new, target: -> { }) do
+ end
+ }.should.raise(TypeError, /no implicit conversion of \w+? into Integer/)
+ end
- -> {
- trace.enable(target_line: 1, target: -> { }) do
- end
- }.should raise_error(ArgumentError, /can not enable any hooks/)
- end
+ it "raises ArgumentError if :target_line value is negative" do
+ trace = TracePoint.new(:line) {}
- it "raises TypeError if :target_line value couldn't be coerced to Integer" do
- trace = TracePoint.new(:line) {}
+ -> {
+ trace.enable(target_line: -2, target: -> { }) do
+ end
+ }.should.raise(ArgumentError, /can not enable any hooks/)
+ end
- -> {
- trace.enable(target_line: Object.new, target: -> { }) do
- end
- }.should raise_error(TypeError, /no implicit conversion of \w+? into Integer/)
+ it "accepts value that could be coerced to Integer" do
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
end
- it "raises ArgumentError if :target_line value is negative" do
- trace = TracePoint.new(:line) {}
+ target = -> {
+ x = 1 # <= this line is target
+ }
+ _, lineno = target.source_location
+ target_line = lineno + 1
- -> {
- trace.enable(target_line: -2, target: -> { }) do
- end
- }.should raise_error(ArgumentError, /can not enable any hooks/)
+ trace.enable(target_line: target_line.to_r, target: target) do
+ target.call
end
- it "accepts value that could be coerced to Integer" do
- trace = TracePoint.new(:line) do |tp|
- next unless TracePointSpec.target_thread?
- 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
+ ScratchPad.recorded.should == [target_line]
end
end
end
diff --git a/spec/ruby/core/tracepoint/eval_script_spec.rb b/spec/ruby/core/tracepoint/eval_script_spec.rb
index ccf7fb5975..7ec53e7094 100644
--- a/spec/ruby/core/tracepoint/eval_script_spec.rb
+++ b/spec/ruby/core/tracepoint/eval_script_spec.rb
@@ -1,25 +1,23 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.6" do
- describe "TracePoint#eval_script" do
- it "is the evald source code" do
- ScratchPad.record []
+describe "TracePoint#eval_script" do
+ it "is the evald source code" do
+ ScratchPad.record []
- script = <<-CODE
- def foo
- p :hello
- end
- CODE
-
- TracePoint.new(:script_compiled) do |e|
- next unless TracePointSpec.target_thread?
- ScratchPad << e.eval_script
- end.enable do
- eval script
+ script = <<-CODE
+ def foo
+ p :hello
end
+ CODE
- ScratchPad.recorded.should == [script]
+ TracePoint.new(:script_compiled) do |e|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << e.eval_script
+ end.enable do
+ eval script
end
+
+ ScratchPad.recorded.should == [script]
end
end
diff --git a/spec/ruby/core/tracepoint/event_spec.rb b/spec/ruby/core/tracepoint/event_spec.rb
index 9dea24d125..58017dc98d 100644
--- a/spec/ruby/core/tracepoint/event_spec.rb
+++ b/spec/ruby/core/tracepoint/event_spec.rb
@@ -9,13 +9,13 @@ describe 'TracePoint#event' do
event_name = tp.event
end.enable do
TracePointSpec.test
- event_name.should equal(:call)
+ event_name.should.equal?(:call)
TracePointSpec::B.new.foo
- event_name.should equal(:call)
+ event_name.should.equal?(:call)
class TracePointSpec::B; end
- event_name.should equal(:end)
+ event_name.should.equal?(:end)
end
end
diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb
index 06bed9c99a..6cc2ebe243 100644
--- a/spec/ruby/core/tracepoint/inspect_spec.rb
+++ b/spec/ruby/core/tracepoint/inspect_spec.rb
@@ -3,24 +3,29 @@ require_relative 'fixtures/classes'
describe 'TracePoint#inspect' do
before do
- ruby_version_is ""..."3.0" do
- @path_prefix = '@'
- end
-
- ruby_version_is "3.0" do
- @path_prefix = ' '
- end
+ @path_prefix = ' '
end
it 'returns a string containing a human-readable TracePoint status' do
TracePoint.new(:line) {}.inspect.should == '#<TracePoint:disabled>'
end
+ it "shows only whether it's enabled when outside the TracePoint handler" do
+ trace = TracePoint.new(:line) {}
+ trace.enable
+
+ trace.inspect.should == '#<TracePoint:enabled>'
+
+ trace.disable
+ end
+
it 'returns a String showing the event, path and line' do
inspect = nil
line = nil
TracePoint.new(:line) { |tp|
next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
inspect ||= tp.inspect
}.enable do
line = __LINE__
@@ -34,6 +39,8 @@ describe 'TracePoint#inspect' do
line = nil
TracePoint.new(:call) { |tp|
next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
inspect ||= tp.inspect
}.enable do
line = __LINE__ + 1
@@ -41,7 +48,7 @@ describe 'TracePoint#inspect' do
trace_point_spec_test_call
end
- inspect.should == "#<TracePoint:call `trace_point_spec_test_call'#{@path_prefix}#{__FILE__}:#{line}>"
+ inspect.should =~ /\A#<TracePoint:call [`']trace_point_spec_test_call'#{@path_prefix}#{__FILE__}:#{line}>\z/
end
it 'returns a String showing the event, method, path and line for a :return event' do
@@ -49,6 +56,8 @@ describe 'TracePoint#inspect' do
line = nil
TracePoint.new(:return) { |tp|
next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
inspect ||= tp.inspect
}.enable do
line = __LINE__ + 4
@@ -58,22 +67,25 @@ describe 'TracePoint#inspect' do
end
trace_point_spec_test_return
end
+ ruby_version_is("3.4") { line -= 1 }
- inspect.should == "#<TracePoint:return `trace_point_spec_test_return'#{@path_prefix}#{__FILE__}:#{line}>"
+ inspect.should =~ /\A#<TracePoint:return [`']trace_point_spec_test_return'#{@path_prefix}#{__FILE__}:#{line}>\z/
end
it 'returns a String showing the event, method, path and line for a :c_call event' do
inspect = nil
- line = nil
- TracePoint.new(:c_call) { |tp|
+ tracepoint = TracePoint.new(:c_call) { |tp|
next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
inspect ||= tp.inspect
- }.enable do
- line = __LINE__ + 1
+ }
+ line = __LINE__ + 2
+ tracepoint.enable do
[0, 1].max
end
- inspect.should == "#<TracePoint:c_call `max'#{@path_prefix}#{__FILE__}:#{line}>"
+ inspect.should =~ /\A#<TracePoint:c_call [`']max'#{@path_prefix}#{__FILE__}:#{line}>\z/
end
it 'returns a String showing the event, path and line for a :class event' do
@@ -81,6 +93,8 @@ describe 'TracePoint#inspect' do
line = nil
TracePoint.new(:class) { |tp|
next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
inspect ||= tp.inspect
}.enable do
line = __LINE__ + 1
@@ -97,8 +111,9 @@ describe 'TracePoint#inspect' do
thread_inspection = nil
TracePoint.new(:thread_begin) { |tp|
next unless Thread.current == thread
+
inspect ||= tp.inspect
- }.enable do
+ }.enable(target_thread: nil) do
thread = Thread.new {}
thread_inspection = thread.inspect
thread.join
@@ -113,8 +128,9 @@ describe 'TracePoint#inspect' do
thread_inspection = nil
TracePoint.new(:thread_end) { |tp|
next unless Thread.current == thread
+
inspect ||= tp.inspect
- }.enable do
+ }.enable(target_thread: nil) do
thread = Thread.new {}
thread_inspection = thread.inspect
thread.join
diff --git a/spec/ruby/core/tracepoint/lineno_spec.rb b/spec/ruby/core/tracepoint/lineno_spec.rb
index 77b3ac8b54..7c46d5222b 100644
--- a/spec/ruby/core/tracepoint/lineno_spec.rb
+++ b/spec/ruby/core/tracepoint/lineno_spec.rb
@@ -15,6 +15,6 @@ describe 'TracePoint#lineno' do
it 'raises RuntimeError if accessed from outside' do
tp = TracePoint.new(:line) {}
- -> { tp.lineno }.should raise_error(RuntimeError, 'access from outside')
+ -> { tp.lineno }.should.raise(RuntimeError, 'access from outside')
end
end
diff --git a/spec/ruby/core/tracepoint/method_id_spec.rb b/spec/ruby/core/tracepoint/method_id_spec.rb
index 43e23248b7..67740f2d7d 100644
--- a/spec/ruby/core/tracepoint/method_id_spec.rb
+++ b/spec/ruby/core/tracepoint/method_id_spec.rb
@@ -9,7 +9,7 @@ describe 'TracePoint#method_id' do
method_name = tp.method_id
}.enable do
TracePointSpec.test
- method_name.should equal(:test)
+ method_name.should.equal?(:test)
end
end
end
diff --git a/spec/ruby/core/tracepoint/new_spec.rb b/spec/ruby/core/tracepoint/new_spec.rb
index e53c2b04a2..763b35292b 100644
--- a/spec/ruby/core/tracepoint/new_spec.rb
+++ b/spec/ruby/core/tracepoint/new_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe 'TracePoint.new' do
it 'returns a new TracePoint object, not enabled by default' do
- TracePoint.new(:line) {}.enabled?.should be_false
+ TracePoint.new(:line) {}.enabled?.should == false
end
it 'includes :line event when event is not specified' do
@@ -12,15 +12,15 @@ describe 'TracePoint.new' do
next unless TracePointSpec.target_thread?
event_name = tp.event
}.enable do
- event_name.should equal(:line)
+ event_name.should.equal?(:line)
event_name = nil
TracePointSpec.test
- event_name.should equal(:line)
+ event_name.should.equal?(:line)
event_name = nil
TracePointSpec::B.new.foo
- event_name.should equal(:line)
+ event_name.should.equal?(:line)
end
end
@@ -44,29 +44,29 @@ describe 'TracePoint.new' do
event_name = tp.event
end.enable do
TracePointSpec.test
- event_name.should equal(:call)
+ event_name.should.equal?(:call)
TracePointSpec::B.new.foo
- event_name.should equal(:call)
+ event_name.should.equal?(:call)
class TracePointSpec::B; end
- event_name.should equal(:end)
+ event_name.should.equal?(:end)
end
end
it 'raises a TypeError when the given object is not a string/symbol' do
o = mock('123')
- -> { TracePoint.new(o) {} }.should raise_error(TypeError)
+ -> { TracePoint.new(o) {} }.should.raise(TypeError)
o.should_receive(:to_sym).and_return(123)
- -> { TracePoint.new(o) {} }.should raise_error(TypeError)
+ -> { TracePoint.new(o) {} }.should.raise(TypeError)
end
it 'expects to be called with a block' do
- -> { TracePoint.new(:line) }.should raise_error(ArgumentError, "must be called with a block")
+ -> { TracePoint.new(:line) }.should.raise(ArgumentError, "must be called with a block")
end
it "raises a Argument error when the given argument doesn't match an event name" do
- -> { TracePoint.new(:test) }.should raise_error(ArgumentError, "unknown event: test")
+ -> { TracePoint.new(:test) }.should.raise(ArgumentError, "unknown event: test")
end
end
diff --git a/spec/ruby/core/tracepoint/parameters_spec.rb b/spec/ruby/core/tracepoint/parameters_spec.rb
index 3a2cdd7750..82aee3caa4 100644
--- a/spec/ruby/core/tracepoint/parameters_spec.rb
+++ b/spec/ruby/core/tracepoint/parameters_spec.rb
@@ -1,30 +1,28 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.6" do
- describe 'TracePoint#parameters' do
- it 'returns the parameters of block' do
- f = proc {|x, y, z| }
- parameters = nil
- TracePoint.new(:b_call) { |tp|
- next unless TracePointSpec.target_thread?
- parameters = tp.parameters
- }.enable do
- f.call
- parameters.should == [[:opt, :x], [:opt, :y], [:opt, :z]]
- end
+describe 'TracePoint#parameters' do
+ it 'returns the parameters of block' do
+ f = proc {|x, y, z| }
+ parameters = nil
+ TracePoint.new(:b_call) { |tp|
+ next unless TracePointSpec.target_thread?
+ parameters = tp.parameters
+ }.enable do
+ f.call
+ parameters.should == [[:opt, :x], [:opt, :y], [:opt, :z]]
end
+ end
- it 'returns the parameters of lambda block' do
- f = -> x, y, z { }
- parameters = nil
- TracePoint.new(:b_call) { |tp|
- next unless TracePointSpec.target_thread?
- parameters = tp.parameters
- }.enable do
- f.call(1, 2, 3)
- parameters.should == [[:req, :x], [:req, :y], [:req, :z]]
- end
+ it 'returns the parameters of lambda block' do
+ f = -> x, y, z { }
+ parameters = nil
+ TracePoint.new(:b_call) { |tp|
+ next unless TracePointSpec.target_thread?
+ parameters = tp.parameters
+ }.enable do
+ f.call(1, 2, 3)
+ parameters.should == [[:req, :x], [:req, :y], [:req, :z]]
end
end
end
diff --git a/spec/ruby/core/tracepoint/path_spec.rb b/spec/ruby/core/tracepoint/path_spec.rb
index 5b6c6d4cfc..aa6868ead2 100644
--- a/spec/ruby/core/tracepoint/path_spec.rb
+++ b/spec/ruby/core/tracepoint/path_spec.rb
@@ -13,7 +13,7 @@ describe 'TracePoint#path' do
path.should == "#{__FILE__}"
end
- it 'equals (eval) inside an eval for :end event' do
+ it 'equals "(eval at __FILE__:__LINE__)" inside an eval for :end event' do
path = nil
TracePoint.new(:end) { |tp|
next unless TracePointSpec.target_thread?
@@ -21,6 +21,6 @@ describe 'TracePoint#path' do
}.enable do
eval("module TracePointSpec; end")
end
- path.should == '(eval)'
+ path.should == "(eval at #{__FILE__}:#{__LINE__ - 2})"
end
end
diff --git a/spec/ruby/core/tracepoint/raised_exception_spec.rb b/spec/ruby/core/tracepoint/raised_exception_spec.rb
index ca2f50abb3..b1199902f2 100644
--- a/spec/ruby/core/tracepoint/raised_exception_spec.rb
+++ b/spec/ruby/core/tracepoint/raised_exception_spec.rb
@@ -14,7 +14,23 @@ describe 'TracePoint#raised_exception' do
rescue => e
error_result = e
end
- raised_exception.should equal(error_result)
+ raised_exception.should.equal?(error_result)
+ end
+ end
+
+ it 'returns value from exception rescued on the :rescue event' do
+ raised_exception, error_result = nil
+ trace = TracePoint.new(:rescue) { |tp|
+ next unless TracePointSpec.target_thread?
+ raised_exception = tp.raised_exception
+ }
+ trace.enable do
+ begin
+ raise StandardError
+ rescue => e
+ error_result = e
+ end
+ raised_exception.should.equal?(error_result)
end
end
end
diff --git a/spec/ruby/core/tracepoint/self_spec.rb b/spec/ruby/core/tracepoint/self_spec.rb
index 2098860e59..bf9a2b6a45 100644
--- a/spec/ruby/core/tracepoint/self_spec.rb
+++ b/spec/ruby/core/tracepoint/self_spec.rb
@@ -8,7 +8,7 @@ describe 'TracePoint#self' do
next unless TracePointSpec.target_thread?
trace = tp.self
}.enable do
- trace.equal?(self).should be_true
+ trace.equal?(self).should == true
end
end
@@ -21,6 +21,6 @@ describe 'TracePoint#self' do
class TracePointSpec::C
end
end
- trace.should equal TracePointSpec::C
+ trace.should.equal? TracePointSpec::C
end
end