2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-12-01 15:41:50 +00:00
|
|
|
|
|
|
|
describe 'TracePoint#disable' do
|
|
|
|
it 'returns true if trace was enabled' do
|
2017-12-01 17:51:16 +00:00
|
|
|
called = false
|
2019-02-21 15:38:59 +00:00
|
|
|
trace = TracePoint.new(:line) do |tp|
|
2017-12-01 17:51:16 +00:00
|
|
|
called = true
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trace.enable
|
2019-02-21 15:38:59 +00:00
|
|
|
begin
|
|
|
|
line_event = true
|
|
|
|
ensure
|
|
|
|
ret = trace.disable
|
|
|
|
ret.should == true
|
|
|
|
end
|
|
|
|
called.should == true
|
2017-12-01 17:51:16 +00:00
|
|
|
|
|
|
|
# Check the TracePoint is disabled
|
|
|
|
called = false
|
2019-02-21 15:38:59 +00:00
|
|
|
line_event = true
|
2017-12-01 17:51:16 +00:00
|
|
|
called.should == false
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if trace was disabled' do
|
2019-02-21 15:38:59 +00:00
|
|
|
called = false
|
|
|
|
trace = TracePoint.new(:line) do |tp|
|
|
|
|
called = true
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
|
2019-02-21 15:38:59 +00:00
|
|
|
line_event = true
|
|
|
|
trace.disable.should == false
|
|
|
|
line_event = true
|
|
|
|
called.should == false
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is disabled within a block & is enabled outside the block' do
|
|
|
|
enabled = nil
|
|
|
|
trace = TracePoint.new(:line) {}
|
|
|
|
trace.enable
|
2017-12-01 17:51:16 +00:00
|
|
|
begin
|
|
|
|
trace.disable { enabled = trace.enabled? }
|
2019-02-21 15:38:59 +00:00
|
|
|
enabled.should == false
|
|
|
|
trace.enabled?.should == true
|
2017-12-01 17:51:16 +00:00
|
|
|
ensure
|
|
|
|
trace.disable
|
|
|
|
end
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
|
2019-02-21 15:38:59 +00:00
|
|
|
it 'returns the return value of the block' do
|
2017-12-01 15:41:50 +00:00
|
|
|
trace = TracePoint.new(:line) {}
|
|
|
|
trace.enable
|
2017-12-01 17:51:16 +00:00
|
|
|
begin
|
2019-02-21 15:38:59 +00:00
|
|
|
trace.disable { 42 }.should == 42
|
|
|
|
trace.enabled?.should == true
|
2017-12-01 17:51:16 +00:00
|
|
|
ensure
|
|
|
|
trace.disable
|
|
|
|
end
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
|
2018-04-28 19:50:06 +00:00
|
|
|
ruby_bug "#14057", ""..."2.5" do
|
2017-12-01 15:41:50 +00:00
|
|
|
it 'can accept param within a block but it should not yield arguments' do
|
|
|
|
trace = TracePoint.new(:line) {}
|
|
|
|
trace.enable
|
2017-12-01 17:51:16 +00:00
|
|
|
begin
|
|
|
|
trace.disable do |*args|
|
|
|
|
args.should == []
|
|
|
|
end
|
2019-02-21 15:38:59 +00:00
|
|
|
trace.enabled?.should == true
|
2017-12-01 17:51:16 +00:00
|
|
|
ensure
|
|
|
|
trace.disable
|
2017-12-01 15:41:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|