summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-12-20 18:21:43 +0100
committerBenoit Daloze <eregontp@gmail.com>2022-12-20 19:32:23 +0100
commit0efa36ac06a14a3e2e0aca395fee6530c790bdf1 (patch)
treeea1b27a60f59fa7ce9e6f3efe5fd9934366c6f15 /spec/ruby
parentd557f17974384dde4ff2da021a1b38905a39bda2 (diff)
Ensure Fiber storage is only accessed from the Fiber it belongs to
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6972
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/core/fiber/storage_spec.rb26
1 files changed, 13 insertions, 13 deletions
diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb
index c0958d98ee..98215ebd59 100644
--- a/spec/ruby/core/fiber/storage_spec.rb
+++ b/spec/ruby/core/fiber/storage_spec.rb
@@ -11,8 +11,7 @@ describe "Fiber.new(storage:)" do
end
it "creates a fiber with lazily initialized storage" do
- fiber = Fiber.new(storage: nil) {}
- fiber.storage.should == {}
+ Fiber.new(storage: nil) { Fiber.current.storage }.resume.should == {}
end
it "creates a fiber by inheriting the storage of the parent fiber" do
@@ -28,33 +27,34 @@ describe "Fiber.new(storage:)" do
end
end
-describe "Fiber#storage" do
+describe "Fiber#storage=" do
ruby_version_is "3.2" do
it "can clear the storage of the fiber" do
- fiber = Fiber.new(storage: {life: 42}) { Fiber.current.storage }
- fiber.storage = nil
+ fiber = Fiber.new(storage: {life: 42}) {
+ Fiber.current.storage = nil
+ Fiber.current.storage
+ }
fiber.resume.should == {}
end
it "can set the storage of the fiber" do
- fiber = Fiber.new(storage: {life: 42}) { Fiber.current.storage }
- fiber.storage = {life: 43}
+ fiber = Fiber.new(storage: {life: 42}) {
+ Fiber.current.storage = {life: 43}
+ Fiber.current.storage
+ }
fiber.resume.should == {life: 43}
end
it "can't set the storage of the fiber to non-hash" do
- fiber = Fiber.new(storage: {life: 42}) { Fiber.current.storage }
- -> { fiber.storage = 42 }.should raise_error(TypeError)
+ -> { Fiber.current.storage = 42 }.should raise_error(TypeError)
end
it "can't set the storage of the fiber to a frozen hash" do
- fiber = Fiber.new(storage: {life: 42}) { Fiber.current.storage }
- -> { fiber.storage = {life: 43}.freeze }.should raise_error(FrozenError)
+ -> { Fiber.current.storage = {life: 43}.freeze }.should raise_error(FrozenError)
end
it "can't set the storage of the fiber to a hash with non-symbol keys" do
- fiber = Fiber.new(storage: {life: 42}) { Fiber.current.storage }
- -> { fiber.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError)
+ -> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError)
end
end
end