Skip to content

Commit

Permalink
Expand tests for Fiber.[]=
Browse files Browse the repository at this point in the history
* Checks for not overwriting the storage of the parent fiber
* Cannot access with non symbol key
  • Loading branch information
herwinw authored and eregon committed Aug 28, 2023
1 parent 83c1550 commit d31cf74
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/fiber/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d31cf74

Please sign in to comment.