Class: Ace::TestRunner::Organisms::ReportGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/test_runner/organisms/report_generator.rb

Overview

Generates comprehensive test reports

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ ReportGenerator

Returns a new instance of ReportGenerator.



8
9
10
11
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 8

def initialize(configuration)
  @configuration = configuration
  @formatter = configuration.formatter_class.new(configuration.to_h)
end

Instance Method Details

#generate(result, files_tested) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 13

def generate(result, files_tested)
  report = Models::TestReport.new(
    result: result,
    configuration: @configuration,
    timestamp: Time.now,
    files_tested: files_tested,
    metadata: 
  )

  # Let formatter enhance the report if needed
  if @formatter.respond_to?(:enhance_report)
    @formatter.enhance_report(report)
  end

  report
end

#generate_deprecation_report(deprecations) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 54

def generate_deprecation_report(deprecations)
  return nil if deprecations.empty?

  fixer = Molecules::DeprecationFixer.new
  fixes = deprecations.map do |deprecation|
    fixer.fix_deprecations_in_output(deprecation)
  end.flatten

  {
    count: deprecations.size,
    warnings: deprecations,
    suggested_fixes: fixes
  }
end

#generate_failure_report(failures) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 43

def generate_failure_report(failures)
  return nil if failures.empty?

  {
    count: failures.size,
    by_type: group_failures_by_type(failures),
    by_file: group_failures_by_file(failures),
    details: failures.map(&:to_h)
  }
end

#generate_performance_report(result) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 69

def generate_performance_report(result)
  {
    total_duration: result.duration,
    average_per_test: (result.total_tests > 0) ? result.duration / result.total_tests : 0,
    tests_per_second: (result.duration > 0) ? result.total_tests / result.duration : 0,
    assertions_per_second: (result.duration > 0) ? result.assertions / result.duration : 0
  }
end

#generate_recommendations(result) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 78

def generate_recommendations(result)
  recommendations = []

  # Performance recommendations
  if result.duration > 60
    recommendations << {
      type: "performance",
      message: "Tests took over a minute. Consider using --parallel or optimizing slow tests."
    }
  end

  # Failure rate recommendations
  if result.pass_rate < 50
    recommendations << {
      type: "quality",
      message: "Less than 50% of tests passing. Focus on fixing critical failures first."
    }
  end

  # Skip recommendations
  if result.skipped > result.total_tests * 0.2
    recommendations << {
      type: "coverage",
      message: "Over 20% of tests are skipped. Review and enable skipped tests."
    }
  end

  # Deprecation recommendations
  if result.has_deprecations?
    recommendations << {
      type: "maintenance",
      message: "Deprecation warnings detected. Run with --fix-deprecations to auto-fix."
    }
  end

  recommendations
end

#generate_summary(result) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/test_runner/organisms/report_generator.rb', line 30

def generate_summary(result)
  {
    total_tests: result.total_tests,
    passed: result.passed,
    failed: result.failed,
    errors: result.errors,
    skipped: result.skipped,
    pass_rate: result.pass_rate,
    duration: result.duration,
    success: result.success?
  }
end