File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1+ require 'stringio'
2+
13# utility methods totally not edited from StackOverflow
24class Utils
35 # captures stdout from a block: out = capture_stdout { code }
46 def self . capture_stdout
5- old_stdout = $stdout
7+ Thread . current [ : old_stdout] = $stdout
68 $stdout = StringIO . new
79 yield
810 $stdout. string
911 ensure
10- $stdout = old_stdout
12+ $stdout = Thread . current [ :old_stdout ] if Thread . current [ :old_stdout ]
13+ Thread . current [ :old_stdout ] = nil
1114 end
1215
1316 # captures stderr from a block: err = capture_stderr { code }
1417 def self . capture_stderr
15- old_stderr = $stderr
18+ Thread . current [ : old_stderr] = $stderr
1619 $stderr = StringIO . new
1720 yield
1821 $stderr. string
1922 ensure
20- $stderr = old_stderr
23+ $stderr = Thread . current [ :old_stderr ] if Thread . current [ :old_stderr ]
24+ Thread . current [ :old_stderr ] = nil
2125 end
2226end
You can’t perform that action at this time.
0 commit comments