Skip to content

Commit

Permalink
Add specs for Thread.each_caller_location
Browse files Browse the repository at this point in the history
  • Loading branch information
AI-Mozi committed May 24, 2023
1 parent d598249 commit e416b01
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core/thread/each_caller_location_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative '../../spec_helper'

describe "Thread.each_caller_location" do
ruby_version_is "3.2" do
context "starts at the default frame that caller_locations would start at and" do
it "yields Thread::Backtrace::Location" do
i = 0;
ecl = Thread.each_caller_location do |loc|
i += 1;
break loc if i == 1;
end

ecl.to_s.should == caller_locations(1, 1)[0].to_s
ecl.should be_kind_of(Thread::Backtrace::Location)
end

it "yields multiple Thread::Backtrace::Locations" do
i = 0;
ar = []
ecl = Thread.each_caller_location do |loc|
ar << loc;
i += 1;
break loc if i == 2;
end

ar.map(&:to_s).should == caller_locations(1..2).map(&:to_s)
ecl.should be_kind_of(Thread::Backtrace::Location)
end
end

it "raises StopIteration if reached an end" do
-> {
Thread.to_enum(:each_caller_location).next
}.should raise_error(StopIteration, "iteration reached an end")
end
end
end

0 comments on commit e416b01

Please sign in to comment.