Module: RSpec::Support::InSubProcess
- Defined in:
- lib/rspec/support/spec/in_sub_process.rb
Instance Method Summary collapse
-
#in_sub_process ⇒ Object
rubocop:disable MethodLength.
-
#in_sub_process_if_possible ⇒ Object
rubocop:disable MethodLength rubocop:enable MethodLength.
Instance Method Details
#in_sub_process ⇒ Object
rubocop:disable MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rspec/support/spec/in_sub_process.rb', line 9 def in_sub_process(prevent_warnings=true) readme, writeme = IO.pipe pid = Process.fork do exception = nil warning_preventer = $stderr = RSpec::Support::StdErrSplitter.new($stderr) begin yield warning_preventer.verify_no_warnings! if prevent_warnings rescue Exception => e exception = e end writeme.write Marshal.dump(exception) readme.close writeme.close exit! # prevent at_exit hooks from running (e.g. minitest) end writeme.close Process.waitpid(pid) exception = Marshal.load(readme.read) readme.close raise exception if exception end |
#in_sub_process_if_possible ⇒ Object
rubocop:disable MethodLength rubocop:enable MethodLength
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rspec/support/spec/in_sub_process.rb', line 39 def in_sub_process(prevent_warnings=true) readme, writeme = IO.pipe pid = Process.fork do exception = nil warning_preventer = $stderr = RSpec::Support::StdErrSplitter.new($stderr) begin yield warning_preventer.verify_no_warnings! if prevent_warnings rescue Exception => e exception = e end writeme.write Marshal.dump(exception) readme.close writeme.close exit! # prevent at_exit hooks from running (e.g. minitest) end writeme.close Process.waitpid(pid) exception = Marshal.load(readme.read) readme.close raise exception if exception end |