2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-12-01 10:41:50 -05:00
|
|
|
|
|
|
|
describe 'TracePoint#disable' do
|
|
|
|
it 'returns true if trace was enabled' do
|
2017-12-01 12:51:16 -05:00
|
|
|
called = false
|
2019-02-21 10:38:59 -05:00
|
|
|
trace = TracePoint.new(:line) do |tp|
|
2017-12-01 12:51:16 -05:00
|
|
|
called = true
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
trace.enable
|
2019-02-21 10:38:59 -05:00
|
|
|
begin
|
|
|
|
line_event = true
|
|
|
|
ensure
|
|
|
|
ret = trace.disable
|
|
|
|
ret.should == true
|
|
|
|
end
|
|
|
|
called.should == true
|
2017-12-01 12:51:16 -05:00
|
|
|
|
|
|
|
# Check the TracePoint is disabled
|
|
|
|
called = false
|
2019-02-21 10:38:59 -05:00
|
|
|
line_event = true
|
2017-12-01 12:51:16 -05:00
|
|
|
called.should == false
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if trace was disabled' do
|
2019-02-21 10:38:59 -05:00
|
|
|
called = false
|
|
|
|
trace = TracePoint.new(:line) do |tp|
|
|
|
|
called = true
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
|
|
|
|
2019-02-21 10:38:59 -05:00
|
|
|
line_event = true
|
|
|
|
trace.disable.should == false
|
|
|
|
line_event = true
|
|
|
|
called.should == false
|
2017-12-01 10:41:50 -05: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 12:51:16 -05:00
|
|
|
begin
|
|
|
|
trace.disable { enabled = trace.enabled? }
|
2019-02-21 10:38:59 -05:00
|
|
|
enabled.should == false
|
2020-05-03 06:28:29 -04:00
|
|
|
trace.should.enabled?
|
2017-12-01 12:51:16 -05:00
|
|
|
ensure
|
|
|
|
trace.disable
|
|
|
|
end
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
|
|
|
|
2019-02-21 10:38:59 -05:00
|
|
|
it 'returns the return value of the block' do
|
2017-12-01 10:41:50 -05:00
|
|
|
trace = TracePoint.new(:line) {}
|
|
|
|
trace.enable
|
2017-12-01 12:51:16 -05:00
|
|
|
begin
|
2019-02-21 10:38:59 -05:00
|
|
|
trace.disable { 42 }.should == 42
|
2020-05-03 06:28:29 -04:00
|
|
|
trace.should.enabled?
|
2017-12-01 12:51:16 -05:00
|
|
|
ensure
|
|
|
|
trace.disable
|
|
|
|
end
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it 'can accept param within a block but it should not yield arguments' do
|
|
|
|
trace = TracePoint.new(:line) {}
|
|
|
|
trace.enable
|
|
|
|
begin
|
|
|
|
trace.disable do |*args|
|
|
|
|
args.should == []
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
2020-05-03 06:28:29 -04:00
|
|
|
trace.should.enabled?
|
2019-04-27 12:53:23 -04:00
|
|
|
ensure
|
|
|
|
trace.disable
|
2017-12-01 10:41:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|