Module: Rake::TeamCity::StdCaptureHelper

Included in:
Spec::Runner::Formatter::TeamcityFormatter
Defined in:
lib/rspec/teamcity/utils/std_capture_helper.rb

Overview

Captures STDOUT and STDERR

Instance Method Summary collapse

Instance Method Details

#capture_output_end_external(old_out, old_err, new_out, new_err) ⇒ Object

returns STDOUT and STDERR content



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rspec/teamcity/utils/std_capture_helper.rb', line 62

def capture_output_end_external(old_out, old_err, new_out, new_err)
  STDOUT.flush
  STDERR.flush

  if isCaptureDisabled()
    return "", ""
  end

  reopen_stdout_stderr(old_out, old_err)

  return get_redirected_stdout_stderr_from_files(new_out, new_err)
end

#capture_output_start_externalObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rspec/teamcity/utils/std_capture_helper.rb', line 32

def capture_output_start_external
  old_out, old_err = copy_stdout_stderr

  if isCaptureDisabled()
    return old_out, old_err, nil, nil
  end

  new_out = Tempfile.new("tempfile_out")
  new_err = Tempfile.new("tempfile_err")

  reopen_stdout_stderr(new_out, new_err)

  return old_out, old_err, new_out, new_err
end

#copy_stdout_stderrObject



47
48
49
50
51
52
53
# File 'lib/rspec/teamcity/utils/std_capture_helper.rb', line 47

def copy_stdout_stderr
   if isCaptureDisabled()
     return STDOUT, STDERR
   else
     return STDOUT.dup, STDERR.dup
   end
end

#get_redirected_stdout_stderr_from_files(new_out, new_err) ⇒ Object

Closes files’ streams and gets its output.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rspec/teamcity/utils/std_capture_helper.rb', line 76

def get_redirected_stdout_stderr_from_files(new_out, new_err)
  if isCaptureDisabled()
    return "", ""
  end

  begin
    new_out.close
    new_out.open
    s_out = new_out.readlines.join
    new_out.close
  rescue Exception => ex
    s_out = "Error: Teamcity agent is unable to capture STDOUT: #{ex}"
  end

  begin
    new_err.close
    new_err.open
    s_err = new_err.readlines.join
    new_err.close
  rescue Exception => ex
    s_err = "Error: Teamcity agent is unable to capture STDERR: #{ex}"
  end

  return s_out, s_err
end

#isCaptureDisabledObject



28
29
30
# File 'lib/rspec/teamcity/utils/std_capture_helper.rb', line 28

def isCaptureDisabled()
  ENV[TEAMCITY_RAKERUNNER_LOG_OUTPUT_CAPTURER_ENABLED_KEY] != "true"
end

#reopen_stdout_stderr(sout, serr) ⇒ Object



55
56
57
58
59
# File 'lib/rspec/teamcity/utils/std_capture_helper.rb', line 55

def reopen_stdout_stderr(sout, serr)
  STDOUT.reopen(sout)
  STDERR.reopen(serr)
  nil
end