Module: RSpecTelemetry::SummaryPrinter
- Defined in:
- lib/rspec_telemetry/summary.rb
Class Method Summary collapse
- .example_section(summary, _config) ⇒ Object
- .factory_section(summary, _config) ⇒ Object
- .print(summary, config, io = config.summary_io) ⇒ Object
- .round(value) ⇒ Object
Class Method Details
.example_section(summary, _config) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rspec_telemetry/summary.rb', line 115 def example_section(summary, _config) slow = summary.slow_examples return [] if slow.empty? lines = ["Slow examples:", ""] slow.each_with_index do |e, i| lines << "#{i + 1}. #{e.example_id}" lines << " duration: #{round(e.duration_ms)}ms" lines << " factory_bot_total: #{round(e.factory_bot_total_ms)}ms (#{e.factory_bot_count} calls)" lines << "" end lines end |
.factory_section(summary, _config) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rspec_telemetry/summary.rb', line 97 def factory_section(summary, _config) tops = summary.top_factories return [] if tops.empty? lines = ["FactoryBot telemetry summary", "", "Top factories by self time (子factoryを除く):", ""] tops.each_with_index do |f, i| lines << "#{i + 1}. #{f.key}" lines << " count: #{f.count}" lines << " self_total: #{round(f.self_total_ms)}ms" lines << " total: #{round(f.total_ms)}ms" lines << " avg: #{round(f.avg_ms)}ms" lines << " max: #{round(f.max_ms)}ms" lines << "" end lines end |
.print(summary, config, io = config.summary_io) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rspec_telemetry/summary.rb', line 83 def print(summary, config, io = config.summary_io) return unless config.print_summary lines = [] lines.concat(factory_section(summary, config)) lines.concat(example_section(summary, config)) return if lines.empty? io.puts io.puts(lines.join("\n")) rescue => e warn("[rspec-telemetry] failed to print summary: #{e.class}: #{e.}") end |
.round(value) ⇒ Object
130 131 132 |
# File 'lib/rspec_telemetry/summary.rb', line 130 def round(value) value.to_f.round(1) end |