1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-12-01 17:51:16 +00:00
parent 60775cc48a
commit d209b4c0a2
2 changed files with 53 additions and 34 deletions

View file

@ -3,18 +3,18 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe 'TracePoint#disable' do describe 'TracePoint#disable' do
def test; end def test; end
it 'returns true if trace was enabled' do it 'returns true if trace was enabled' do
event_name, method_name = nil called = false
trace = TracePoint.new(:call) do |tp| trace = TracePoint.new(:call) do |tp|
event_name = tp.event called = true
method_name = tp.method_id
end end
trace.enable trace.enable
trace.disable.should be_true trace.disable.should be_true
event_name, method_name = nil
# Check the TracePoint is disabled
called = false
test test
method_name.equal?(:test).should be_false called.should == false
event_name.should equal(nil)
end end
it 'returns false if trace was disabled' do it 'returns false if trace was disabled' do
@ -35,30 +35,39 @@ describe 'TracePoint#disable' do
enabled = nil enabled = nil
trace = TracePoint.new(:line) {} trace = TracePoint.new(:line) {}
trace.enable trace.enable
begin
trace.disable { enabled = trace.enabled? } trace.disable { enabled = trace.enabled? }
enabled.should be_false enabled.should be_false
trace.enabled?.should be_true trace.enabled?.should be_true
ensure
trace.disable trace.disable
end end
end
it 'is disabled within a block & also returns false when its called with a block' do it 'is disabled within a block & also returns false when its called with a block' do
trace = TracePoint.new(:line) {} trace = TracePoint.new(:line) {}
trace.enable trace.enable
begin
trace.disable { trace.enabled? }.should == false trace.disable { trace.enabled? }.should == false
trace.enabled?.should equal(true) trace.enabled?.should equal(true)
ensure
trace.disable trace.disable
end end
end
ruby_bug "#14057", "2.0"..."2.5" do ruby_bug "#14057", "2.0"..."2.5" do
it 'can accept param within a block but it should not yield arguments' do it 'can accept param within a block but it should not yield arguments' do
event_name = nil event_name = nil
trace = TracePoint.new(:line) {} trace = TracePoint.new(:line) {}
trace.enable trace.enable
begin
trace.disable do |*args| trace.disable do |*args|
args.should == [] args.should == []
end end
trace.enabled?.should be_true trace.enabled?.should be_true
ensure
trace.disable trace.disable
end end
end end
end end
end

View file

@ -5,21 +5,22 @@ describe 'TracePoint#enable' do
describe 'without a block' do describe 'without a block' do
it 'returns true if trace was enabled' do it 'returns true if trace was enabled' do
event_name, method_name = nil, nil event_name = nil
method_name = []
trace = TracePoint.new(:call) do |tp| trace = TracePoint.new(:call) do |tp|
event_name = tp.event event_name = tp.event
method_name << tp.method_id
end end
test test
event_name.should == nil event_name.should == nil
trace.enable trace.enable
begin
test test
event_name.should equal(:call) event_name.should equal(:call)
ensure
trace.disable trace.disable
end end
end
it 'returns false if trace was disabled' do it 'returns false if trace was disabled' do
event_name, method_name = nil, nil event_name, method_name = nil, nil
@ -29,23 +30,29 @@ describe 'TracePoint#enable' do
end end
trace.enable.should be_false trace.enable.should be_false
begin
event_name.should equal(:call) event_name.should equal(:call)
test test
method_name.equal?(:test).should be_true method_name.equal?(:test).should be_true
ensure
trace.disable trace.disable
end
event_name, method_name = nil event_name, method_name = nil
test test
method_name.equal?(:test).should be_false method_name.equal?(:test).should be_false
event_name.should equal(nil) event_name.should equal(nil)
trace.enable.should be_false trace.enable.should be_false
begin
event_name.should equal(:call) event_name.should equal(:call)
test test
method_name.equal?(:test).should be_true method_name.equal?(:test).should be_true
ensure
trace.disable trace.disable
end end
end end
end
describe 'with a block' do describe 'with a block' do
it 'enables the trace object within a block' do it 'enables the trace object within a block' do
@ -71,10 +78,13 @@ describe 'TracePoint#enable' do
enabled = nil enabled = nil
trace = TracePoint.new(:line) {} trace = TracePoint.new(:line) {}
trace.enable trace.enable
begin
trace.enable { enabled = trace.enabled? } trace.enable { enabled = trace.enabled? }
enabled.should == true enabled.should == true
ensure
trace.disable trace.disable
end end
end
it 'returns value returned by the block' do it 'returns value returned by the block' do
trace = TracePoint.new(:line) {} trace = TracePoint.new(:line) {}