Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
244ea65
Add spec for TracePoint#new
Atul9 Oct 15, 2017
edf50d2
Add spec for TracePoint#trace
Atul9 Oct 15, 2017
4f9e612
Add specs for TracePoint#disable
Atul9 Oct 15, 2017
25b4f26
Add specs for TracePoint#enable
Atul9 Oct 15, 2017
47138a1
Add spec for TracePoint#binding
Atul9 Oct 15, 2017
9ab3a7a
Add spec for TracePoint#defined_class
Atul9 Oct 15, 2017
c3d3ea8
Add spec for TracePoint#enabled?
Atul9 Oct 15, 2017
da7768a
Add spec for TracePoint#event
Atul9 Oct 15, 2017
2f2437d
Add spec for TracePoint#inspect
Atul9 Oct 15, 2017
c2cff28
Add spec for TracePoint#lineno
Atul9 Oct 15, 2017
5db554f
Add spec for TracePoint#method_id
Atul9 Oct 15, 2017
38b985b
Add spec for TracePoint#path
Atul9 Oct 15, 2017
25e1d98
Add spec for TracePoint#raised_exception
Atul9 Oct 15, 2017
d980bf7
Add spec for TracePoint#return_value
Atul9 Oct 15, 2017
5509912
Add spec for TracePoint#self
Atul9 Oct 15, 2017
b41bb0a
Rename ruby version to 2.0, since TracePoint was introduced in 2.0
Atul9 Oct 16, 2017
03a2cb5
TracePoint#defined_class check for module & calls made in inheritance…
Atul9 Oct 16, 2017
6aff6e5
Update TracePoint#self spec
Atul9 Oct 16, 2017
996ac8a
TracePoint#enable TracePoint#disable - Add specs
Atul9 Oct 16, 2017
c4f97a1
Add TracePoint#enabled? spec when trace is enabled
Atul9 Oct 16, 2017
f662fac
Add TracePoint#event spec for multiple events
Atul9 Oct 16, 2017
7c29a4c
Add TracePoint#new specs
Atul9 Oct 16, 2017
2b6b2b5
Update TracePoint#raised_exception & #return_value
Atul9 Oct 16, 2017
fbca3e3
Define class A in a module ClassSpecs to fix test
Atul9 Oct 17, 2017
1db9f74
Update #defined_class & #event spec to use TracePointSpec module
Atul9 Oct 17, 2017
e779c2e
Add specs to TracePoint#new & #path
Atul9 Oct 17, 2017
2ed6b17
Define module & classes in TracePointSpec module
Atul9 Oct 17, 2017
181972a
TracePoint - disable trace at end of each spec/ enclose spec within {}
Atul9 Oct 22, 2017
2d55b37
TracePoint#enable add specs for enable {'with block'}
Atul9 Oct 24, 2017
62a7e82
TracePoint#enable add spec to check if args are nil within enable block
Atul9 Oct 25, 2017
d07cc9a
TracePoint#path spec to check for path inside eval
Atul9 Oct 25, 2017
2350809
TracePoint#enable add specs for enable {with_block}
Atul9 Oct 25, 2017
e274e66
TracePoint#path Remove global test definition & other events specs
Atul9 Oct 27, 2017
a191029
TracePoint#disable add specs for disable{} & spec for ruby bug #14057
Atul9 Oct 27, 2017
5c4001c
TracePoint#enable update to check for enable{} result & spec for ruby…
Atul9 Oct 27, 2017
af2c421
Improve TracePoint#binding specs based on review
eregon Oct 28, 2017
d748f08
TracePoint#disable update block spec & add spec to check block result
Atul9 Oct 28, 2017
0a9c1e4
TracePoint#enable update block spec & add spec to check block result
Atul9 Oct 28, 2017
3b50ef4
Update TracePoint#new spec to use raise_error matcher
Atul9 Nov 1, 2017
1d2a900
Update TracePointSpec module & Tracepoint#new spec
Atul9 Nov 1, 2017
bbb2954
Update TracePoint#event spec to use test method from TracePointSpec m…
Atul9 Nov 1, 2017
8803665
TracePoint#enable Rename labelling of spec
Atul9 Nov 2, 2017
2f8762b
Merge branch 'master' into trace_point_specs
Atul9 Nov 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/tracepoint/binding_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' do
describe 'TracePoint#binding' do
def test
secret = 42
end

