Class: RSpec::Core::Notifications::ProfileNotification

Inherits:
Struct
  • Object
show all
Defined in:
lib/rspec/core/notifications.rb,
lib/rspec/core/notifications.rb

Overview

The ProfileNotification holds information about the results of running a test suite when profiling is enabled. It is used by formatters to provide information at the end of the test run for profiling information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#durationFloat

the time taken (in seconds) to run the suite



552
553
554
# File 'lib/rspec/core/notifications.rb', line 552

def duration
  @duration
end

#examplesArray<RSpec::Core::Example>

the examples run



552
553
554
# File 'lib/rspec/core/notifications.rb', line 552

def examples
  @examples
end

#number_of_examplesFixnum

the number of examples to profile



552
553
554
# File 'lib/rspec/core/notifications.rb', line 552

def number_of_examples
  @number_of_examples
end

Instance Method Details

#percentageString



571
572
573
574
575
576
577
# File 'lib/rspec/core/notifications.rb', line 571

def percentage
  @percentage ||=
    begin
      time_taken = slow_duration / duration
      '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
    end
end

#slow_durationFloat



563
564
565
566
567
568
# File 'lib/rspec/core/notifications.rb', line 563

def slow_duration
  @slow_duration ||=
    slowest_examples.inject(0.0) do |i, e|
      i + e.execution_result.run_time
    end
end

#slowest_examplesArray<RSpec::Core::Example>



555
556
557
558
559
560
# File 'lib/rspec/core/notifications.rb', line 555

def slowest_examples
  @slowest_examples ||=
    examples.sort_by do |example|
      -example.execution_result.run_time
    end.first(number_of_examples)
end

#slowest_groupsArray<RSpec::Core::Example>



580
581
582
# File 'lib/rspec/core/notifications.rb', line 580

def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end