Module: Maxitest::Helpers::InstanceMethods

Defined in:
lib/maxitest/helpers.rb

Instance Method Summary collapse

Instance Method Details

#capture_stderrObject

stripped down version of capture_io



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

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

#capture_stdoutObject

stripped down version of capture_io



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

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

#with_env(env) ⇒ Object



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

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