Class: TestProf::RSpecDissect::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/rspec_dissect/collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top_count:) ⇒ Collector

Returns a new instance of Collector.



15
16
17
18
19
20
# File 'lib/test_prof/rspec_dissect/collector.rb', line 15

def initialize(top_count:)
  @top_count = top_count
  @results = Utils::SizedOrderedSet.new(
    top_count, sort_by: :total_setup
  )
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/test_prof/rspec_dissect/collector.rb', line 13

def name
  @name
end

#resultsObject (readonly)

Returns the value of attribute results.



13
14
15
# File 'lib/test_prof/rspec_dissect/collector.rb', line 13

def results
  @results
end

#top_countObject (readonly)

Returns the value of attribute top_count.



13
14
15
# File 'lib/test_prof/rspec_dissect/collector.rb', line 13

def top_count
  @top_count
end

Instance Method Details

#<<(data) ⇒ Object



22
23
24
# File 'lib/test_prof/rspec_dissect/collector.rb', line 22

def <<(data)
  results << data
end


34
35
36
37
38
39
40
# File 'lib/test_prof/rspec_dissect/collector.rb', line 34

def print_group_result(group)
  "#{group[:desc].truncate} (#{group[:loc]}) – \e[1m#{group[:total_setup].duration}\e[22m " \
  "of #{group[:total].duration} / #{group[:count]} " \
  "(before: #{(group[:total_setup] - group[:total_lazy_let]).duration}, " \
  "before let: #{group[:total_before_let].duration}, " \
  "lazy let: #{group[:total_lazy_let].duration})"
end


26
27
28
29
30
31
32
# File 'lib/test_prof/rspec_dissect/collector.rb', line 26

def print_result_header
  <<~MSG

    Top #{top_count} slowest suites by setup time:

  MSG
end


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/test_prof/rspec_dissect/collector.rb', line 42

def print_results
  msgs = [print_result_header]

  results.each do |group|
    msgs << print_group_result(group)
    msgs << "\n" if group[:top_lets].any?
    group[:top_lets].each do |let|
      msgs << "#{let[:name]}#{let[:duration].duration} (#{let[:size]})\n"
    end
    msgs << "\n"
  end

  msgs.join
end