Class: RSpecTelemetry::CompareCLI

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

Instance Method Summary collapse

Constructor Details

#initialize(argv, out: $stdout, err: $stderr) ⇒ CompareCLI

Returns a new instance of CompareCLI.



10
11
12
13
14
15
# File 'lib/rspec_telemetry/compare_cli.rb', line 10

def initialize(argv, out: $stdout, err: $stderr)
  @argv = argv
  @out = out
  @err = err
  @options = {all_depths: false, by_factory: false, sort: "duration"}
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rspec_telemetry/compare_cli.rb', line 17

def run
  paths = parse!
  unless paths.length == 2
    @err.puts("Specify exactly two telemetry files: BEFORE AFTER")
    return 1
  end

  comparison = FactoryComparison.new(
    paths[0], paths[1],
    all_depths: @options[:all_depths],
    by_factory: @options[:by_factory]
  )
  rows = sort_rows(comparison.rows)
  @out.puts(render(rows, duration_label: comparison.duration_label, label_heading: label_heading))
  0
rescue Errno::ENOENT => e
  @err.puts("File not found: #{e.message}")
  1
rescue OptionParser::ParseError => e
  @err.puts(e.message)
  1
end