module Maxitest::Helpers::InstanceMethods

def capture_stderr

stripped down version of capture_io
def capture_stderr
  _synchronize do
    begin
      captured_stderr = StringIO.new
      orig_stderr = $stderr
      $stderr = captured_stderr
      yield
      return captured_stderr.string
    ensure
      $stderr = orig_stderr
    end
  end
end

def capture_stdout

stripped down version of capture_io
def capture_stdout
  _synchronize do
    begin
      captured_stdout = StringIO.new
      orig_stdout = $stdout
      $stdout = captured_stdout
      yield
      return captured_stdout.string
    ensure
      $stdout = orig_stdout
    end
  end
end

def with_env(env)

def with_env(env)
  _synchronize do
    old = ENV.to_h
    env.each { |k, v| ENV[k.to_s] = v }
    yield
  ensure
    ENV.replace old
  end
end