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

Inherits:
Object
  • Object
show all
Defined in:
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)

Constructor Details

- (ProfileNotification) initialize(duration, examples, number_of_examples, example_groups)

Returns a new instance of ProfileNotification

421
422
423
424
425
426
# File 'lib/rspec/core/notifications.rb', line 421
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

- (Float) duration

the time taken (in seconds) to run the suite

Returns:

  • (Float)

    the current value of duration

420
421
422
# File 'lib/rspec/core/notifications.rb', line 420
def duration
  @duration
end

- (Array<RSpec::Core::Profiler>) example_groups

example groups run

Returns:

  • (Array<RSpec::Core::Profiler>)

    the current value of example_groups

420
421
422
# File 'lib/rspec/core/notifications.rb', line 420
def example_groups
  @example_groups
end

- (Array<RSpec::Core::Example>) examples

the examples run

Returns:

420
421
422
# File 'lib/rspec/core/notifications.rb', line 420
def examples
  @examples
end

- (Fixnum) number_of_examples

the number of examples to profile

Returns:

  • (Fixnum)

    the current value of number_of_examples

420
421
422
# File 'lib/rspec/core/notifications.rb', line 420
def number_of_examples
  @number_of_examples
end

Instance Method Details

- (String) percentage

Returns the percentage of total time taken

Returns:

  • (String)

    the percentage of total time taken

446
447
448
449
450
451
452
# File 'lib/rspec/core/notifications.rb', line 446
def percentage
  @percentage ||=
    begin
      time_taken = slow_duration / duration
      '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
    end
end

- (Float) slow_duration

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

Returns:

  • (Float)

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

438
439
440
441
442
443
# File 'lib/rspec/core/notifications.rb', line 438
def slow_duration
  @slow_duration ||=
    slowest_examples.inject(0.0) do |i, e|
      i + e.execution_result.run_time
    end
end

- (Array<RSpec::Core::Example>) slowest_examples

Returns the slowest examples

Returns:

430
431
432
433
434
435
# File 'lib/rspec/core/notifications.rb', line 430
def slowest_examples
  @slowest_examples ||=
    examples.sort_by do |example|
      -example.execution_result.run_time
    end.first(number_of_examples)
end

- (Array<RSpec::Core::Example>) slowest_groups

Returns the slowest example groups

Returns:

455
456
457
# File 'lib/rspec/core/notifications.rb', line 455
def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end