Module: Polyrun::Data::FactoryCounts

Defined in:
lib/polyrun/data/factory_counts.rb

Overview

Lightweight per-example factory/build counters with zero dependencies. Call reset! in before(:suite) or setup, record inside factory helpers, summary in after(:suite).

Class Method Summary collapse

Class Method Details

.countsObject



16
17
18
19
# File 'lib/polyrun/data/factory_counts.rb', line 16

def counts
  @counts ||= Hash.new(0)
  @counts.dup
end

.format_summary(title: "Polyrun factory counts") ⇒ Object



27
28
29
30
31
# File 'lib/polyrun/data/factory_counts.rb', line 27

def format_summary(title: "Polyrun factory counts")
  lines = [title]
  lines.concat(summary_lines)
  lines.join("\n") + "\n"
end

.record(factory_name) ⇒ Object



11
12
13
14
# File 'lib/polyrun/data/factory_counts.rb', line 11

def record(factory_name)
  @counts ||= Hash.new(0)
  @counts[factory_name.to_s] += 1
end

.reset!Object



7
8
9
# File 'lib/polyrun/data/factory_counts.rb', line 7

def reset!
  @counts = Hash.new(0)
end

.summary_lines(top: 20) ⇒ Object



21
22
23
24
25
# File 'lib/polyrun/data/factory_counts.rb', line 21

def summary_lines(top: 20)
  @counts ||= Hash.new(0)
  sorted = @counts.sort_by { |_, n| -n }
  sorted[0, top].map { |name, n| "  #{name}: #{n}" }
end