Skip to content

Commit

Permalink
Move version guard in fiber storage spec to top level
Browse files Browse the repository at this point in the history
This feature is introduced in Ruby 3.2, so by wrapping everything in the
version guard there is no more need to repeat in at every block.
  • Loading branch information
herwinw authored and eregon committed Aug 29, 2023
1 parent 0ef4c80 commit 7a818ec
Showing 1 changed file with 7 additions and 17 deletions.
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

0 comments on commit 7a818ec

Please sign in to comment.