Class: SnapDiff::Reporters::HTML
- Inherits:
-
Object
- Object
- SnapDiff::Reporters::HTML
- Defined in:
- lib/snap_diff/reporters/html.rb
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#dump_state ⇒ Object
Fork-parallel handoff (issue #258).
- #failed ⇒ Object
- #finalize ⇒ Object
-
#initialize(output_path: nil, embed_images: false) ⇒ HTML
constructor
A new instance of HTML.
- #merge_state!(state) ⇒ Object
- #output_path ⇒ Object
- #passed ⇒ Object
- #record(assertions) ⇒ Object
- #render ⇒ Object
-
#summary ⇒ String?
Both customer personas named this path as the best output in the product, so it gets its own line -- but only when a report was actually written.
Constructor Details
#initialize(output_path: nil, embed_images: false) ⇒ HTML
Returns a new instance of HTML.
18 19 20 21 22 23 24 25 |
# File 'lib/snap_diff/reporters/html.rb', line 18 def initialize(output_path: nil, embed_images: false) @explicit_output_path = output_path @embed_images = @failures = [] @total = 0 @finalized = false @mutex = Mutex.new end |
Instance Attribute Details
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
16 17 18 |
# File 'lib/snap_diff/reporters/html.rb', line 16 def failures @failures end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
16 17 18 |
# File 'lib/snap_diff/reporters/html.rb', line 16 def total @total end |
Class Method Details
.default_output_path ⇒ Object
107 108 109 110 |
# File 'lib/snap_diff/reporters/html.rb', line 107 def self.default_output_path root = SnapDiff.config.root || Pathname.pwd root / SnapDiff.config.save_path / "snap_diff_report.html" end |
.template_path ⇒ Object
103 104 105 |
# File 'lib/snap_diff/reporters/html.rb', line 103 def self.template_path File.("templates/report.html.erb", __dir__) end |
Instance Method Details
#dump_state ⇒ Object
Fork-parallel handoff (issue #258). A forked worker never reaches
Minitest.after_run, so it hands its records to the parent as
plain data instead. JSON on purpose -- boring, and a half-written
file is discarded rather than half-read. Image paths were resolved
against output_path, which is the same in both processes.
72 73 74 |
# File 'lib/snap_diff/reporters/html.rb', line 72 def dump_state @mutex.synchronize { {"total" => @total, "failures" => @failures} } end |
#failed ⇒ Object
84 |
# File 'lib/snap_diff/reporters/html.rb', line 84 def failed = failures.size |
#finalize ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/snap_diff/reporters/html.rb', line 52 def finalize @mutex.synchronize do return if @finalized return if failures.empty? write_report @finalized = true output_path end end |
#merge_state!(state) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/snap_diff/reporters/html.rb', line 76 def merge_state!(state) @mutex.synchronize do @total += state["total"] @failures.concat(state["failures"].map { |entry| entry.transform_keys(&:to_sym) }) end end |
#output_path ⇒ Object
63 64 65 |
# File 'lib/snap_diff/reporters/html.rb', line 63 def output_path @output_path ||= Pathname.new(@explicit_output_path || self.class.default_output_path) end |
#passed ⇒ Object
83 |
# File 'lib/snap_diff/reporters/html.rb', line 83 def passed = total - failures.size |
#record(assertions) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/snap_diff/reporters/html.rb', line 27 def record(assertions) return if @finalized failures = [] total = 0 assertions.each do |assertion| compare = assertion.compare next unless compare total += 1 next unless compare.difference&.different? failures << failure_entry_for(assertion.name, compare) rescue => e warn "[snap_diff] Reporter skipped '#{assertion.name}': #{e.}" if ENV["DEBUG"] end @mutex.synchronize do return if @finalized @total += total @failures.concat(failures) end end |
#render ⇒ Object
99 100 101 |
# File 'lib/snap_diff/reporters/html.rb', line 99 def render ERB.new(File.read(self.class.template_path)).result(binding) end |
#summary ⇒ String?
Both customer personas named this path as the best output in the product, so it gets its own line -- but only when a report was actually written.
The counts this used to carry moved to SnapDiff::Reporting (issue #269): they are printed for every user, and this file is not. See Reporting.counts_summary.
95 96 97 |
# File 'lib/snap_diff/reporters/html.rb', line 95 def summary "[snap_diff] Report: #{output_path}" if @finalized end |