Class: RSpecTelemetry::FactoryComparison

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_telemetry/factory_comparison.rb

Defined Under Namespace

Classes: FactoryStat, Row

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before_path, after_path, all_depths: false) ⇒ FactoryComparison

Returns a new instance of FactoryComparison.



43
44
45
46
47
# File 'lib/rspec_telemetry/factory_comparison.rb', line 43

def initialize(before_path, after_path, all_depths: false)
  @before_path = before_path
  @after_path = after_path
  @all_depths = all_depths
end

Instance Attribute Details

#after_pathObject (readonly)

Returns the value of attribute after_path.



41
42
43
# File 'lib/rspec_telemetry/factory_comparison.rb', line 41

def after_path
  @after_path
end

#all_depthsObject (readonly)

Returns the value of attribute all_depths.



41
42
43
# File 'lib/rspec_telemetry/factory_comparison.rb', line 41

def all_depths
  @all_depths
end

#before_pathObject (readonly)

Returns the value of attribute before_path.



41
42
43
# File 'lib/rspec_telemetry/factory_comparison.rb', line 41

def before_path
  @before_path
end

Instance Method Details

#rowsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rspec_telemetry/factory_comparison.rb', line 49

def rows
  before = aggregate(before_path)
  after = aggregate(after_path)

  (before.keys | after.keys).sort.map do |factory|
    before_stat = before.fetch(factory, empty_stat)
    after_stat = after.fetch(factory, empty_stat)

    Row.new(
      factory: factory,
      before_count: before_stat.count,
      after_count: after_stat.count,
      before_duration_ms: before_stat.duration_ms,
      after_duration_ms: after_stat.duration_ms
    )
  end
end