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

#initialize(duration, examples, number_of_examples, example_groups) ⇒ ProfileNotification



432
433
434
435
436
437
# File '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

#durationFloat

the time taken (in seconds) to run the suite



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

def duration
  @duration
end

#example_groupsArray<RSpec::Core::Profiler>

example groups run



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

def example_groups
  @example_groups
end

#examplesArray<RSpec::Core::Example>

the examples run



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

def examples
  @examples
end

#number_of_examplesFixnum

the number of examples to profile



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

def number_of_examples
  @number_of_examples
end

Instance Method Details

#percentageString



457
458
459
460
461
462
463
# File '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



449
450
451
452
453
454
# File '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>



441
442
443
444
445
446
# File '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>



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

def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end