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

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,41 @@
require File.expand_path('../../../spec_helper', __FILE__)
with_feature :fiber do
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
it "creates a fiber from a subclass" do
class MyFiber < Fiber
end
fiber = MyFiber.new {}
fiber.resume
fiber.should be_an_instance_of(MyFiber)
end
it "raises an ArgumentError if called without a block" do
lambda { Fiber.new }.should raise_error(ArgumentError)
end
it "does not invoke the block" do
invoked = false
fiber = Fiber.new { invoked = true }
invoked.should be_false
fiber.resume
end
it "closes over lexical environments" do
o = Object.new
def o.f
a = 1
f = Fiber.new { a = 2 }
f.resume
a
end
o.f.should == 2
end
end
end

View file

@ -0,0 +1,54 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/fiber/resume', __FILE__)
with_feature :fiber do
describe "Fiber#resume" do
it_behaves_like :fiber_resume, :resume
end
describe "Fiber#resume" do
it "returns control to the calling Fiber if called from one" do
fiber1 = Fiber.new { :fiber1 }
fiber2 = Fiber.new { fiber1.resume; :fiber2 }
fiber2.resume.should == :fiber2
end
with_feature :fork do
# Redmine #595
it "executes the ensure clause" do
rd, wr = IO.pipe
pid = Kernel::fork do
rd.close
f = Fiber.new do
begin
Fiber.yield
ensure
wr.write "executed"
end
end
# The apparent issue is that when Fiber.yield executes, control
# "leaves" the "ensure block" and so the ensure clause should run. But
# control really does NOT leave the ensure block when Fiber.yield
# executes. It merely pauses there. To require ensure to run when a
# Fiber is suspended then makes ensure-in-a-Fiber-context different
# than ensure-in-a-Thread-context and this would be very confusing.
f.resume
# When we execute the second #resume call, the ensure block DOES exit,
# the ensure clause runs. This is Ruby behavior as of 2.3.1.
f.resume
exit 0
end
wr.close
Process.waitpid pid
rd.read.should == "executed"
rd.close
end
end
end
end

View file

@ -0,0 +1,51 @@
require File.expand_path('../../../spec_helper', __FILE__)
with_feature :fiber do
describe "Fiber.yield" do
it "passes control to the Fiber's caller" do
step = 0
fiber = Fiber.new { step = 1; Fiber.yield; step = 2; Fiber.yield; step = 3 }
fiber.resume
step.should == 1
fiber.resume
step.should == 2
end
it "returns its arguments to the caller" do
fiber = Fiber.new { true; Fiber.yield :glark; true }
fiber.resume.should == :glark
fiber.resume
end
it "returns nil to the caller if given no arguments" do
fiber = Fiber.new { true; Fiber.yield; true }
fiber.resume.should be_nil
fiber.resume
end
it "returns to the Fiber the value of the #resume call that invoked it" do
fiber = Fiber.new { Fiber.yield.should == :caller }
fiber.resume
fiber.resume :caller
end
it "does not propagate or reraise a rescued exception" do
fiber = Fiber.new do
begin
raise "an error in a Fiber"
rescue
Fiber.yield :first
end
:second
end
fiber.resume.should == :first
fiber.resume.should == :second
end
it "raises a FiberError if called from the root Fiber" do
lambda{ Fiber.yield }.should raise_error(FiberError)
end
end
end