Class: RspecSprint::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_sprint/normalizer.rb

Overview

Turns raw profiler JSON (rspec’s JSON formatter + test-prof’s FactoryProf JSON) into one normalized Snapshot. Input is FILE PATHS (decoupled from the live run) so golden fixtures and a future artifact-ingest mode feed the same code (design doc D3).

Defined Under Namespace

Classes: Example, Factory, Snapshot

Instance Method Summary collapse

Constructor Details

#initialize(rspec_json:, factory_prof_json: nil) ⇒ Normalizer

Returns a new instance of Normalizer.



57
58
59
60
# File 'lib/rspec_sprint/normalizer.rb', line 57

def initialize(rspec_json:, factory_prof_json: nil)
  @rspec_json = rspec_json
  @factory_prof_json = factory_prof_json
end

Instance Method Details

#callObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rspec_sprint/normalizer.rb', line 62

def call
  rspec = JSON.parse(File.read(@rspec_json))
  summary = rspec.fetch("summary", {})
  Snapshot.new(
    suite_duration: summary.fetch("duration"),
    factory_time: top_level_factory_time,
    factories: build_factories,
    examples: build_examples(rspec.fetch("examples", [])),
    example_count: summary.fetch("example_count", 0),
    failure_count: summary.fetch("failure_count", 0)
  )
end