From 83c1550a2706d956f478bac5ec7a2c1eafe52fb2 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 d173da4a3..ce0351927 100644 --- a/core/fiber/storage_spec.rb +++ b/core/fiber/storage_spec.rb @@ -90,6 +90,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 == 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