From d31cf749dfa03ef7ddc317044c858226f5370568 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 ce0351927..7efa23944 100644 --- a/core/fiber/storage_spec.rb +++ b/core/fiber/storage_spec.rb @@ -117,6 +117,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