class RSpec::Core::Notifications::ProfileNotification

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.

@attr duration [Float] the time taken (in seconds) to run the suite @attr examples [Array<RSpec::Core::Example>] the examples run @attr number_of_examples [Fixnum] the number of examples to profile @attr example_groups [Array<RSpec::Core::Profiler>] example groups run

Attributes

Public Class Methods

# File rspec-core/lib/rspec/core/notifications.rb, line 430
def initialize(duration, examples, number_of_examples, example_groups)
  @duration = duration
  @examples = examples
  @number_of_examples = number_of_examples
  @example_groups = example_groups
end

Public Instance Methods

@return [String] the percentage of total time taken

# File rspec-core/lib/rspec/core/notifications.rb, line 455
def percentage
  @percentage ||=
    begin
      time_taken = slow_duration / duration
      '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
    end
end

@return [Float] the time taken (in seconds) to run the slowest examples

# File rspec-core/lib/rspec/core/notifications.rb, line 447
def slow_duration
  @slow_duration ||=
    slowest_examples.inject(0.0) do |i, e|
      i + e.execution_result.run_time
    end
end

@return [Array<RSpec::Core::Example>] the slowest examples

# File rspec-core/lib/rspec/core/notifications.rb, line 439
def slowest_examples
  @slowest_examples ||=
    examples.sort_by do |example|
      -example.execution_result.run_time
    end.first(number_of_examples)
end

@return [Array<RSpec::Core::Example>] the slowest example groups

# File rspec-core/lib/rspec/core/notifications.rb, line 464
def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end