@api private Formatter for providing profile output
@private
# File lib/rspec/core/formatters/profile_formatter.rb, line 12 def initialize(output) @output = output end
@method #dump_profile @api public
This method is invoked after the dumping the summary if profiling is enabled.
@param profile [ProfileNotification] containing duration, slowest_examples
and slowest_example_groups
# File lib/rspec/core/formatters/profile_formatter.rb, line 27 def dump_profile(profile) dump_profile_slowest_examples(profile) dump_profile_slowest_example_groups(profile) end
# File lib/rspec/core/formatters/profile_formatter.rb, line 60 def bold(text) ConsoleCodes.wrap(text, :bold) end
# File lib/rspec/core/formatters/profile_formatter.rb, line 43 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
# File lib/rspec/core/formatters/profile_formatter.rb, line 34 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
# File lib/rspec/core/formatters/profile_formatter.rb, line 56 def format_caller(caller_info) RSpec.configuration.backtrace_formatter.backtrace_line(caller_info.to_s.split(':in `block').first) end