summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2024-04-17 23:08:47 +1200
committerGitHub <noreply@github.com>2024-04-17 23:08:47 +1200
commit6ade36c06b7cef948099b8f5f483763498705d12 (patch)
treecf647f2c9716ef9e01d7194f29ba974214b91cac /spec
parent945a0334c71412ddeeb540f68481eee40e250c61 (diff)
`Fiber#raise` recursively raises on nested resuming_fiber. (#10482)
* Improve consistency of `Fiber.current.raise`.
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/fiber/raise_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/ruby/core/fiber/raise_spec.rb b/spec/ruby/core/fiber/raise_spec.rb
index eb4b39c8be..b3e021e636 100644
--- a/spec/ruby/core/fiber/raise_spec.rb
+++ b/spec/ruby/core/fiber/raise_spec.rb
@@ -91,6 +91,40 @@ describe "Fiber#raise" do
fiber_two.resume.should == [:yield_one, :rescued]
end
+
+ ruby_version_is "3.4" do
+ it "raises on the resumed fiber" do
+ root_fiber = Fiber.current
+ f1 = Fiber.new { root_fiber.transfer }
+ f2 = Fiber.new { f1.resume }
+ f2.transfer
+
+ -> do
+ f2.raise(RuntimeError, "Expected error")
+ end.should raise_error(RuntimeError, "Expected error")
+ end
+
+ it "raises on itself" do
+ -> do
+ Fiber.current.raise(RuntimeError, "Expected error")
+ end.should raise_error(RuntimeError, "Expected error")
+ end
+
+ it "should raise on parent fiber" do
+ f2 = nil
+ f1 = Fiber.new do
+ # This is equivalent to Kernel#raise:
+ f2.raise(RuntimeError, "Expected error")
+ end
+ f2 = Fiber.new do
+ f1.resume
+ end
+
+ -> do
+ f2.resume
+ end.should raise_error(RuntimeError, "Expected error")
+ end
+ end
end