module Gorillib::TestHelpers
Public Instance Methods
capture_output() { || ... }
click to toggle source
Temporarily sets the global variables $stderr and $stdout to a capturable StringIO; restores them at the end, even if there is an error
# File lib/gorillib/utils/capture_output.rb, line 22 def capture_output dummy_stdio{ yield } end
Also aliased as: quiet_output
dummy_stdio(stdin_text=nil) { || ... }
click to toggle source
# File lib/gorillib/utils/capture_output.rb, line 5 def dummy_stdio(stdin_text=nil) stdin = stdin_text.nil? ? $stdin : StringIO.new(stdin_text) new_fhs = [stdin, StringIO.new('', 'w'), StringIO.new('', 'w')] old_fhs = [$stdin, $stdout, $stderr] begin $stdin, $stdout, $stderr = new_fhs yield ensure $stdin, $stdout, $stderr = old_fhs end new_fhs[1..2] end