Class: ImageDiff::Differ::Results::Output

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/image_diff/differ/results/output.rb

Overview

Decorator for Results hash

Constant Summary collapse

CURRENT_DIR =
File.dirname(__FILE__)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOutput

Returns a new instance of Output.



11
12
13
14
15
# File 'lib/image_diff/differ/results/output.rb', line 11

def initialize
  super(List.instance)
  @regressions = regressions
  @reference_errors = reference_errors
end

Class Method Details

.clearObject



48
49
50
# File 'lib/image_diff/differ/results/output.rb', line 48

def self.clear
  List.instance.clear
end

.flushObject



52
53
54
55
56
# File 'lib/image_diff/differ/results/output.rb', line 52

def self.flush
  return if List.instance.empty?

  new.out
end

Instance Method Details

#outObject



17
18
19
20
# File 'lib/image_diff/differ/results/output.rb', line 17

def out
  render_reference_errors
  render_regression_errors
end

#render_reference_errorsObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/image_diff/differ/results/output.rb', line 22

def render_reference_errors
  print_str = String.new ''
  unless @reference_errors.empty?
    @reference_errors.map do |component, failures|
      print_str << "The following reference files were not found, you need to generate screenshots before comparing...\n"
      failures.each do |failure|
        print_str << "\033[31m#{failure.snapshot.filename}\033[0m\n"
      end
    end
  end
  print print_str
end

#render_regression_errorsObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/image_diff/differ/results/output.rb', line 35

def render_regression_errors
  print_str = String.new ''
  unless @regressions.empty?
    @regressions.map do |component, failures|
      print_str << "The following screenshots are different from the comparison image, if this expected then regenerate comparison images...\n"
      failures.each do |failure|
        print_str << "\033[31m#{failure.output}\033[0m\n"
      end
    end
  end
  print print_str
end