Module: Maxitest::Helpers::InstanceMethods

Included in:
Minitest::Test
Defined in:
lib/maxitest/helpers.rb

Instance Method Summary collapse

Instance Method Details

#capture_stderrObject

stripped down version of capture_io



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/maxitest/helpers.rb', line 29

def capture_stderr
  _synchronize do
    captured_stderr = StringIO.new
    orig_stderr = $stderr
    $stderr = captured_stderr
    yield
    return captured_stderr.string
  ensure
    $stderr = orig_stderr
  end
end

#capture_stdoutObject

stripped down version of capture_io



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/maxitest/helpers.rb', line 16

def capture_stdout
  _synchronize do
    captured_stdout = StringIO.new
    orig_stdout = $stdout
    $stdout = captured_stdout
    yield
    return captured_stdout.string
  ensure
    $stdout = orig_stdout
  end
end

#with_env(env) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/maxitest/helpers.rb', line 5

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