-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
add spec for Fiber#raise #809
Conversation
library/fiber/raise.rb
Outdated
@@ -0,0 +1,91 @@ | |||
require_relative '../../spec_helper' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fiber#raise is actually a core method (it does not need require 'fiber'
unlike e.g. Fiber#transfer), so it should be in core/fiber/raise_spec.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This a good start but needs some fixes.
library/fiber/raise.rb
Outdated
-> { fiber.raise }.should raise_error(FiberError, "dead fiber called") | ||
end | ||
|
||
class TestError < StandardError ; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will define a new global constant, it should instead be nested under module FiberSpecs
, or Class.new(StandardError)
be used instead.
library/fiber/raise.rb
Outdated
ruby_version_is "2.7" do | ||
describe "Fiber#raise" do | ||
|
||
it 'raise RuntimeError by default' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec descriptions should form a sentence, so typically the first word will be a 3rd person present verb like raises/accepts/does not accept
, etc.
There are specs for Kernel/Thread#raise (https://github.com/ruby/spec/blob/master/shared/kernel/raise.rb) we should be able to reuse here, like so: module FiberSpecs
class NewFiberToRaise
def self.raise(*args)
fiber = Fiber.new { Fiber.yield }
fiber.resume
fiber.raise(*args)
end
end
end
describe "Fiber#raise" do
it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
end |
Thanks for your comment! I have followed your suggestion and update the code, everything works fine except one.
I think Fiber has a different mechanism here. Fiber does not, it will jump to the file where Fiber yield was and throw an exception. Not active by raise. |
@kuei0221 I think that's simply of the extra indirection we have for |
0837f2d
to
dafe897
Compare
dafe897
to
c187994
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the new specs!
This PR is for solving #745, add spec of Fiber#raise. I am not very familiar with Fiber, so tell me if anything needs to improve 😄