From 881be2ecbce849e6dc0290c0053b6ddf59a576c8 Mon Sep 17 00:00:00 2001 From: safa Date: Tue, 30 Jan 2024 14:55:31 +0100 Subject: [PATCH] Add HTML output --- .gitignore | 2 +- lib/failing_spec_detector/combiner.rb | 10 ++++++ lib/failing_spec_detector/views/template.erb | 34 +++++++++++++++++++ .../failing_spec_detector/combine_log.rake | 7 ++-- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 lib/failing_spec_detector/views/template.erb diff --git a/.gitignore b/.gitignore index c7f5bff..458bd9e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ # log files exceptions_log_*.yml failures_log_*.yml -failing_specs_detector_log.txt +failing_specs_detector_log.* diff --git a/lib/failing_spec_detector/combiner.rb b/lib/failing_spec_detector/combiner.rb index ecbbe0f..713956e 100644 --- a/lib/failing_spec_detector/combiner.rb +++ b/lib/failing_spec_detector/combiner.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'erb' + module FailingSpecDetector # Combiner class to combine and group the failures by exception class Combiner @@ -7,6 +9,7 @@ def initialize(exceptions, failures) @exceptions = exceptions @failures = failures @filename = 'failing_specs_detector_log.txt' + @html_filename = 'failing_specs_detector_log.html' end def combine @@ -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 diff --git a/lib/failing_spec_detector/views/template.erb b/lib/failing_spec_detector/views/template.erb new file mode 100644 index 0000000..f6c0f96 --- /dev/null +++ b/lib/failing_spec_detector/views/template.erb @@ -0,0 +1,34 @@ + + + + Failing spec detector + + + + + +
+
+ <% @exceptions.uniq.each_with_index do |exception, index| %> +
+

+ +

+
+
+
    + <% related_examples = @failures.select { |failure| failure.exception == exception } %> + <% related_examples.each do |failure| %> +
  • <%= failure.backtrace %>
  • + <% end %> +
+
+
+
+ <% end %> +
+
+ + diff --git a/lib/tasks/failing_spec_detector/combine_log.rake b/lib/tasks/failing_spec_detector/combine_log.rake index 31cc7e0..2d8ce11 100644 --- a/lib/tasks/failing_spec_detector/combine_log.rake +++ b/lib/tasks/failing_spec_detector/combine_log.rake @@ -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 = [] @@ -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