Module: SeeingIsBelieving::Binary::AnnotateEndOfFile

Extended by:
AnnotateEndOfFile
Included in:
AnnotateEndOfFile
Defined in:
lib/seeing_is_believing/binary/annotate_end_of_file.rb

Instance Method Summary collapse

Instance Method Details

#add_stdout_stderr_and_exceptions_to(new_body, results, options) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/seeing_is_believing/binary/annotate_end_of_file.rb', line 9

def add_stdout_stderr_and_exceptions_to(new_body, results, options)
  output = stdout_ouptut_for(results, options)    <<
           stderr_ouptut_for(results, options)    <<
           exception_output_for(results, options)

  code = Code.new(new_body)
  code.rewriter.insert_after code.body_range, output
  new_body.replace code.rewriter.process
end

#exception_output_for(results, options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/seeing_is_believing/binary/annotate_end_of_file.rb', line 37

def exception_output_for(results, options)
  return '' unless results.has_exception?
  exception_marker = options[:markers][:exception][:prefix]
  output = ""
  results.exceptions.each do |exception|
    output << "\n"
    output << FormatComment.new(0, exception_marker, exception.class_name, options).call << "\n"
    exception.message.each_line do |line|
      output << FormatComment.new(0, exception_marker, line.chomp, options).call << "\n"
    end
    output << exception_marker.sub(/\s+$/, '') << "\n"
    exception.backtrace.each do |line|
      output << FormatComment.new(0, exception_marker, line.chomp, options).call << "\n"
    end
  end
  output
end

#stderr_ouptut_for(results, options) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/seeing_is_believing/binary/annotate_end_of_file.rb', line 28

def stderr_ouptut_for(results, options)
  return '' unless results.has_stderr?
  output = "\n"
  results.stderr.each_line do |line|
    output << FormatComment.call(0, options[:markers][:stderr][:prefix], line.chomp, options) << "\n"
  end
  output
end

#stdout_ouptut_for(results, options) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/seeing_is_believing/binary/annotate_end_of_file.rb', line 19

def stdout_ouptut_for(results, options)
  return '' unless results.has_stdout?
  output = "\n"
  results.stdout.each_line do |line|
    output << FormatComment.call(0, options[:markers][:stdout][:prefix], line.chomp, options) << "\n"
  end
  output
end