123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Inherits: Object
Defined in: rspec-core/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.

Class Method Summary

Instance Attribute Summary

  • #duration rw

    The ProfileNotification holds information about the results of running a test suite when profiling is enabled.

  • #example_groups rw

    The ProfileNotification holds information about the results of running a test suite when profiling is enabled.

  • #examples rw

    The ProfileNotification holds information about the results of running a test suite when profiling is enabled.

  • #number_of_examples rw

    The ProfileNotification holds information about the results of running a test suite when profiling is enabled.

Instance Method Summary

Constructor Details

.new(duration, examples, number_of_examples, example_groups) ⇒ ProfileNotification

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 432

def initialize(duration, examples, number_of_examples, example_groups)
  @duration = duration
  @examples = examples
  @number_of_examples = number_of_examples
  @example_groups = example_groups
end

Instance Attribute Details

#duration (rw)

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.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 431

class ProfileNotification
def initialize(duration, examples, number_of_examples, example_groups)

#example_groups (rw)

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.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 431

class ProfileNotification
def initialize(duration, examples, number_of_examples, example_groups)

#examples (rw)

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.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 431

class ProfileNotification
def initialize(duration, examples, number_of_examples, example_groups)

#number_of_examples (rw)

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.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 431

class ProfileNotification
def initialize(duration, examples, number_of_examples, example_groups)

Instance Method Details

#calculate_slowest_groups (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 472

def calculate_slowest_groups
  # stop if we've only one example group
  return {} if @example_groups.keys.length <= 1

  @example_groups.each_value do |hash|
    hash[:average] = hash[:total_time].to_f / hash[:count]
  end

  groups = @example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
  groups.map { |group, data| [group.location, data] }
end

#percentageString

Returns:

  • (String)

    the percentage of total time taken

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 457

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

#slow_durationFloat

Returns:

  • (Float)

    the time taken (in seconds) to run the slowest examples

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 449

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>

Returns:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 441

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>

Returns:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 466

def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end