blob: 675f9939c1ddaec486cc10965acca1516fe5f051 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
require File.expand_path('../../../spec_helper', __FILE__)
describe 'TracePoint#enable' do
def test; 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
test
event_name.should == nil
trace.enable
test
event_name.should equal(:call)
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
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
trace.disable
end
end
describe 'with a block' do
it 'enables the trace object within a block' do
event_name = nil
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
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 'returns value returned by the block' do
trace = TracePoint.new(:line) {}
trace.enable { true; 'test' }.should == 'test'
end
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
|