Skip to content

Commit

Permalink
Add HTML output
Browse files Browse the repository at this point in the history
  • Loading branch information
safafa committed Jan 30, 2024
1 parent f44625a commit ddd4356
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# log files
exceptions_log_*.yml
failures_log_*.yml
failing_specs_detector_log.txt
failing_specs_detector_log.*
10 changes: 10 additions & 0 deletions lib/failing_spec_detector/combiner.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# frozen_string_literal: true

require 'erb'

module FailingSpecDetector
# Combiner class to combine and group the failures by exception
class Combiner
def initialize(exceptions, failures)
@exceptions = exceptions
@failures = failures
@filename = 'failing_specs_detector_log.txt'
@html_filename = 'failing_specs_detector_log.html'
end

def combine
Expand All @@ -25,5 +28,12 @@ def combine
end
File.write(@filename, '----------------------------------------------------------------', mode: 'a')
end

def combine_html
return if @exceptions.empty?

template = ERB.new(File.read(File.join(File.dirname(__FILE__), 'views', 'template.erb')))
File.write(@html_filename, template.result(binding))
end
end
end
34 changes: 34 additions & 0 deletions lib/failing_spec_detector/views/template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Failing spec detector </title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css' media='screen, projection, print' rel='stylesheet' type='text/css'>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js'></script>
</head>
<body>
<div class= "w-100 position-relative my-3">
<div class="accordion w-75 position-absolute top-10 start-50 translate-middle-x" id="accordionPanelsStayOpenExample">
<% @exceptions.uniq.each_with_index do |exception, index| %>
<div class="accordion-item">
<h2 class="accordion-heade">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-<%= index %>" aria-expanded="true" aria-controls="panelsStayOpen-collapseOne">
<%= exception %>
</button>
</h2>
<div id="panelsStayOpen-<%= index %>" class="accordion-collapse collapse show">
<div class="accordion-body">
<ul class="list-group list-group-flush">
<% related_examples = @failures.select { |failure| failure.exception == exception } %>
<% related_examples.each do |failure| %>
<li class="list-group-item"><%= failure.backtrace %></li>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
</div>
</div>
</body>
</html>
5 changes: 4 additions & 1 deletion lib/tasks/failing_spec_detector/combine_log.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace :failing_specs_detector do
File.delete(file_path)
end

FailingSpecDetector::Combiner.new(exceptions, failures).combine
combiner = FailingSpecDetector::Combiner.new(exceptions, failures)

combiner.combine_html
combiner.combine
end
end

0 comments on commit ddd4356

Please sign in to comment.