Class: Kumi::Dev::Golden::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/dev/golden/reporter.rb

Instance Method Summary collapse

Instance Method Details

#report_diff(results_by_schema) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/kumi/dev/golden/reporter.rb', line 79

def report_diff(results_by_schema)
  results_by_schema.each do |schema_name, results|
    results.each do |result|
      next unless result.failed? && result.diff

      puts "=== #{schema_name}/#{result.representation}.* ==="
      puts result.diff
      puts
    end
  end
end

#report_runtime_tests(results_by_language) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/kumi/dev/golden/reporter.rb', line 91

def report_runtime_tests(results_by_language)
  success = true

  # Organize results by schema
  results_by_schema = {}
  results_by_language.each do |language, schema_results|
    schema_results.each do |result|
      results_by_schema[result.schema_name] ||= {}
      results_by_schema[result.schema_name][language] = result
    end
  end

  # Report failures first
  failed_schemas = results_by_schema.select do |_, lang_results|
    lang_results.values.any? { |r| r.error || !r.passed? }
  end

  if failed_schemas.any?
    puts "Failures:"
    failed_schemas.each do |schema_name, lang_results|
      lang_results.each do |language, result|
        if result.error
          puts "  ✗ #{schema_name} [#{language}]: #{result.error}"
          success = false
        elsif !result.passed?
          puts "  ✗ #{schema_name} [#{language}]: #{result.passed_count}/#{result.total_count} passed"
          success = false

          result.test_results.select(&:failed?).each do |test|
            puts "      #{test.decl_name}: got #{test.actual.inspect}, expected #{test.expected.inspect}"
          end
        end
      end
    end
    puts
  end

  # Print summary
  print_combined_summary(results_by_language)

  success
end

#report_update(results_by_schema) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kumi/dev/golden/reporter.rb', line 7

def report_update(results_by_schema)
  changed_any = false
  changed_schemas = []
  errors = []

  results_by_schema.each do |schema_name, results|
    schema_changed = false

    results.each do |result|
      if result.changed?
        puts "  #{schema_name}/#{result.representation}.* (#{result.status})"
        schema_changed = true
        changed_any = true
      elsif result.error?
        errors << "  ✗ #{schema_name}/#{result.representation} (error: #{result.error})"
      end
    end

    changed_schemas << schema_name if schema_changed
  end

  if errors.any?
    puts
    errors.each { |e| puts e }
  end

  if changed_any
    puts
    puts "Updated #{changed_schemas.size} schema(s)"
  else
    puts "All schemas up to date"
  end
end

#report_verify(results_by_schema) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kumi/dev/golden/reporter.rb', line 41

def report_verify(results_by_schema)
  success = true
  results_presented = false

  results_by_schema.each do |schema_name, results|
    failed_reprs = results.select { |r| !r.passed? }

    if failed_reprs.empty?
      puts "✓ #{schema_name}"
      results_presented = true
    else
      success = false
      failed_msgs = failed_reprs.map do |r|
        case r.status
        when :missing_expected
          "#{r.representation}.* (no expected file)"
        when :missing_actual
          "#{r.representation}.* (no actual file)"
        when :error
          "#{r.representation}.* (error: #{r.error})"
        else
          "#{r.representation}.*"
        end
      end
      puts "✗ #{schema_name} (#{failed_msgs.join(', ')})"
      results_presented = true
    end
  end

  # If nothing was shown, report that results were empty
  unless results_presented
    puts "⚠ No test results to report - check that schema files exist"
    success = false
  end

  success
end