From bc36e869583849d6073e1a44c596dfb34691d6db Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 27 Aug 2023 18:53:51 +0200 Subject: [PATCH] Expand tests for Fiber.[]= * Checks for not overwriting the storage of the parent fiber * Cannot access with non symbol key --- core/fiber/storage_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/fiber/storage_spec.rb b/core/fiber/storage_spec.rb index 5891edf33..7188dae8b 100644 --- a/core/fiber/storage_spec.rb +++ b/core/fiber/storage_spec.rb @@ -119,6 +119,19 @@ it "sets the value of the given key in the storage of the current fiber" do Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43 end + + it "does not overwrite the storage of the parent fiber" do + f = Fiber.new(storage: {life: 42}) do + Fiber.yield Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume + Fiber[:life] + end + f.resume.should == 43 # Value of the inner fiber + f.resume.should == 42 # Value of the outer fiber + end + + it "can't access the storage of the fiber with non-symbol keys" do + -> { Fiber[Object.new] = 44 }.should raise_error(TypeError) + end end ruby_version_is "3.3" do