Class: Minitest::HTMLReporter
- Inherits:
-
AbstractReporter
- Object
- AbstractReporter
- Minitest::HTMLReporter
- Defined in:
- lib/minitest/html_plugin.rb
Overview
Custom reporter class that creates an HTML file in the docs folder
Constant Summary collapse
- DOCS_DIR =
"#{__dir__}/../../docs/asciidoc".freeze
- TESTS_DIR =
"#{__dir__}/../../test/asciidoctor/html".freeze
Instance Method Summary collapse
- #display_failure(failure) ⇒ Object
- #display_result(name, adoc) ⇒ Object
- #display_result_title(name, failed, color) ⇒ Object
-
#initialize ⇒ HTMLReporter
constructor
A new instance of HTMLReporter.
- #record(result) ⇒ Object
- #report ⇒ Object
- #report_files(results, dirname) ⇒ Object
Constructor Details
#initialize ⇒ HTMLReporter
Returns a new instance of HTMLReporter.
13 14 15 16 |
# File 'lib/minitest/html_plugin.rb', line 13 def initialize @results = {} super end |
Instance Method Details
#display_failure(failure) ⇒ Object
22 23 24 |
# File 'lib/minitest/html_plugin.rb', line 22 def display_failure(failure) %([source,shell,role="text-bg-danger"]\n----\n#{failure}\n----\n) end |
#display_result(name, adoc) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/minitest/html_plugin.rb', line 31 def display_result(name, adoc) key = "test_#{name}" failed = @results[key]&.size&.positive? color = failed ? "danger" : "success" id = "test-#{name.tr "_", "-"}" title = display_result_title name, failed, color pre = %([live=normal-faded,asciidoc]\n------\n#{adoc}\n------\n) fail = failed ? display_failure(@results[key].join("\n")) : "" %([##{id}.flex-grow-1]\n== #{title}\n\n#{pre}#{fail}\n\n#{adoc}\n\n) end |
#display_result_title(name, failed, color) ⇒ Object
26 27 28 29 |
# File 'lib/minitest/html_plugin.rb', line 26 def display_result_title(name, failed, color) status_icon = %(pass:[<i class="bi bi-#{failed ? "x" : "check"}-lg text-#{color}"></i>]) %(#{status_icon} #{name.tr("_", " ").capitalize}) end |
#record(result) ⇒ Object
18 19 20 |
# File 'lib/minitest/html_plugin.rb', line 18 def record(result) @results[result.name] = result.failures end |
#report ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/minitest/html_plugin.rb', line 51 def report time = %([.lead]\n#{Time.now.strftime("%d/%m/%Y %H:%M")}\n) results = [] Pathname(TESTS_DIR).children.reject { |f| f.file? || f.basename.to_s.start_with?("_") }.sort.each do |pn| report_files results, pn end adoc = %(= Test Results\n:pagestyle: multi\n\n#{time}\n\nsubnav::[border=1]\n\n#{results.join "\n"}) File.write("#{DOCS_DIR}/tests.adoc", adoc) end |
#report_files(results, dirname) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/minitest/html_plugin.rb', line 42 def report_files(results, dirname) dirname.children.sort.each do |filepath| next unless filepath.extname == ".adoc" results << display_result(filepath.basename.sub_ext("").to_s, File.read(filepath)) end end |