1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/core/fiber/new_spec.rb

40 lines
819 B
Ruby
Raw Normal View History

require_relative '../../spec_helper'
2019-04-28 17:20:11 -04:00
describe "Fiber.new" do
it "creates a fiber from the given block" do
fiber = Fiber.new {}
fiber.resume
fiber.should be_an_instance_of(Fiber)
end
2019-04-28 17:20:11 -04:00
it "creates a fiber from a subclass" do
class MyFiber < Fiber
end
2019-04-28 17:20:11 -04:00
fiber = MyFiber.new {}
fiber.resume
fiber.should be_an_instance_of(MyFiber)
end
2019-04-28 17:20:11 -04:00
it "raises an ArgumentError if called without a block" do
2019-07-27 06:40:09 -04:00
-> { Fiber.new }.should raise_error(ArgumentError)
2019-04-28 17:20:11 -04:00
end
2019-04-28 17:20:11 -04:00
it "does not invoke the block" do
invoked = false
fiber = Fiber.new { invoked = true }
invoked.should be_false
fiber.resume
end
2019-04-28 17:20:11 -04:00
it "closes over lexical environments" do
o = Object.new
def o.f
a = 1
f = Fiber.new { a = 2 }
f.resume
a
end
2019-04-28 17:20:11 -04:00
o.f.should == 2
end
end