Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML output #3

Open
wants to merge 1 commit into
base: make-the-gem-multijob
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]/dist/css/bootstrap.min.css' media='screen, projection, print' rel='stylesheet' type='text/css'>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/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>
7 changes: 5 additions & 2 deletions lib/tasks/failing_spec_detector/combine_log.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require_relative '../../failing_spec_detector/failure'
require_relative '../../failing_spec_detector/combiner'

namespace :failing_specs_detector do
desc 'Print all logs in console'
desc 'Combine logs and generate log files'
task :combine_log do
failures = []
exceptions = []
Expand All @@ -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
Loading