Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Add fork_supported?. #342

Merged
merged 1 commit into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions lib/rspec/support/ruby_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ def mri?
module RubyFeatures
module_function

if Ruby.jruby?
# On JRuby 1.7 `--1.8` mode, `Process.respond_to?(:fork)` returns true,
# but when you try to fork, it raises an error:
# NotImplementedError: fork is not available on this platform
#
# When we drop support for JRuby 1.7 and/or Ruby 1.8, we can drop
# this special case.
def fork_supported?
false
end
else
def fork_supported?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we define this conditionally or memoized to avoid calling Process.respond_to?(:fork) repeatedly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd want a benchmark showing memoization is faster as Process.respond_to?(:fork) isn't something I'd expect to be slow. Re: defining it conditionally...we could, but that's not an approach we're consistently following in this file. If we want to go that route, I think we should do it consistently throughout this file.

This method is only going to be called once per spec run (in RSpec::Core::Configuration#initialize) so it's definitely not a perf hot spot, anyway.

Process.respond_to?(:fork)
end
end

def optional_and_splat_args_supported?
Method.method_defined?(:parameters)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/rspec/support/ruby_features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ module Support
end
end

specify "#fork_supported? exists" do
RubyFeatures.fork_supported?
end

specify "#supports_exception_cause? exists" do
RubyFeatures.supports_exception_cause?
end
Expand Down