Class: TestProf::RSpecDissect::Collectors::Base

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

Direct Known Subclasses

Before, Let

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, top_count:) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
21
22
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 16

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 14

def name
  @name
end

#resultsObject (readonly)

Returns the value of attribute results.



14
15
16
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 14

def results
  @results
end

#top_countObject (readonly)

Returns the value of attribute top_count.



14
15
16
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 14

def top_count
  @top_count
end

Instance Method Details

#<<(data) ⇒ Object



28
29
30
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 28

def <<(data)
  results << data
end

#populate!(data) ⇒ Object



24
25
26
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 24

def populate!(data)
  data[name] = RSpecDissect.time_for(name)
end


52
53
54
55
56
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 52

def print_group_result(group)
  <<~GROUP
    #{group[:desc].truncate} (#{group[:loc]}) – #{group[name].duration} of #{group[:total].duration} (#{group[:count]})
  GROUP
end


40
41
42
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 40

def print_name
  name
end


44
45
46
47
48
49
50
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 44

def print_result_header
  <<~MSG

    Top #{top_count} slowest suites (by `#{print_name}` time):

  MSG
end


58
59
60
61
62
63
64
65
66
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 58

def print_results
  msgs = [print_result_header]

  results.each do |group|
    msgs << print_group_result(group)
  end

  msgs.join
end

#total_timeObject



32
33
34
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 32

def total_time
  RSpecDissect.total_time_for(name)
end

#total_time_messageObject



36
37
38
# File 'lib/test_prof/rspec_dissect/collectors/base.rb', line 36

def total_time_message
  "\nTotal `#{print_name}` time: #{total_time.duration}"
end