File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,43 @@ def assert_directory_exists(path, msg = nil)
145145 assert File . directory? ( path ) , msg
146146 end
147147
148+ # https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb#L188
149+ def _synchronize
150+ yield
151+ end
152+
153+ # https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb#L546
154+ def capture_subprocess_io
155+ _synchronize do
156+ begin
157+ require "tempfile"
158+
159+ captured_stdout , captured_stderr = Tempfile . new ( "out" ) , Tempfile . new ( "err" )
160+
161+ orig_stdout , orig_stderr = $stdout. dup , $stderr. dup
162+ $stdout. reopen captured_stdout
163+ $stderr. reopen captured_stderr
164+
165+ yield
166+
167+ $stdout. rewind
168+ $stderr. rewind
169+
170+ return captured_stdout . read , captured_stderr . read
171+ ensure
172+ captured_stdout . unlink
173+ captured_stderr . unlink
174+ $stdout. reopen orig_stdout
175+ $stderr. reopen orig_stderr
176+
177+ orig_stdout . close
178+ orig_stderr . close
179+ captured_stdout . close
180+ captured_stderr . close
181+ end
182+ end
183+ end
184+
148185 ##
149186 # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores
150187 # the original value when the block ends
You can’t perform that action at this time.
0 commit comments