Module: HTMLReport

Included in:
CapybaraHtmlFormatter, CustomParallelHtmlFormatter
Defined in:
lib/sim/html_report.rb

Instance Method Summary collapse

Instance Method Details

#example_failed_helper(example, output_buffer) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sim/html_report.rb', line 20

def example_failed_helper(example, output_buffer)
  move_tmp_to_final(example)
  unless @header_red
    @header_red = true
    @printer.make_header_red
  end

  unless @example_group_red
    @example_group_red = true
    @printer.make_example_group_header_red(example_group_number)
  end

  @printer.move_progress(percent_done)

  exception = example.[:execution_result][:exception]
  exception_details = if exception
  {
    :class => exception.class.to_s,
    :message => exception.message,
    :backtrace => format_backtrace(exception.backtrace, example).join("\n")
  }
  else
    false
  end
  extra = extra_failure_content(exception)

  pending_fixed = example.execution_result[:pending_fixed]
  description = example.description
  run_time = example.execution_result[:run_time]
  failure_id = @failed_examples.size
  exception = exception_details
  extra_content = (extra == "") ? false : extra
  escape_backtrace = true
  formatted_run_time = sprintf("%.5f", run_time)

  output_buffer.puts "    <dd class=\"example #{pending_fixed ? 'pending_fixed' : 'failed'}\">"
  output_buffer.puts "      <span class=\"failed_spec_name\">#{h(description)}</span>"
  output_buffer.puts "      <span class=\"duration\">#{formatted_run_time}s</span>"
  output_buffer.puts "      <div class=\"failure\" id=\"failure_#{failure_id}\">"
  if exception
    output_buffer.puts "        <div class=\"class\"><pre>#{h(exception[:class])}</pre></div>"
    output_buffer.puts "        <div class=\"message\"><pre>#{h(exception[:message])}</pre></div>"
    if escape_backtrace
      output_buffer.puts "        <div class=\"backtrace\"><pre>#{h exception[:backtrace]}</pre></div>"
    else
      output_buffer.puts "        <div class=\"backtrace\"><pre>#{exception[:backtrace]}</pre></div>"
    end
  end
  output_buffer.puts extra_content if extra_content
  output_buffer.puts "      </div>"

  output_buffer.puts "<div class=\"rerun_command\">bundle exec rspec " + example.[:file_path] + ":" + example.[:line_number].to_s + $local_run_args + "</div>"
  output_buffer.puts "<div class=\"screenshots\">"
  output_buffer.puts "</div>"
  print_screenshot(example)
  output_buffer.puts "    </dd>"
end

#example_passed_helper(example, output_buffer) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sim/html_report.rb', line 4

def example_passed_helper(example, output_buffer)
  move_tmp_to_final(example)
  @printer.move_progress(percent_done)

  description = example.[:description_args].join('')
  run_time = example.execution_result[:run_time]
  formatted_run_time = sprintf("%.5f", run_time)
  output_buffer.puts "    <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(description)}</span><span class='duration'>#{formatted_run_time}s</span>"

  output_buffer.puts "<div class=\"screenshots\">"
  print_screenshot(example)
  output_buffer.puts "</div>"

  output_buffer.puts "</dd>"
end

#move_tmp_to_final(example) ⇒ Object



113
114
115
116
117
# File 'lib/sim/html_report.rb', line 113

def move_tmp_to_final(example)
  if path_to_tmp(example) != path_to_screenshot(example)
      FileUtils.mv(path_to_tmp(example), path_to_screenshot(example))
    end
end


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/sim/html_report.rb', line 78

def print_screenshot_helper(example, output_buffer)
  file_count = Dir[File.join(example.[:screenshot_path], '*.html')].count
  max_columns = 8
  curr_column = 0

  if file_count > 0 then output_buffer.puts "<table>" end

  Dir[File.join(example.[:screenshot_path], '*.html')].sort_by{|filename| filename }.each do |path|
    if curr_column == 0 then output_buffer.puts "<tr>" end
    output_buffer.puts "  <td>"

    path_to_html = Pathname.new(path).relative_path_from(Pathname.new(@output_dir))
    file_name_no_extension = File.basename(path_to_html.basename, '.*')
    directory = Pathname.new(path).dirname
    relative_path_to_img = File.join(path_to_html.dirname, file_name_no_extension) + '.png'
    absolute_path_to_img = File.join(directory, file_name_no_extension) + '.png'
    
    if File.file?(absolute_path_to_img)
      output_buffer.puts "    <a href=\"#{relative_path_to_img}\" style=\"text-decoration: none;\">"
      output_buffer.puts "      <img src=\"#{relative_path_to_img}\" alt=\"#{item}\" height=\"100\" width=\"100\">"
      output_buffer.puts "    </a>"
      output_buffer.puts "    </br>"
    end
    output_buffer.puts "    <a href=\"#{path_to_html}\" style=\"text-decoration: none;\">"
    output_buffer.puts "      <pre align=\"center\">#{dealphabetize_names(File.basename(path, '.*'))}</pre>"
    output_buffer.puts "    </a>"
    output_buffer.puts "  </td>"
    if curr_column == (max_columns - 1) then output_buffer.puts "</tr>" end
    curr_column = (curr_column + 1) % (max_columns - 1)
  end

  if (curr_column != 0) then output_buffer.puts("</tr>") end
  if (file_count > 0) then output_buffer.puts("</table>") end
end