it 'return the generated binding object from event' do
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
28 changes: 28 additions & 0 deletions core/tracepoint/defined_class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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
it 'returns class or module of the method being called' do
last_class_name = nil
TracePoint.new(:call) do |tp|
last_class_name = tp.defined_class
end.enable do
TracePointSpec::B.new.foo
last_class_name.should equal(TracePointSpec::B)

TracePointSpec::B.new.bar
last_class_name.should equal(TracePointSpec::A)

c = TracePointSpec::C.new
last_class_name.should equal(TracePointSpec::C)

c.foo
last_class_name.should equal(TracePointSpec::B)

c.bar
last_class_name.should equal(TracePointSpec::A)
end
end
end
end
66 changes: 66 additions & 0 deletions core/tracepoint/disable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' do
describe 'TracePoint#disable' do
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

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

it 'is disabled within a block & is enabled outside the block' do
enabled = nil
trace = TracePoint.new(:line) {}
trace.enable
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

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
94 changes: 94 additions & 0 deletions core/tracepoint/enable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' do
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
end
16 changes: 16 additions & 0 deletions core/tracepoint/enabled_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' do
describe 'TracePoint#enabled?' do
it 'returns true when current status of the trace is enable' do
trace = TracePoint.new(:call) {}
trace.enable do
trace.enabled?.should be_true
end
end

it 'returns false when current status of the trace is disabled' do
TracePoint.new(:call) {}.enabled?.should be_false
end
end
end
23 changes: 23 additions & 0 deletions core/tracepoint/event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

ruby_version_is '2.0' do
describe 'TracePoint#event' do
it 'returns the type of event' do
event_name = nil
TracePoint.new(:end, :call) do |tp|
event_name = tp.event
end.enable do
TracePointSpec.test
event_name.should equal(:call)

TracePointSpec::B.new.foo
event_name.should equal(:call)

class B; end
event_name.should equal(:end)
end

end
end
end
28 changes: 27 additions & 1 deletion core/tracepoint/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,31 @@ def m
end
alias_method :m_alias, :m
end
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

def self.test
'test'
end
end
10 changes: 10 additions & 0 deletions core/tracepoint/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' do
describe 'TracePoint#inspect' do
it 'returns a string containing a human-readable TracePoint status' do
TracePoint.new(:call) {}.inspect.should ==
'#<TracePoint:disabled>'
end
end
end
12 changes: 12 additions & 0 deletions core/tracepoint/lineno_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' do
describe 'TracePoint#lineno' do
it 'returns the line number of the event' do
lineno = nil
TracePoint.new(:line) { |tp| lineno = tp.lineno }.enable do
lineno.should equal(8)
end
end
end
end
15 changes: 15 additions & 0 deletions core/tracepoint/method_id_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is '2.0' 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 do
test
method_name.should equal(:test)
end
end
end
end
70 changes: 70 additions & 0 deletions core/tracepoint/new_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

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
end

it 'includes :line event when event is not specified' do
event_name = nil
TracePoint.new() { |tp| event_name = tp.event }.enable do
event_name.should equal(:line)

event_name = nil
TracePointSpec.test
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 do
event_name.should equal(nil)
TracePointSpec.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 do
TracePointSpec.test
event_name.should equal(:call)

TracePointSpec::B.new.foo
event_name.should equal(:call)

class B; end
event_name.should equal(:end)
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

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
-> { TracePoint.new(:test) }.should raise_error(ArgumentError)
end
end
end
Loading