Class: RSpecTelemetry::FactoryComparison

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

Defined Under Namespace

Classes: Row

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FactoryComparison.



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

def initialize(before_path, after_path, all_depths: false, by_factory: false)
  @before_path = before_path
  @after_path = after_path
  @all_depths = all_depths
  @by_factory = by_factory
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

#by_factoryObject (readonly)

Returns the value of attribute by_factory.



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

def by_factory
  @by_factory
end

Instance Method Details

#duration_labelObject



50
51
52
# File 'lib/rspec_telemetry/factory_comparison.rb', line 50

def duration_label
  all_depths ? "Self(ms)" : "Total(ms)"
end

#rowsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rspec_telemetry/factory_comparison.rb', line 54

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

  (before.keys | after.keys).sort.map do |key|
    before_stat = before[key]
    after_stat = after[key]

    Row.new(
      label: key,
      before_count: before_stat&.count || 0,
      after_count: after_stat&.count || 0,
      before_duration_ms: duration_for(before_stat),
      after_duration_ms: duration_for(after_stat)
    )
  end
end