123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::Formatters::ProfileFormatter Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-core/lib/rspec/core/formatters/profile_formatter.rb

Overview

Formatter for providing profile output.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#output (readonly)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/profile_formatter.rb', line 16

attr_reader :output

Instance Method Details

#bold(text) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/profile_formatter.rb', line 62

def bold(text)
  ConsoleCodes.wrap(text, :bold)
end

#dump_profile(profile)

This method is invoked after the dumping the summary if profiling is enabled.

Parameters:

  • profile (ProfileNotification)

    containing duration, slowest_examples and slowest_example_groups

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/profile_formatter.rb', line 25

def dump_profile(profile)
  dump_profile_slowest_examples(profile)
  dump_profile_slowest_example_groups(profile)
end

#dump_profile_slowest_example_groups(profile) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/profile_formatter.rb', line 44

def dump_profile_slowest_example_groups(profile)
  return if profile.slowest_groups.empty?

  @output.puts "\nTop #{profile.slowest_groups.size} slowest example groups:"
  profile.slowest_groups.each do |loc, hash|
    average = "#{bold(Helpers.format_seconds(hash[:average]))} #{bold("seconds")} average"
    total   = "#{Helpers.format_seconds(hash[:total_time])} seconds"
    count   = Helpers.pluralize(hash[:count], "example")
    @output.puts "  #{hash[:description]}"
    @output.puts "    #{average} (#{total} / #{count}) #{loc}"
  end
end

#dump_profile_slowest_examples(profile) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/profile_formatter.rb', line 32

def dump_profile_slowest_examples(profile)
  @output.puts "\nTop #{profile.slowest_examples.size} slowest " \
    "examples (#{Helpers.format_seconds(profile.slow_duration)} " \
    "seconds, #{profile.percentage}% of total time):\n"

  profile.slowest_examples.each do |example|
    @output.puts "  #{example.full_description}"
    @output.puts "    #{bold(Helpers.format_seconds(example.execution_result.run_time))} " \
                 "#{bold("seconds")} #{format_caller(example.location)}"
  end
end

#format_caller(caller_info) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/profile_formatter.rb', line 57

def format_caller(caller_info)
  RSpec.configuration.backtrace_formatter.backtrace_line(
    caller_info.to_s.split(':in `block').first)
end