From 244ea65e119d7ce9b52d37ff4c5b1aa6df74f943 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 20:56:10 +0530 Subject: [PATCH 01/42] Add spec for TracePoint#new --- core/tracepoint/new_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 core/tracepoint/new_spec.rb diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb new file mode 100644 index 0000000000..c46d9240c9 --- /dev/null +++ b/core/tracepoint/new_spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint.new' do + it 'returns a new TracePoint object, not enabled by default' do + TracePoint.new(:call) {}.enabled?.should be_false + end + end +end From edf50d2ec3d7a8ccc4cec3cb07abd7f4265197d8 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 20:56:59 +0530 Subject: [PATCH 02/42] Add spec for TracePoint#trace --- core/tracepoint/trace_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 core/tracepoint/trace_spec.rb diff --git a/core/tracepoint/trace_spec.rb b/core/tracepoint/trace_spec.rb new file mode 100644 index 0000000000..69784a8c48 --- /dev/null +++ b/core/tracepoint/trace_spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint.trace' do + it 'activates the trace automatically' do + TracePoint.trace(:call) {}.enabled?.should be_true + end + end +end From 4f9e612474d66a2efff14c6a6fe354731ab38943 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 20:57:25 +0530 Subject: [PATCH 03/42] Add specs for TracePoint#disable --- core/tracepoint/disable_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core/tracepoint/disable_spec.rb diff --git a/core/tracepoint/disable_spec.rb b/core/tracepoint/disable_spec.rb new file mode 100644 index 0000000000..aacc6a6e13 --- /dev/null +++ b/core/tracepoint/disable_spec.rb @@ -0,0 +1,20 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#disable' do + context 'deactivates the trace' do + it 'returns true if trace was enabled' do + trace = TracePoint.new(:call) {} + trace.enable + trace.disable.should be_true + end + + it 'returns false if trace was disabled' do + trace = TracePoint.new(:call) {} + trace.enable + trace.disable + trace.disable.should be_false + end + end + end +end From 25b4f269641721ec6bc7f34f072ff661b5e2a4b2 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:43:33 +0530 Subject: [PATCH 04/42] Add specs for TracePoint#enable --- core/tracepoint/enable_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core/tracepoint/enable_spec.rb diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb new file mode 100644 index 0000000000..c7842a7d11 --- /dev/null +++ b/core/tracepoint/enable_spec.rb @@ -0,0 +1,20 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#enable' do + context 'activates the trace' do + it 'returns true if trace was enabled' do + trace = TracePoint.new(:call) {} + trace.enable + trace.enable.should be_true + end + + it 'returns false if trace was disabled' do + trace = TracePoint.new(:call) {} + trace.enable + trace.disable + trace.enable.should be_false + end + end + end +end From 47138a18aeacf8fec37c2e6546602643c6e2c971 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:55:56 +0530 Subject: [PATCH 05/42] Add spec for TracePoint#binding --- core/tracepoint/binding_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 core/tracepoint/binding_spec.rb diff --git a/core/tracepoint/binding_spec.rb b/core/tracepoint/binding_spec.rb new file mode 100644 index 0000000000..be5277026b --- /dev/null +++ b/core/tracepoint/binding_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#binding' do + it 'return the generated binding object from event' do + binding = nil + TracePoint.new(:line) { |tp| binding = tp.binding }.enable + binding.should be_kind_of(Binding) + end + end +end From 9ab3a7ab965e1fd3f17ca74bc809a0b12b902985 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:56:23 +0530 Subject: [PATCH 06/42] Add spec for TracePoint#defined_class --- core/tracepoint/defined_class_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 core/tracepoint/defined_class_spec.rb diff --git a/core/tracepoint/defined_class_spec.rb b/core/tracepoint/defined_class_spec.rb new file mode 100644 index 0000000000..957955560c --- /dev/null +++ b/core/tracepoint/defined_class_spec.rb @@ -0,0 +1,17 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#defined_class' do + class A; def foo; end; end + + it 'returns class or module of the method being called' do + class_name = nil + TracePoint.new(:call) do |tp| + class_name = tp.defined_class + end.enable do + A.new.foo + class_name.should equal(A) + end + end + end +end From c3d3ea86f5c01f2a91fe037a233e033ee6e81f1e Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:57:04 +0530 Subject: [PATCH 07/42] Add spec for TracePoint#enabled? --- core/tracepoint/enabled_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 core/tracepoint/enabled_spec.rb diff --git a/core/tracepoint/enabled_spec.rb b/core/tracepoint/enabled_spec.rb new file mode 100644 index 0000000000..662d825b62 --- /dev/null +++ b/core/tracepoint/enabled_spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#enabled?' do + it 'returns the current status of the trace' do + TracePoint.new(:call) {}.enabled?.should be_false + end + end +end From da7768afef8b154aa53dadcd9554a89c407cee9b Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:57:24 +0530 Subject: [PATCH 08/42] Add spec for TracePoint#event --- core/tracepoint/event_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 core/tracepoint/event_spec.rb diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb new file mode 100644 index 0000000000..a018416378 --- /dev/null +++ b/core/tracepoint/event_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#event' do + it 'returns the type of event' do + event_name = nil + TracePoint.new(:line) { |tp| event_name = tp.event }.enable + event_name.should equal(:line) + end + end +end From 2f2437d866714a7b2b5e697d87b5cebd1053e9d6 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:57:43 +0530 Subject: [PATCH 09/42] Add spec for TracePoint#inspect --- core/tracepoint/inspect_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 core/tracepoint/inspect_spec.rb diff --git a/core/tracepoint/inspect_spec.rb b/core/tracepoint/inspect_spec.rb new file mode 100644 index 0000000000..f6a841222d --- /dev/null +++ b/core/tracepoint/inspect_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#inspect' do + it 'return a string containing a human-readable TracePoint status' do + TracePoint.new(:call) {}.inspect.should == + '#' + end + end +end From c2cff28329d345efe2826803b32e817fb3503134 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:58:11 +0530 Subject: [PATCH 10/42] Add spec for TracePoint#lineno --- core/tracepoint/lineno_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 core/tracepoint/lineno_spec.rb diff --git a/core/tracepoint/lineno_spec.rb b/core/tracepoint/lineno_spec.rb new file mode 100644 index 0000000000..12064e166d --- /dev/null +++ b/core/tracepoint/lineno_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#lineno' do + it 'returns the line number of the event' do + lineno = nil + TracePoint.new(:line) { |tp| lineno = tp.lineno }.enable + lineno.should equal(8) + end + end +end From 5db554f2db4110d4508b9ba2d371bc0c3b6f5d6d Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:59:29 +0530 Subject: [PATCH 11/42] Add spec for TracePoint#method_id --- core/tracepoint/method_id_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 core/tracepoint/method_id_spec.rb diff --git a/core/tracepoint/method_id_spec.rb b/core/tracepoint/method_id_spec.rb new file mode 100644 index 0000000000..d3f3941f18 --- /dev/null +++ b/core/tracepoint/method_id_spec.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#method_id' do + def test; end + + it 'returns the name at the definition of the method being called' do + method_name = nil + TracePoint.new(:call) { |tp| method_name = tp.method_id}.enable + test + method_name.should equal(:test) + end + end +end From 38b985bab8c85fa8a1c28d7eb3b000e2620c4063 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 15 Oct 2017 23:59:58 +0530 Subject: [PATCH 12/42] Add spec for TracePoint#path --- core/tracepoint/path_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 core/tracepoint/path_spec.rb diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb new file mode 100644 index 0000000000..20fcbf800a --- /dev/null +++ b/core/tracepoint/path_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#path' do + it 'returns the path of the file being run' do + path = nil + TracePoint.new(:line) { |tp| path = tp.path }.enable + path.should == "#{__FILE__}" + end + end +end From 25e1d9840a4cad37a0ac10fa1544f5e60b742d2b Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 00:00:45 +0530 Subject: [PATCH 13/42] Add spec for TracePoint#raised_exception --- core/tracepoint/raised_exception_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 core/tracepoint/raised_exception_spec.rb diff --git a/core/tracepoint/raised_exception_spec.rb b/core/tracepoint/raised_exception_spec.rb new file mode 100644 index 0000000000..e6498b5fde --- /dev/null +++ b/core/tracepoint/raised_exception_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#raised_exception' do + it 'returns value from exception raised on the :raise event' do + value = nil + trace = TracePoint.new(:raise) { |tp| value = tp.raised_exception } + trace.enable + begin + raise StandardError + rescue => _ ; end + value.should be_kind_of(StandardError) + end + end +end From d980bf746ebf789b389f44e974740b13068f8501 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 00:01:06 +0530 Subject: [PATCH 14/42] Add spec for TracePoint#return_value --- core/tracepoint/return_value_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 core/tracepoint/return_value_spec.rb diff --git a/core/tracepoint/return_value_spec.rb b/core/tracepoint/return_value_spec.rb new file mode 100644 index 0000000000..d3922acd41 --- /dev/null +++ b/core/tracepoint/return_value_spec.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#return_value' do + def test; end + + it 'returns value from :return event' do + trace_value = nil + TracePoint.new(:return) { |tp| trace_value = tp.return_value}.enable + test + trace_value.should equal(nil) + end + end +end From 55099121233d9abe891cfc6998402fed6999256b Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 00:01:23 +0530 Subject: [PATCH 15/42] Add spec for TracePoint#self --- core/tracepoint/self_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 core/tracepoint/self_spec.rb diff --git a/core/tracepoint/self_spec.rb b/core/tracepoint/self_spec.rb new file mode 100644 index 0000000000..a41611bb5b --- /dev/null +++ b/core/tracepoint/self_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +ruby_version_is '2.4' do + describe 'TracePoint#self' do + it 'return the trace object from event' do + trace = nil + TracePoint.new(:line) { |tp| trace = tp.self }.enable + trace.should be_kind_of(MSpecEnv) + end + end +end From b41bb0a65d0350ce75b4451452522f72959145f8 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 10:33:39 +0530 Subject: [PATCH 16/42] Rename ruby version to 2.0, since TracePoint was introduced in 2.0 --- core/tracepoint/binding_spec.rb | 2 +- core/tracepoint/defined_class_spec.rb | 2 +- core/tracepoint/disable_spec.rb | 2 +- core/tracepoint/enable_spec.rb | 2 +- core/tracepoint/enabled_spec.rb | 2 +- core/tracepoint/event_spec.rb | 2 +- core/tracepoint/inspect_spec.rb | 2 +- core/tracepoint/lineno_spec.rb | 2 +- core/tracepoint/method_id_spec.rb | 2 +- core/tracepoint/new_spec.rb | 2 +- core/tracepoint/path_spec.rb | 2 +- core/tracepoint/raised_exception_spec.rb | 2 +- core/tracepoint/return_value_spec.rb | 2 +- core/tracepoint/self_spec.rb | 2 +- core/tracepoint/trace_spec.rb | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/tracepoint/binding_spec.rb b/core/tracepoint/binding_spec.rb index be5277026b..939b009b10 100644 --- a/core/tracepoint/binding_spec.rb +++ b/core/tracepoint/binding_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#binding' do it 'return the generated binding object from event' do binding = nil diff --git a/core/tracepoint/defined_class_spec.rb b/core/tracepoint/defined_class_spec.rb index 957955560c..3bbb5fba22 100644 --- a/core/tracepoint/defined_class_spec.rb +++ b/core/tracepoint/defined_class_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#defined_class' do class A; def foo; end; end diff --git a/core/tracepoint/disable_spec.rb b/core/tracepoint/disable_spec.rb index aacc6a6e13..ce4048c9fe 100644 --- a/core/tracepoint/disable_spec.rb +++ b/core/tracepoint/disable_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#disable' do context 'deactivates the trace' do it 'returns true if trace was enabled' do diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index c7842a7d11..5d9905e204 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#enable' do context 'activates the trace' do it 'returns true if trace was enabled' do diff --git a/core/tracepoint/enabled_spec.rb b/core/tracepoint/enabled_spec.rb index 662d825b62..56155a4e03 100644 --- a/core/tracepoint/enabled_spec.rb +++ b/core/tracepoint/enabled_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#enabled?' do it 'returns the current status of the trace' do TracePoint.new(:call) {}.enabled?.should be_false diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb index a018416378..0e64f17a10 100644 --- a/core/tracepoint/event_spec.rb +++ b/core/tracepoint/event_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#event' do it 'returns the type of event' do event_name = nil diff --git a/core/tracepoint/inspect_spec.rb b/core/tracepoint/inspect_spec.rb index f6a841222d..ed14f24eda 100644 --- a/core/tracepoint/inspect_spec.rb +++ b/core/tracepoint/inspect_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#inspect' do it 'return a string containing a human-readable TracePoint status' do TracePoint.new(:call) {}.inspect.should == diff --git a/core/tracepoint/lineno_spec.rb b/core/tracepoint/lineno_spec.rb index 12064e166d..c525f22d94 100644 --- a/core/tracepoint/lineno_spec.rb +++ b/core/tracepoint/lineno_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#lineno' do it 'returns the line number of the event' do lineno = nil diff --git a/core/tracepoint/method_id_spec.rb b/core/tracepoint/method_id_spec.rb index d3f3941f18..795f35a45c 100644 --- a/core/tracepoint/method_id_spec.rb +++ b/core/tracepoint/method_id_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#method_id' do def test; end diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index c46d9240c9..97c1798e86 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint.new' do it 'returns a new TracePoint object, not enabled by default' do TracePoint.new(:call) {}.enabled?.should be_false diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb index 20fcbf800a..c2f400c745 100644 --- a/core/tracepoint/path_spec.rb +++ b/core/tracepoint/path_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#path' do it 'returns the path of the file being run' do path = nil diff --git a/core/tracepoint/raised_exception_spec.rb b/core/tracepoint/raised_exception_spec.rb index e6498b5fde..8e104a300a 100644 --- a/core/tracepoint/raised_exception_spec.rb +++ b/core/tracepoint/raised_exception_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#raised_exception' do it 'returns value from exception raised on the :raise event' do value = nil diff --git a/core/tracepoint/return_value_spec.rb b/core/tracepoint/return_value_spec.rb index d3922acd41..27f84f95e7 100644 --- a/core/tracepoint/return_value_spec.rb +++ b/core/tracepoint/return_value_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#return_value' do def test; end diff --git a/core/tracepoint/self_spec.rb b/core/tracepoint/self_spec.rb index a41611bb5b..913736c94e 100644 --- a/core/tracepoint/self_spec.rb +++ b/core/tracepoint/self_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint#self' do it 'return the trace object from event' do trace = nil diff --git a/core/tracepoint/trace_spec.rb b/core/tracepoint/trace_spec.rb index 69784a8c48..f120961cea 100644 --- a/core/tracepoint/trace_spec.rb +++ b/core/tracepoint/trace_spec.rb @@ -1,6 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is '2.4' do +ruby_version_is '2.0' do describe 'TracePoint.trace' do it 'activates the trace automatically' do TracePoint.trace(:call) {}.enabled?.should be_true From 03a2cb50306227081ce483ee14b1bc520bb157af Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:00:59 +0530 Subject: [PATCH 17/42] TracePoint#defined_class check for module & calls made in inheritance chain --- core/tracepoint/defined_class_spec.rb | 41 +++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/core/tracepoint/defined_class_spec.rb b/core/tracepoint/defined_class_spec.rb index 3bbb5fba22..584945f886 100644 --- a/core/tracepoint/defined_class_spec.rb +++ b/core/tracepoint/defined_class_spec.rb @@ -2,16 +2,47 @@ ruby_version_is '2.0' do describe 'TracePoint#defined_class' do - class A; def foo; end; end + module A; def bar; end; end + + class B + include A + def foo; end; + end + + class C < B + def initialize + super + end + + def foo + super + end + + def bar + super + end + end it 'returns class or module of the method being called' do class_name = nil TracePoint.new(:call) do |tp| class_name = tp.defined_class - end.enable do - A.new.foo - class_name.should equal(A) - end + end.enable + + B.new.foo + class_name.should equal(B) + + B.new.bar + class_name.should equal(A) + + c = C.new + class_name.should equal(C) + + c.foo + class_name.should equal(B) + + c.bar + class_name.should equal(A) end end end From 6aff6e5718a8418bfe401ef16de3313d3195db2e Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:03:32 +0530 Subject: [PATCH 18/42] Update TracePoint#self spec --- core/tracepoint/self_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tracepoint/self_spec.rb b/core/tracepoint/self_spec.rb index 913736c94e..8ad38746ed 100644 --- a/core/tracepoint/self_spec.rb +++ b/core/tracepoint/self_spec.rb @@ -5,7 +5,7 @@ it 'return the trace object from event' do trace = nil TracePoint.new(:line) { |tp| trace = tp.self }.enable - trace.should be_kind_of(MSpecEnv) + trace.equal?(self).should be_true end end end From 996ac8aa6c197c0fc54911bf7940c465f28f8456 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:38:12 +0530 Subject: [PATCH 19/42] TracePoint#enable TracePoint#disable - Add specs Add specs to check that a trace doesn't call the block until it's enabled. --- core/tracepoint/disable_spec.rb | 35 ++++++++++++++++------- core/tracepoint/enable_spec.rb | 49 ++++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/core/tracepoint/disable_spec.rb b/core/tracepoint/disable_spec.rb index ce4048c9fe..3c13075f24 100644 --- a/core/tracepoint/disable_spec.rb +++ b/core/tracepoint/disable_spec.rb @@ -2,19 +2,34 @@ ruby_version_is '2.0' do describe 'TracePoint#disable' do - context 'deactivates the trace' do - it 'returns true if trace was enabled' do - trace = TracePoint.new(:call) {} - trace.enable - trace.disable.should be_true + def test; end + it 'returns true if trace was enabled' do + event_name, method_name = nil + trace = TracePoint.new(:call) do |tp| + event_name = tp.event + method_name = tp.method_id end - it 'returns false if trace was disabled' do - trace = TracePoint.new(:call) {} - trace.enable - trace.disable - trace.disable.should be_false + trace.enable + trace.disable.should be_true + event_name, method_name = nil + test + method_name.equal?(:test).should be_false + event_name.should equal(nil) + end + + it 'returns false if trace was disabled' do + event_name, method_name = nil + trace = TracePoint.new(:call) do |tp| + event_name = tp.event + method_name = tp.method_id end + + trace.disable.should be_false + event_name, method_name = nil + test + method_name.equal?(:test).should be_false + event_name.should equal(nil) end end end diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 5d9905e204..41f0fcee46 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -2,19 +2,48 @@ ruby_version_is '2.0' do describe 'TracePoint#enable' do - context 'activates the trace' do - it 'returns true if trace was enabled' do - trace = TracePoint.new(:call) {} - trace.enable - trace.enable.should be_true + def test; end + + it 'returns true if trace was enabled' do + event_name, method_name = nil + trace = TracePoint.new(:call) do |tp| + event_name = tp.event + method_name = tp.method_id end - it 'returns false if trace was disabled' do - trace = TracePoint.new(:call) {} - trace.enable - trace.disable - trace.enable.should be_false + event_name.should equal(nil) + test + method_name.equal?(:test).should be_false + + trace.enable + trace.enable.should be_true + event_name.should equal(:call) + test + method_name.equal?(:test).should be_true + end + + it 'returns false if trace was disabled' do + event_name, method_name = nil + trace = TracePoint.new(:call) do |tp| + event_name = tp.event + method_name = tp.method_id end + + trace.enable.should be_false + event_name.should equal(:call) + test + method_name.equal?(:test).should be_true + + trace.disable + event_name, method_name = nil + test + method_name.equal?(:test).should be_false + event_name.should equal(nil) + + trace.enable.should be_false + event_name.should equal(:call) + test + method_name.equal?(:test).should be_true end end end From c4f97a1b4ecf9f7a5a9fd554f0e239c8d01dfc30 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:42:40 +0530 Subject: [PATCH 20/42] Add TracePoint#enabled? spec when trace is enabled Add spec to check if enabled? returns true when trace is enabled --- core/tracepoint/enabled_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/tracepoint/enabled_spec.rb b/core/tracepoint/enabled_spec.rb index 56155a4e03..173a449308 100644 --- a/core/tracepoint/enabled_spec.rb +++ b/core/tracepoint/enabled_spec.rb @@ -2,7 +2,13 @@ ruby_version_is '2.0' do describe 'TracePoint#enabled?' do - it 'returns the current status of the trace' do + it 'returns true when current status of the trace is enable' do + trace = TracePoint.new(:call) {} + trace.enable + trace.enabled?.should be_true + end + + it 'returns false when current status of the trace is disabled' do TracePoint.new(:call) {}.enabled?.should be_false end end From f662facde69d26f8cc48f698eb29efc1fb757347 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:45:03 +0530 Subject: [PATCH 21/42] Add TracePoint#event spec for multiple events Add spec to call tace block multiple times for more than one type of event. --- core/tracepoint/event_spec.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb index 0e64f17a10..04c59ca3c5 100644 --- a/core/tracepoint/event_spec.rb +++ b/core/tracepoint/event_spec.rb @@ -2,10 +2,23 @@ ruby_version_is '2.0' do describe 'TracePoint#event' do + def test; 'test' end + class A; def foo; end end + it 'returns the type of event' do event_name = nil - TracePoint.new(:line) { |tp| event_name = tp.event }.enable - event_name.should equal(:line) + TracePoint.new(:end, :call) do |tp| + event_name = tp.event + end.enable + + test + event_name.should equal(:call) + + A.new.foo + event_name.should equal(:call) + + class B; end + event_name.should equal(:end) end end end From 7c29a4c0122d62baa91085304f9e44c5e2346b33 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:46:50 +0530 Subject: [PATCH 22/42] Add TracePoint#new specs Add specs for #new when called with string argument, multiple argument and no arguments. --- core/tracepoint/new_spec.rb | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index 97c1798e86..425cbe940c 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -2,8 +2,48 @@ ruby_version_is '2.0' do describe 'TracePoint.new' do + def test; 'test' end + class A; def foo; end end it 'returns a new TracePoint object, not enabled by default' do TracePoint.new(:call) {}.enabled?.should be_false end + + it 'includes :line event when event is not specified' do + event_name = nil + TracePoint.new() { |tp| event_name = tp.event }.enable + event_name.should equal(:line) + + event_name = nil + test + event_name.should equal(:line) + + event_name = nil + A.new.foo + event_name.should equal(:line) + end + + it 'includes the matching event name if argument is string' do + event_name = nil + TracePoint.new('return') { |tp| event_name = tp.event}.enable + event_name.should equal(nil) + test + event_name.should equal(:return) + end + + it 'includes multiple events when multiple event names are passed as params' do + event_name = nil + TracePoint.new(:end, :call) do |tp| + event_name = tp.event + end.enable + + test + event_name.should equal(:call) + + A.new.foo + event_name.should equal(:call) + + class B; end + event_name.should equal(:end) + end end end From 2b6b2b553108bf696367f7afd7914e7559fd1985 Mon Sep 17 00:00:00 2001 From: atul Date: Mon, 16 Oct 2017 16:52:06 +0530 Subject: [PATCH 23/42] Update TracePoint#raised_exception & #return_value Update spec to check the raised_exception with the error_result --- core/tracepoint/raised_exception_spec.rb | 10 ++++++---- core/tracepoint/return_value_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/tracepoint/raised_exception_spec.rb b/core/tracepoint/raised_exception_spec.rb index 8e104a300a..cd53a8fd09 100644 --- a/core/tracepoint/raised_exception_spec.rb +++ b/core/tracepoint/raised_exception_spec.rb @@ -3,13 +3,15 @@ ruby_version_is '2.0' do describe 'TracePoint#raised_exception' do it 'returns value from exception raised on the :raise event' do - value = nil - trace = TracePoint.new(:raise) { |tp| value = tp.raised_exception } + raised_exception, error_result = nil + trace = TracePoint.new(:raise) { |tp| raised_exception = tp.raised_exception } trace.enable begin raise StandardError - rescue => _ ; end - value.should be_kind_of(StandardError) + rescue => e + error_result = e + end + raised_exception.should equal(error_result) end end end diff --git a/core/tracepoint/return_value_spec.rb b/core/tracepoint/return_value_spec.rb index 27f84f95e7..faeee06f9b 100644 --- a/core/tracepoint/return_value_spec.rb +++ b/core/tracepoint/return_value_spec.rb @@ -2,13 +2,13 @@ ruby_version_is '2.0' do describe 'TracePoint#return_value' do - def test; end + def test; 'test' end it 'returns value from :return event' do trace_value = nil TracePoint.new(:return) { |tp| trace_value = tp.return_value}.enable test - trace_value.should equal(nil) + trace_value.should == 'test' end end end From fbca3e30f52ec7daf88209bdf3d1b226ee092a23 Mon Sep 17 00:00:00 2001 From: atul Date: Tue, 17 Oct 2017 10:53:36 +0530 Subject: [PATCH 24/42] Define class A in a module ClassSpecs to fix test --- core/tracepoint/event_spec.rb | 13 +++++++++---- core/tracepoint/new_spec.rb | 14 ++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb index 04c59ca3c5..67dddc78f4 100644 --- a/core/tracepoint/event_spec.rb +++ b/core/tracepoint/event_spec.rb @@ -1,10 +1,15 @@ require File.expand_path('../../../spec_helper', __FILE__) +module ClassSpecs + class A + def foo; end + end +end + +def test; 'test' end + ruby_version_is '2.0' do describe 'TracePoint#event' do - def test; 'test' end - class A; def foo; end end - it 'returns the type of event' do event_name = nil TracePoint.new(:end, :call) do |tp| @@ -14,7 +19,7 @@ class A; def foo; end end test event_name.should equal(:call) - A.new.foo + ClassSpecs::A.new.foo event_name.should equal(:call) class B; end diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index 425cbe940c..e63444d4c6 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -1,9 +1,15 @@ require File.expand_path('../../../spec_helper', __FILE__) +module ClassSpecs + class A + def foo; end + end +end + +def test; 'test' end + ruby_version_is '2.0' do describe 'TracePoint.new' do - def test; 'test' end - class A; def foo; end end it 'returns a new TracePoint object, not enabled by default' do TracePoint.new(:call) {}.enabled?.should be_false end @@ -18,7 +24,7 @@ class A; def foo; end end event_name.should equal(:line) event_name = nil - A.new.foo + ClassSpecs::A.new.foo event_name.should equal(:line) end @@ -39,7 +45,7 @@ class A; def foo; end end test event_name.should equal(:call) - A.new.foo + ClassSpecs::A.new.foo event_name.should equal(:call) class B; end From 1db9f740a00b80b1fce3c6dd8f5375c1a7bc2927 Mon Sep 17 00:00:00 2001 From: atul Date: Tue, 17 Oct 2017 21:41:40 +0530 Subject: [PATCH 25/42] Update #defined_class & #event spec to use TracePointSpec module --- core/tracepoint/defined_class_spec.rb | 42 +++++++-------------------- core/tracepoint/event_spec.rb | 11 ++----- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/core/tracepoint/defined_class_spec.rb b/core/tracepoint/defined_class_spec.rb index 584945f886..4db98dfabc 100644 --- a/core/tracepoint/defined_class_spec.rb +++ b/core/tracepoint/defined_class_spec.rb @@ -1,48 +1,28 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) ruby_version_is '2.0' do describe 'TracePoint#defined_class' do - module A; def bar; end; end - - class B - include A - def foo; end; - end - - class C < B - def initialize - super - end - - def foo - super - end - - def bar - super - end - end - it 'returns class or module of the method being called' do - class_name = nil + last_class_name = nil TracePoint.new(:call) do |tp| - class_name = tp.defined_class + last_class_name = tp.defined_class end.enable - B.new.foo - class_name.should equal(B) + TracePointSpec::B.new.foo + last_class_name.should equal(TracePointSpec::B) - B.new.bar - class_name.should equal(A) + TracePointSpec::B.new.bar + last_class_name.should equal(TracePointSpec::A) - c = C.new - class_name.should equal(C) + c = TracePointSpec::C.new + last_class_name.should equal(TracePointSpec::C) c.foo - class_name.should equal(B) + last_class_name.should equal(TracePointSpec::B) c.bar - class_name.should equal(A) + last_class_name.should equal(TracePointSpec::A) end end end diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb index 67dddc78f4..c8e08628ec 100644 --- a/core/tracepoint/event_spec.rb +++ b/core/tracepoint/event_spec.rb @@ -1,12 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) - -module ClassSpecs - class A - def foo; end - end -end - -def test; 'test' end +require File.expand_path('../fixtures/classes', __FILE__) ruby_version_is '2.0' do describe 'TracePoint#event' do @@ -19,7 +12,7 @@ def test; 'test' end test event_name.should equal(:call) - ClassSpecs::A.new.foo + TracePointSpec::B.new.foo event_name.should equal(:call) class B; end From e779c2eb19299c30b0c7e9ee59283e0c4b24c680 Mon Sep 17 00:00:00 2001 From: atul Date: Tue, 17 Oct 2017 21:42:44 +0530 Subject: [PATCH 26/42] Add specs to TracePoint#new & #path --- core/tracepoint/new_spec.rb | 46 ++++++++++++++++++++++++++---------- core/tracepoint/path_spec.rb | 7 ++++++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index e63444d4c6..85687c0ee6 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -1,12 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) - -module ClassSpecs - class A - def foo; end - end -end - -def test; 'test' end +require File.expand_path('../fixtures/classes', __FILE__) ruby_version_is '2.0' do describe 'TracePoint.new' do @@ -24,13 +17,16 @@ def test; 'test' end event_name.should equal(:line) event_name = nil - ClassSpecs::A.new.foo + TracePointSpec::B.new.foo event_name.should equal(:line) end - it 'includes the matching event name if argument is string' do + it 'converts given event name as string into symbol using to_sym' do event_name = nil - TracePoint.new('return') { |tp| event_name = tp.event}.enable + (o = mock('return')).should_receive(:to_sym).and_return(:return) + + TracePoint.new(o) { |tp| event_name = tp.event}.enable + event_name.should equal(nil) test event_name.should equal(:return) @@ -45,11 +41,37 @@ def test; 'test' end test event_name.should equal(:call) - ClassSpecs::A.new.foo + TracePointSpec::B.new.foo event_name.should equal(:call) class B; end event_name.should equal(: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) + + o.should_receive(:to_sym).and_return(123) + -> { TracePoint.new(o) {}}.should raise_error(TypeError) + end + + it 'expects to be called with a block' do + begin + TracePoint.new(:line) + rescue => e + e.class.should equal(ThreadError) + e.message.should == 'must be called with a block' + end + end + + it "raises a Argument error when the give argument doesn't match an event name" do + begin + TracePoint.new(:test) + rescue => e + e.class.should equal(ArgumentError) + e.message.should == 'unknown event: test' + end + end end end diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb index c2f400c745..e8db77ab8d 100644 --- a/core/tracepoint/path_spec.rb +++ b/core/tracepoint/path_spec.rb @@ -7,5 +7,12 @@ TracePoint.new(:line) { |tp| path = tp.path }.enable path.should == "#{__FILE__}" end + + it 'equals (eval) inside an eval' do + path = nil + TracePoint.new(:end) { |tp| path = tp.path }.enable + eval("class A; end") + path.should == '(eval)' + end end end From 2ed6b176abb47d612e82fc899b4358582e796d11 Mon Sep 17 00:00:00 2001 From: atul Date: Tue, 17 Oct 2017 21:43:30 +0530 Subject: [PATCH 27/42] Define module & classes in TracePointSpec module --- core/tracepoint/fixtures/classes.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/tracepoint/fixtures/classes.rb b/core/tracepoint/fixtures/classes.rb index fd22ac319d..72f25ee1b6 100644 --- a/core/tracepoint/fixtures/classes.rb +++ b/core/tracepoint/fixtures/classes.rb @@ -4,5 +4,31 @@ def m end alias_method :m_alias, :m end + + module A + def bar; end + end + + class B + include A + + def foo; end; + end + + class C < B + def initialize + end + + def foo + super + end + + def bar + super + end + end end +def test + 'test' +end From 181972a76bd9080640bfc5f4ed39bb24bb24efe9 Mon Sep 17 00:00:00 2001 From: atul Date: Sun, 22 Oct 2017 06:39:28 +0530 Subject: [PATCH 28/42] TracePoint - disable trace at end of each spec/ enclose spec within {} --- core/tracepoint/defined_class_spec.rb | 24 ++++++------- core/tracepoint/enable_spec.rb | 1 + core/tracepoint/enabled_spec.rb | 5 +-- core/tracepoint/event_spec.rb | 15 +++++---- core/tracepoint/lineno_spec.rb | 5 +-- core/tracepoint/method_id_spec.rb | 7 ++-- core/tracepoint/new_spec.rb | 43 ++++++++++++------------ core/tracepoint/path_spec.rb | 12 ++++--- core/tracepoint/raised_exception_spec.rb | 13 +++---- core/tracepoint/return_value_spec.rb | 7 ++-- core/tracepoint/self_spec.rb | 5 +-- core/tracepoint/trace_spec.rb | 4 ++- 12 files changed, 77 insertions(+), 64 deletions(-) diff --git a/core/tracepoint/defined_class_spec.rb b/core/tracepoint/defined_class_spec.rb index 4db98dfabc..84005bbcc7 100644 --- a/core/tracepoint/defined_class_spec.rb +++ b/core/tracepoint/defined_class_spec.rb @@ -7,22 +7,22 @@ last_class_name = nil TracePoint.new(:call) do |tp| last_class_name = tp.defined_class - end.enable + end.enable do + TracePointSpec::B.new.foo + last_class_name.should equal(TracePointSpec::B) - TracePointSpec::B.new.foo - last_class_name.should equal(TracePointSpec::B) + TracePointSpec::B.new.bar + last_class_name.should equal(TracePointSpec::A) - TracePointSpec::B.new.bar - last_class_name.should equal(TracePointSpec::A) + c = TracePointSpec::C.new + last_class_name.should equal(TracePointSpec::C) - c = TracePointSpec::C.new - last_class_name.should equal(TracePointSpec::C) + c.foo + last_class_name.should equal(TracePointSpec::B) - c.foo - last_class_name.should equal(TracePointSpec::B) - - c.bar - last_class_name.should equal(TracePointSpec::A) + c.bar + last_class_name.should equal(TracePointSpec::A) + end end end end diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 41f0fcee46..4a0bf40eb6 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -44,6 +44,7 @@ def test; end event_name.should equal(:call) test method_name.equal?(:test).should be_true + trace.disable end end end diff --git a/core/tracepoint/enabled_spec.rb b/core/tracepoint/enabled_spec.rb index 173a449308..bed2d1ba0c 100644 --- a/core/tracepoint/enabled_spec.rb +++ b/core/tracepoint/enabled_spec.rb @@ -4,8 +4,9 @@ describe 'TracePoint#enabled?' do it 'returns true when current status of the trace is enable' do trace = TracePoint.new(:call) {} - trace.enable - trace.enabled?.should be_true + trace.enable do + trace.enabled?.should be_true + end end it 'returns false when current status of the trace is disabled' do diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb index c8e08628ec..753162775d 100644 --- a/core/tracepoint/event_spec.rb +++ b/core/tracepoint/event_spec.rb @@ -7,16 +7,17 @@ event_name = nil TracePoint.new(:end, :call) do |tp| event_name = tp.event - end.enable + end.enable do + test + event_name.should equal(:call) - test - event_name.should equal(:call) + TracePointSpec::B.new.foo + event_name.should equal(:call) - TracePointSpec::B.new.foo - event_name.should equal(:call) + class B; end + event_name.should equal(:end) + end - class B; end - event_name.should equal(:end) end end end diff --git a/core/tracepoint/lineno_spec.rb b/core/tracepoint/lineno_spec.rb index c525f22d94..574765ee5d 100644 --- a/core/tracepoint/lineno_spec.rb +++ b/core/tracepoint/lineno_spec.rb @@ -4,8 +4,9 @@ describe 'TracePoint#lineno' do it 'returns the line number of the event' do lineno = nil - TracePoint.new(:line) { |tp| lineno = tp.lineno }.enable - lineno.should equal(8) + TracePoint.new(:line) { |tp| lineno = tp.lineno }.enable do + lineno.should equal(8) + end end end end diff --git a/core/tracepoint/method_id_spec.rb b/core/tracepoint/method_id_spec.rb index 795f35a45c..62cf2f4044 100644 --- a/core/tracepoint/method_id_spec.rb +++ b/core/tracepoint/method_id_spec.rb @@ -6,9 +6,10 @@ def test; end it 'returns the name at the definition of the method being called' do method_name = nil - TracePoint.new(:call) { |tp| method_name = tp.method_id}.enable - test - method_name.should equal(:test) + TracePoint.new(:call) { |tp| method_name = tp.method_id}.enable do + test + method_name.should equal(:test) + end end end end diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index 85687c0ee6..5044b2a978 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -9,43 +9,44 @@ it 'includes :line event when event is not specified' do event_name = nil - TracePoint.new() { |tp| event_name = tp.event }.enable - event_name.should equal(:line) + TracePoint.new() { |tp| event_name = tp.event }.enable do + event_name.should equal(:line) - event_name = nil - test - event_name.should equal(:line) + event_name = nil + test + event_name.should equal(:line) - event_name = nil - TracePointSpec::B.new.foo - event_name.should equal(:line) + event_name = nil + TracePointSpec::B.new.foo + event_name.should equal(:line) + end end it 'converts given event name as string into symbol using to_sym' do event_name = nil (o = mock('return')).should_receive(:to_sym).and_return(:return) - TracePoint.new(o) { |tp| event_name = tp.event}.enable - - event_name.should equal(nil) - test - event_name.should equal(:return) + TracePoint.new(o) { |tp| event_name = tp.event}.enable do + event_name.should equal(nil) + test + event_name.should equal(:return) + end end it 'includes multiple events when multiple event names are passed as params' do event_name = nil TracePoint.new(:end, :call) do |tp| event_name = tp.event - end.enable - - test - event_name.should equal(:call) + end.enable do + test + event_name.should equal(:call) - TracePointSpec::B.new.foo - event_name.should equal(:call) + TracePointSpec::B.new.foo + event_name.should equal(:call) - class B; end - event_name.should equal(:end) + class B; end + event_name.should equal(:end) + end end it 'raises a TypeError when the given object is not a string/symbol' do diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb index e8db77ab8d..4764869924 100644 --- a/core/tracepoint/path_spec.rb +++ b/core/tracepoint/path_spec.rb @@ -4,15 +4,17 @@ describe 'TracePoint#path' do it 'returns the path of the file being run' do path = nil - TracePoint.new(:line) { |tp| path = tp.path }.enable - path.should == "#{__FILE__}" + TracePoint.new(:line) { |tp| path = tp.path }.enable do + path.should == "#{__FILE__}" + end end it 'equals (eval) inside an eval' do path = nil - TracePoint.new(:end) { |tp| path = tp.path }.enable - eval("class A; end") - path.should == '(eval)' + TracePoint.new(:end) { |tp| path = tp.path }.enable do + eval("class A; end") + path.should == '(eval)' + end end end end diff --git a/core/tracepoint/raised_exception_spec.rb b/core/tracepoint/raised_exception_spec.rb index cd53a8fd09..2b07878cd7 100644 --- a/core/tracepoint/raised_exception_spec.rb +++ b/core/tracepoint/raised_exception_spec.rb @@ -5,13 +5,14 @@ it 'returns value from exception raised on the :raise event' do raised_exception, error_result = nil trace = TracePoint.new(:raise) { |tp| raised_exception = tp.raised_exception } - trace.enable - begin - raise StandardError - rescue => e - error_result = e + trace.enable do + begin + raise StandardError + rescue => e + error_result = e + end + raised_exception.should equal(error_result) end - raised_exception.should equal(error_result) end end end diff --git a/core/tracepoint/return_value_spec.rb b/core/tracepoint/return_value_spec.rb index faeee06f9b..cffb021d20 100644 --- a/core/tracepoint/return_value_spec.rb +++ b/core/tracepoint/return_value_spec.rb @@ -6,9 +6,10 @@ def test; 'test' end it 'returns value from :return event' do trace_value = nil - TracePoint.new(:return) { |tp| trace_value = tp.return_value}.enable - test - trace_value.should == 'test' + TracePoint.new(:return) { |tp| trace_value = tp.return_value}.enable do + test + trace_value.should == 'test' + end end end end diff --git a/core/tracepoint/self_spec.rb b/core/tracepoint/self_spec.rb index 8ad38746ed..638f9711f7 100644 --- a/core/tracepoint/self_spec.rb +++ b/core/tracepoint/self_spec.rb @@ -4,8 +4,9 @@ describe 'TracePoint#self' do it 'return the trace object from event' do trace = nil - TracePoint.new(:line) { |tp| trace = tp.self }.enable - trace.equal?(self).should be_true + TracePoint.new(:line) { |tp| trace = tp.self }.enable do + trace.equal?(self).should be_true + end end end end diff --git a/core/tracepoint/trace_spec.rb b/core/tracepoint/trace_spec.rb index f120961cea..2bb0e0897a 100644 --- a/core/tracepoint/trace_spec.rb +++ b/core/tracepoint/trace_spec.rb @@ -3,7 +3,9 @@ ruby_version_is '2.0' do describe 'TracePoint.trace' do it 'activates the trace automatically' do - TracePoint.trace(:call) {}.enabled?.should be_true + trace = TracePoint.trace(:call) {} + trace.enabled?.should be_true + trace.disable end end end From 2d55b374000e0ba9d35d4bbe3b6dff6086eb9618 Mon Sep 17 00:00:00 2001 From: atul Date: Tue, 24 Oct 2017 21:49:41 +0530 Subject: [PATCH 29/42] TracePoint#enable add specs for enable {'with block'} --- core/tracepoint/enable_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 4a0bf40eb6..0df03fddea 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -5,7 +5,7 @@ def test; end it 'returns true if trace was enabled' do - event_name, method_name = nil + event_name, method_name = nil, nil trace = TracePoint.new(:call) do |tp| event_name = tp.event method_name = tp.method_id @@ -20,10 +20,11 @@ def test; end event_name.should equal(:call) test method_name.equal?(:test).should be_true + trace.disable end it 'returns false if trace was disabled' do - event_name, method_name = nil + event_name, method_name = nil, nil trace = TracePoint.new(:call) do |tp| event_name = tp.event method_name = tp.method_id @@ -46,5 +47,19 @@ def test; end method_name.equal?(:test).should be_true trace.disable end + + it 'is enabled within a block' do + event_name = nil + TracePoint.new(:line) do |tp| + event_name = tp.event + end.enable { event_name.should equal(:line) } + end + + it 'can accept param but they are initialized as nil within a block' do + event_name = nil + TracePoint.new(:line) do |tp| + event_name = tp.event + end.enable { |f| f.should equal(nil) } + end end end From 62a7e82009b8d5e3642bae7468f48b4f7de3c383 Mon Sep 17 00:00:00 2001 From: atul Date: Thu, 26 Oct 2017 00:47:00 +0530 Subject: [PATCH 30/42] TracePoint#enable add spec to check if args are nil within enable block --- core/tracepoint/enable_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 0df03fddea..151501ab50 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -55,11 +55,14 @@ def test; end end.enable { event_name.should equal(:line) } end - it 'can accept param but they are initialized as nil within a block' do + it 'can accept param within a block but its initialized as nil' do event_name = nil TracePoint.new(:line) do |tp| event_name = tp.event - end.enable { |f| f.should equal(nil) } + end.enable do |*args| + event_name.should equal(:line) + args.should == [nil] + end end end end From d07cc9a6681e62bf0efabeeffb5d23e541ba225f Mon Sep 17 00:00:00 2001 From: atul Date: Thu, 26 Oct 2017 00:48:35 +0530 Subject: [PATCH 31/42] TracePoint#path spec to check for path inside eval Add specs to check for path inside eval for :call, :end, :line & :return event. --- core/tracepoint/path_spec.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb index 4764869924..6180664fbc 100644 --- a/core/tracepoint/path_spec.rb +++ b/core/tracepoint/path_spec.rb @@ -1,5 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) +def test; 'test' end + ruby_version_is '2.0' do describe 'TracePoint#path' do it 'returns the path of the file being run' do @@ -9,12 +11,36 @@ end end - it 'equals (eval) inside an eval' do + it 'equals (eval) inside an eval for :end event' do path = nil TracePoint.new(:end) { |tp| path = tp.path }.enable do eval("class A; end") path.should == '(eval)' end end + + it 'equals the path of the file being run for :line event inside an eval' do + path = nil + TracePoint.new(:line) { |tp| path = tp.path }.enable do + eval("2 + 2") + path.should == "#{__FILE__}" + end + end + + it 'equals the path of the file being run for :call event inside an eval' do + path = nil + TracePoint.new(:call) { |tp| path = tp.path }.enable do + eval("test") + path.should == "#{__FILE__}" + end + end + + it 'equals the path of the file being run for :return event inside an eval' do + path = nil + TracePoint.new(:return) { |tp| path = tp.path }.enable do + eval("test") + path.should == "#{__FILE__}" + end + end end end From 23508090f9644f907211578c8488803214a24921 Mon Sep 17 00:00:00 2001 From: atul Date: Thu, 26 Oct 2017 01:57:17 +0530 Subject: [PATCH 32/42] TracePoint#enable add specs for enable {with_block} --- core/tracepoint/enable_spec.rb | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 151501ab50..bde029251a 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -57,12 +57,31 @@ def test; end it 'can accept param within a block but its initialized as nil' do event_name = nil - TracePoint.new(:line) do |tp| - event_name = tp.event - end.enable do |*args| + trace = TracePoint.new(:line) { |tp| event_name = tp.event } + trace.enable do |*args| event_name.should equal(:line) args.should == [nil] end + trace.enabled?.should be_false + end + + it 'is enabled on calling with a block if it was already enabled' do + event_name = nil + trace = TracePoint.new(:line) { |tp|event_name = tp.event } + trace.enable + trace.enabled?.should be_true + trace.enable { event_name.should equal(:line) } + trace.enabled?.should be_true + trace.disable + end + + it 'is disabled after the block & expects the result of enable {} to equal + nil' do + event_name = nil + trace = TracePoint.new(:line) { |tp|event_name = tp.event } + trace.enable { event_name.should equal(:line) } == nil + trace.enabled?.should be_false + trace.disable end end end From e274e66c39b3689efcf4c678e222d7516048477f Mon Sep 17 00:00:00 2001 From: atul Date: Sat, 28 Oct 2017 00:29:54 +0530 Subject: [PATCH 33/42] TracePoint#path Remove global test definition & other events specs --- core/tracepoint/path_spec.rb | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb index 6180664fbc..39d1a0063b 100644 --- a/core/tracepoint/path_spec.rb +++ b/core/tracepoint/path_spec.rb @@ -1,7 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) -def test; 'test' end - ruby_version_is '2.0' do describe 'TracePoint#path' do it 'returns the path of the file being run' do @@ -18,29 +16,5 @@ def test; 'test' end path.should == '(eval)' end end - - it 'equals the path of the file being run for :line event inside an eval' do - path = nil - TracePoint.new(:line) { |tp| path = tp.path }.enable do - eval("2 + 2") - path.should == "#{__FILE__}" - end - end - - it 'equals the path of the file being run for :call event inside an eval' do - path = nil - TracePoint.new(:call) { |tp| path = tp.path }.enable do - eval("test") - path.should == "#{__FILE__}" - end - end - - it 'equals the path of the file being run for :return event inside an eval' do - path = nil - TracePoint.new(:return) { |tp| path = tp.path }.enable do - eval("test") - path.should == "#{__FILE__}" - end - end end end From a191029e7fda967f2b3bd6122497d97e4240bea9 Mon Sep 17 00:00:00 2001 From: atul Date: Sat, 28 Oct 2017 00:56:59 +0530 Subject: [PATCH 34/42] TracePoint#disable add specs for disable{} & spec for ruby bug #14057 --- core/tracepoint/disable_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/tracepoint/disable_spec.rb b/core/tracepoint/disable_spec.rb index 3c13075f24..5ccc782111 100644 --- a/core/tracepoint/disable_spec.rb +++ b/core/tracepoint/disable_spec.rb @@ -31,5 +31,27 @@ def test; end method_name.equal?(:test).should be_false event_name.should equal(nil) end + + it 'is disabled within a block' do + event_name = nil + trace = TracePoint.new(:line) {} + trace.enable + trace.disable { puts 2 + 2 }.should == nil + trace.enabled?.should equal(true) + trace.disable + end + + ruby_bug "#14057", "2.0"..."2.5" do + it 'can accept param within a block but it should not yield arguments' do + event_name = nil + trace = TracePoint.new(:line) {} + trace.enable + trace.disable do |*args| + args.should == [] + end + trace.enabled?.should be_true + trace.disable + end + end end end From 5c4001c7ce6a59b8c52ca16ef70026f9d5fb3c24 Mon Sep 17 00:00:00 2001 From: atul Date: Sat, 28 Oct 2017 00:58:05 +0530 Subject: [PATCH 35/42] TracePoint#enable update to check for enable{} result & spec for ruby bug #14057 --- core/tracepoint/enable_spec.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index bde029251a..702abae6c0 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -55,14 +55,16 @@ def test; end end.enable { event_name.should equal(:line) } end - it 'can accept param within a block but its initialized as nil' do - event_name = nil - trace = TracePoint.new(:line) { |tp| event_name = tp.event } - trace.enable do |*args| - event_name.should equal(:line) - args.should == [nil] + ruby_bug "#14057", "2.0"..."2.5" do + it 'can accept param within a block but it should not yield arguments' do + event_name = nil + trace = TracePoint.new(:line) { |tp| event_name = tp.event } + trace.enable do |*args| + event_name.should equal(:line) + args.should == [] + end + trace.enabled?.should be_false end - trace.enabled?.should be_false end it 'is enabled on calling with a block if it was already enabled' do @@ -70,7 +72,7 @@ def test; end trace = TracePoint.new(:line) { |tp|event_name = tp.event } trace.enable trace.enabled?.should be_true - trace.enable { event_name.should equal(:line) } + trace.enable { puts 2 + 2 }.should == nil trace.enabled?.should be_true trace.disable end @@ -79,7 +81,7 @@ def test; end nil' do event_name = nil trace = TracePoint.new(:line) { |tp|event_name = tp.event } - trace.enable { event_name.should equal(:line) } == nil + trace.enable { event_name.should equal(:line) }.should == nil trace.enabled?.should be_false trace.disable end From af2c4217da2c7493f59a28dd79022662d685fbcd Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 28 Oct 2017 12:06:44 +0200 Subject: [PATCH 36/42] Improve TracePoint#binding specs based on review --- core/tracepoint/binding_spec.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/tracepoint/binding_spec.rb b/core/tracepoint/binding_spec.rb index 939b009b10..afdcd75671 100644 --- a/core/tracepoint/binding_spec.rb +++ b/core/tracepoint/binding_spec.rb @@ -2,10 +2,20 @@ ruby_version_is '2.0' do describe 'TracePoint#binding' do + def test + secret = 42 + end + it 'return the generated binding object from event' do - binding = nil - TracePoint.new(:line) { |tp| binding = tp.binding }.enable - binding.should be_kind_of(Binding) + bindings = [] + TracePoint.new(:return) { |tp| + bindings << tp.binding + }.enable { + test + } + bindings.size.should == 1 + bindings[0].should be_kind_of(Binding) + bindings[0].local_variables.should == [:secret] end end end From d748f08e171e094553afb561eb5c34a81d9781a6 Mon Sep 17 00:00:00 2001 From: atul Date: Sat, 28 Oct 2017 21:00:47 +0530 Subject: [PATCH 37/42] TracePoint#disable update block spec & add spec to check block result --- core/tracepoint/disable_spec.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/tracepoint/disable_spec.rb b/core/tracepoint/disable_spec.rb index 5ccc782111..60d5a659e0 100644 --- a/core/tracepoint/disable_spec.rb +++ b/core/tracepoint/disable_spec.rb @@ -32,11 +32,20 @@ def test; end event_name.should equal(nil) end - it 'is disabled within a block' do - event_name = nil + it 'is disabled within a block & is enabled outside the block' do + enabled = nil trace = TracePoint.new(:line) {} trace.enable - trace.disable { puts 2 + 2 }.should == nil + trace.disable { enabled = trace.enabled? } + enabled.should be_false + trace.enabled?.should be_true + trace.disable + end + + it 'is disabled within a block & also returns false when its called with a block' do + trace = TracePoint.new(:line) {} + trace.enable + trace.disable { trace.enabled? }.should == false trace.enabled?.should equal(true) trace.disable end From 0a9c1e4252aefa35e0cb39c5cd1faab9d1f4bc1f Mon Sep 17 00:00:00 2001 From: atul Date: Sat, 28 Oct 2017 21:01:29 +0530 Subject: [PATCH 38/42] TracePoint#enable update block spec & add spec to check block result --- core/tracepoint/enable_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 702abae6c0..10bacf54bd 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -68,15 +68,21 @@ def test; end end it 'is enabled on calling with a block if it was already enabled' do - event_name = nil - trace = TracePoint.new(:line) { |tp|event_name = tp.event } + enabled = nil + trace = TracePoint.new(:line) {} trace.enable trace.enabled?.should be_true - trace.enable { puts 2 + 2 }.should == nil - trace.enabled?.should be_true + trace.enable { enabled = trace.enabled? } + enabled.should be_true trace.disable end + it 'is enabled within a block & also returns true when its called with a block' do + trace = TracePoint.new(:line) {} + trace.enable { trace.enabled? }.should == true + trace.enabled?.should be_false + end + it 'is disabled after the block & expects the result of enable {} to equal nil' do event_name = nil From 3b50ef479614707f38d9728ba58ad4d027c392f0 Mon Sep 17 00:00:00 2001 From: atul Date: Wed, 1 Nov 2017 19:35:48 +0530 Subject: [PATCH 39/42] Update TracePoint#new spec to use raise_error matcher --- core/tracepoint/new_spec.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index 5044b2a978..516cb7d8e6 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -58,21 +58,11 @@ class B; end end it 'expects to be called with a block' do - begin - TracePoint.new(:line) - rescue => e - e.class.should equal(ThreadError) - e.message.should == 'must be called with a block' - end + -> { TracePoint.new(:line) }.should raise_error(ArgumentError) end it "raises a Argument error when the give argument doesn't match an event name" do - begin - TracePoint.new(:test) - rescue => e - e.class.should equal(ArgumentError) - e.message.should == 'unknown event: test' - end + -> { TracePoint.new(:test) }.should raise_error(ArgumentError) end end end From 1d2a9004390be8d431996bf631b26214638f2f1c Mon Sep 17 00:00:00 2001 From: atul Date: Wed, 1 Nov 2017 19:45:51 +0530 Subject: [PATCH 40/42] Update TracePointSpec module & Tracepoint#new spec Scope test method within TracePointSpec module. Update Tracepoint#new spec to use the test method within TracePointSpec module --- core/tracepoint/fixtures/classes.rb | 6 +++--- core/tracepoint/new_spec.rb | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/tracepoint/fixtures/classes.rb b/core/tracepoint/fixtures/classes.rb index 72f25ee1b6..49c70e1915 100644 --- a/core/tracepoint/fixtures/classes.rb +++ b/core/tracepoint/fixtures/classes.rb @@ -27,8 +27,8 @@ def bar super end end -end -def test - 'test' + def self.test + 'test' + end end diff --git a/core/tracepoint/new_spec.rb b/core/tracepoint/new_spec.rb index 516cb7d8e6..5f8dca344e 100644 --- a/core/tracepoint/new_spec.rb +++ b/core/tracepoint/new_spec.rb @@ -13,7 +13,7 @@ event_name.should equal(:line) event_name = nil - test + TracePointSpec.test event_name.should equal(:line) event_name = nil @@ -28,7 +28,7 @@ TracePoint.new(o) { |tp| event_name = tp.event}.enable do event_name.should equal(nil) - test + TracePointSpec.test event_name.should equal(:return) end end @@ -38,7 +38,7 @@ TracePoint.new(:end, :call) do |tp| event_name = tp.event end.enable do - test + TracePointSpec.test event_name.should equal(:call) TracePointSpec::B.new.foo @@ -57,8 +57,10 @@ class B; end -> { TracePoint.new(o) {}}.should raise_error(TypeError) end - it 'expects to be called with a block' do - -> { TracePoint.new(:line) }.should raise_error(ArgumentError) + ruby_bug "#140740", "2.0"..."2.5" do + it 'expects to be called with a block' do + -> { TracePoint.new(:line) }.should raise_error(ArgumentError) + end end it "raises a Argument error when the give argument doesn't match an event name" do From bbb295464ffcbecceab9f931ef89ba36bc016c39 Mon Sep 17 00:00:00 2001 From: atul Date: Wed, 1 Nov 2017 19:50:36 +0530 Subject: [PATCH 41/42] Update TracePoint#event spec to use test method from TracePointSpec module --- core/tracepoint/event_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tracepoint/event_spec.rb b/core/tracepoint/event_spec.rb index 753162775d..1e31ccb7d8 100644 --- a/core/tracepoint/event_spec.rb +++ b/core/tracepoint/event_spec.rb @@ -8,7 +8,7 @@ TracePoint.new(:end, :call) do |tp| event_name = tp.event end.enable do - test + TracePointSpec.test event_name.should equal(:call) TracePointSpec::B.new.foo From 8803665e1324a24ff78c2589db992810dda19439 Mon Sep 17 00:00:00 2001 From: atul Date: Thu, 2 Nov 2017 22:50:51 +0530 Subject: [PATCH 42/42] TracePoint#enable Rename labelling of spec --- core/tracepoint/enable_spec.rb | 141 ++++++++++++++++---------------- core/tracepoint/inspect_spec.rb | 2 +- 2 files changed, 71 insertions(+), 72 deletions(-) diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 10bacf54bd..1c510bcbb0 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -4,92 +4,91 @@ describe 'TracePoint#enable' do def test; end - it 'returns true if trace was enabled' do - event_name, method_name = nil, nil - trace = TracePoint.new(:call) do |tp| - event_name = tp.event - method_name = tp.method_id - end + describe 'without a block' do + it 'returns true if trace was enabled' do + event_name, method_name = nil, nil + method_name = [] + trace = TracePoint.new(:call) do |tp| + event_name = tp.event + method_name << tp.method_id + end - event_name.should equal(nil) - test - method_name.equal?(:test).should be_false + test + event_name.should == nil - trace.enable - trace.enable.should be_true - event_name.should equal(:call) - test - method_name.equal?(:test).should be_true - trace.disable - end - - it 'returns false if trace was disabled' do - event_name, method_name = nil, nil - trace = TracePoint.new(:call) do |tp| - event_name = tp.event - method_name = tp.method_id + trace.enable + test + event_name.should equal(:call) + trace.disable end - trace.enable.should be_false - event_name.should equal(:call) - test - method_name.equal?(:test).should be_true + it 'returns false if trace was disabled' do + event_name, method_name = nil, nil + trace = TracePoint.new(:call) do |tp| + event_name = tp.event + method_name = tp.method_id + end - trace.disable - event_name, method_name = nil - test - method_name.equal?(:test).should be_false - event_name.should equal(nil) + trace.enable.should be_false + event_name.should equal(:call) + test + method_name.equal?(:test).should be_true - trace.enable.should be_false - event_name.should equal(:call) - test - method_name.equal?(:test).should be_true - trace.disable - end + trace.disable + event_name, method_name = nil + test + method_name.equal?(:test).should be_false + event_name.should equal(nil) - it 'is enabled within a block' do - event_name = nil - TracePoint.new(:line) do |tp| - event_name = tp.event - end.enable { event_name.should equal(:line) } + trace.enable.should be_false + event_name.should equal(:call) + test + method_name.equal?(:test).should be_true + trace.disable + end end - ruby_bug "#14057", "2.0"..."2.5" do - it 'can accept param within a block but it should not yield arguments' do + describe 'with a block' do + it 'enables the trace object within a block' do event_name = nil - trace = TracePoint.new(:line) { |tp| event_name = tp.event } - trace.enable do |*args| - event_name.should equal(:line) - args.should == [] + TracePoint.new(:line) do |tp| + event_name = tp.event + end.enable { event_name.should equal(:line) } + end + + ruby_bug "#14057", "2.0"..."2.5" do + it 'can accept arguments within a block but it should not yield arguments' do + event_name = nil + trace = TracePoint.new(:line) { |tp| event_name = tp.event } + trace.enable do |*args| + event_name.should equal(:line) + args.should == [] + end + trace.enabled?.should be_false end - trace.enabled?.should be_false end - end - it 'is enabled on calling with a block if it was already enabled' do - enabled = nil - trace = TracePoint.new(:line) {} - trace.enable - trace.enabled?.should be_true - trace.enable { enabled = trace.enabled? } - enabled.should be_true - trace.disable - end + it 'enables trace object on calling with a block if it was already enabled' do + enabled = nil + trace = TracePoint.new(:line) {} + trace.enable + trace.enable { enabled = trace.enabled? } + enabled.should == true + trace.disable + end - it 'is enabled within a block & also returns true when its called with a block' do - trace = TracePoint.new(:line) {} - trace.enable { trace.enabled? }.should == true - trace.enabled?.should be_false - end + it 'returns value returned by the block' do + trace = TracePoint.new(:line) {} + trace.enable { true; 'test' }.should == 'test' + end - it 'is disabled after the block & expects the result of enable {} to equal - nil' do - event_name = nil - trace = TracePoint.new(:line) { |tp|event_name = tp.event } - trace.enable { event_name.should equal(:line) }.should == nil - trace.enabled?.should be_false - trace.disable + it 'disables the trace object outside the block' do + event_name = nil + trace = TracePoint.new(:line) { |tp|event_name = tp.event } + trace.enable { '2 + 2' } + event_name.should equal(:line) + trace.enabled?.should be_false + end end end end diff --git a/core/tracepoint/inspect_spec.rb b/core/tracepoint/inspect_spec.rb index ed14f24eda..97d77eedd8 100644 --- a/core/tracepoint/inspect_spec.rb +++ b/core/tracepoint/inspect_spec.rb @@ -2,7 +2,7 @@ ruby_version_is '2.0' do describe 'TracePoint#inspect' do - it 'return a string containing a human-readable TracePoint status' do + it 'returns a string containing a human-readable TracePoint status' do TracePoint.new(:call) {}.inspect.should == '#' end