Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move version guard in fiber storage spec to top level #1061

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions core/fiber/storage_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'

describe "Fiber.new(storage:)" do
ruby_version_is "3.2" do
ruby_version_is "3.2" do
describe "Fiber.new(storage:)" do
it "creates a Fiber with the given storage" do
storage = {life: 42}
fiber = Fiber.new(storage: storage) { Fiber.current.storage }
Expand Down Expand Up @@ -31,21 +31,17 @@
-> { Fiber.new(storage: {life: 43, Object.new => 44}) {} }.should raise_error(TypeError)
end
end
end

describe "Fiber#storage" do
ruby_version_is "3.2" do
describe "Fiber#storage" do
it "cannot be accessed from a different fiber" do
f = Fiber.new(storage: {life: 42}) { nil }
-> {
f.storage
}.should raise_error(ArgumentError, /Fiber storage can only be accessed from the Fiber it belongs to/)
end
end
end

describe "Fiber#storage=" do
ruby_version_is "3.2" do
describe "Fiber#storage=" do
it "can clear the storage of the fiber" do
fiber = Fiber.new(storage: {life: 42}) do
Fiber.current.storage = nil
Expand Down Expand Up @@ -75,10 +71,8 @@
-> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError)
end
end
end

describe "Fiber.[]" do
ruby_version_is "3.2" do
describe "Fiber.[]" do
it "returns the value of the given key in the storage of the current fiber" do
Fiber.new(storage: {life: 42}) { Fiber[:life] }.resume.should == 42
end
Expand All @@ -102,10 +96,8 @@
-> { Fiber[Object.new] }.should raise_error(TypeError)
end
end
end

describe "Fiber.[]=" do
ruby_version_is "3.2" do
describe "Fiber.[]=" do
it "sets the value of the given key in the storage of the current fiber" do
Fiber.new(storage: {life: 42}) { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
end
Expand Down Expand Up @@ -137,10 +129,8 @@
Fiber.new(storage: {life: 42}) { Fiber[:life] = nil; Fiber.current.storage }.resume.should == {}
end
end
end

describe "Thread.new" do
ruby_version_is "3.2" do
describe "Thread.new" do
it "creates a thread with the storage of the current fiber" do
fiber = Fiber.new(storage: {life: 42}) do
Thread.new { Fiber.current.storage }.value
Expand Down