Module: Tapioca::Helpers::Test::Isolation::Forking
- Extended by:
- T::Helpers, T::Sig
- Included in:
- Tapioca::Helpers::Test::Isolation
- Defined in:
- lib/tapioca/helpers/test/isolation.rb
Instance Method Summary collapse
-
#run_in_isolation(&_blk) ⇒ Object
: ?{ (?) -> untyped } -> String.
Instance Method Details
#run_in_isolation(&_blk) ⇒ Object
: ?{ (?) -> untyped } -> String
38 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 68 69 70 71 72 73 |
# File 'lib/tapioca/helpers/test/isolation.rb', line 38 def run_in_isolation(&_blk) read, write = IO.pipe read.binmode write.binmode this = T.cast(self, Minitest::Test) pid = fork do read.close yield begin if this.error? this.failures.map! do |e| Marshal.dump(e) e rescue TypeError ex = Exception.new(e.) ex.set_backtrace(e.backtrace) Minitest::UnexpectedError.new(ex) end end test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : this.dup result = Marshal.dump(test_result) end write.puts [result].pack("m") write.close exit!(false) end write.close result = read.read read.close Process.wait2(pid) result.unpack1("m") end |