Skip to content

Commit 346921d

Browse files
author
Nicolas Laurent
committed
add tests for Kernel#caller_locations
1 parent cbe7e32 commit 346921d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

spec/ruby/core/kernel/caller_locations_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,39 @@
2222
locations.length.should == 1
2323
end
2424

25+
it "can be called with a range" do
26+
locations1 = caller_locations(0)
27+
locations2 = caller_locations(2..4)
28+
locations1[2..4].map(&:to_s).should == locations2.map(&:to_s)
29+
end
30+
31+
it "can be called with a range whose end is negative" do
32+
locations1 = caller_locations(0)
33+
locations2 = caller_locations(2..-1)
34+
locations3 = caller_locations(2..-2)
35+
locations1[2..-1].map(&:to_s).should == locations2.map(&:to_s)
36+
locations1[2..-2].map(&:to_s).should == locations3.map(&:to_s)
37+
end
38+
39+
it "must return nil if omitting more locations than available" do
40+
caller_locations(100).should == nil
41+
caller_locations(100..-1).should == nil
42+
end
43+
44+
it "must return [] if omitting exactly the number of locations available" do
45+
omit = caller_locations(0).length
46+
caller_locations(omit).should == []
47+
end
48+
2549
it 'returns the locations as Thread::Backtrace::Location instances' do
2650
locations = KernelSpecs::CallerLocationsTest.locations
2751

2852
locations.each do |location|
2953
location.kind_of?(Thread::Backtrace::Location).should == true
3054
end
3155
end
56+
57+
it "must return the same locations when called with 1..-1 and when called with no arguments" do
58+
caller_locations.map(&:to_s).should == caller_locations(1..-1).map(&:to_s)
59+
end
3260
end

0 commit comments

Comments
 (0)