Skip to content

Commit

Permalink
Ruby 3.4 allows Strings as Fiber storage keys
Browse files Browse the repository at this point in the history
But not anything else that responds to #to_sym
  • Loading branch information
herwinw committed Dec 31, 2024
1 parent ecb47be commit 1c0c8d8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/fiber/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,30 @@
end

it "can't use invalid keys" do
invalid_keys = [Object.new, "Foo", 12]
invalid_keys = [Object.new, 12]
invalid_keys.each do |key|
-> { Fiber[key] }.should raise_error(TypeError)
end
end

ruby_version_is ""..."3.4" do
it "can't use String as a key" do
-> { Fiber["Foo"] }.should raise_error(TypeError)
end
end
end

ruby_version_is "3.4" do
it "can use String as a key" do
Fiber["Foo"] = 123
Fiber["Foo"].should == 123
end
end

it "does not call #to_sym on the key" do
key = mock("key")
key.should_not_receive(:to_sym)
-> { Fiber[key] }.should raise_error(TypeError)
end

it "can access the storage of the parent fiber" do
Expand Down

0 comments on commit 1c0c8d8

Please sign in to comment.