From 887e4d056aa99052f2a97e26b07cd6d6d2be73d2 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 27 Aug 2023 18:47:19 +0200 Subject: [PATCH] Expand tests of Fiber.[] * It can access storage of the parent fiber * It cannot access storage with non-symbol keys --- core/fiber/storage_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/fiber/storage_spec.rb b/core/fiber/storage_spec.rb index 5e4de0af9..5891edf33 100644 --- a/core/fiber/storage_spec.rb +++ b/core/fiber/storage_spec.rb @@ -92,6 +92,17 @@ it "returns nil if the current fiber has no storage" do Fiber.new { Fiber[:life] }.resume.should be_nil end + + it "can access the storage of the parent fiber" do + f = Fiber.new(storage: {life: 42}) do + Fiber.new { Fiber[:life] }.resume + end + f.resume.should == {life: 42} + end + + it "can't access the storage of the fiber with non-symbol keys" do + -> { Fiber[Object.new] }.should raise_error(TypeError) + end end end