Skip to content

Commit e416b01

Browse files
committed
Add specs for Thread.each_caller_location
1 parent d598249 commit e416b01

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "Thread.each_caller_location" do
4+
ruby_version_is "3.2" do
5+
context "starts at the default frame that caller_locations would start at and" do
6+
it "yields Thread::Backtrace::Location" do
7+
i = 0;
8+
ecl = Thread.each_caller_location do |loc|
9+
i += 1;
10+
break loc if i == 1;
11+
end
12+
13+
ecl.to_s.should == caller_locations(1, 1)[0].to_s
14+
ecl.should be_kind_of(Thread::Backtrace::Location)
15+
end
16+
17+
it "yields multiple Thread::Backtrace::Locations" do
18+
i = 0;
19+
ar = []
20+
ecl = Thread.each_caller_location do |loc|
21+
ar << loc;
22+
i += 1;
23+
break loc if i == 2;
24+
end
25+
26+
ar.map(&:to_s).should == caller_locations(1..2).map(&:to_s)
27+
ecl.should be_kind_of(Thread::Backtrace::Location)
28+
end
29+
end
30+
31+
it "raises StopIteration if reached an end" do
32+
-> {
33+
Thread.to_enum(:each_caller_location).next
34+
}.should raise_error(StopIteration, "iteration reached an end")
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)