Class: Cucumber::Formatter::Profile

Inherits:
Progress show all
Defined in:
lib/cucumber/formatter/profile.rb

Constant Summary collapse

NUMBER_OF_STEP_DEFINITONS_TO_SHOW =
10
NUMBER_OF_STEP_INVOCATIONS_TO_SHOW =
5

Constants included from Console

Console::FORMATS

Constants included from ANSIColor

ANSIColor::ALIASES

Instance Attribute Summary

Attributes inherited from Ast::Visitor

#options, #step_mother

Instance Method Summary collapse

Methods inherited from Progress

#visit_feature_element, #visit_features, #visit_table_cell_value

Methods included from Console

#announce, #format_step, #format_string, #print_counts, #print_elements, #print_exception, #print_passing_wip, #print_snippets, #print_stats, #print_steps, #print_tag_limit_warnings, #record_tag_occurrences

Methods included from ANSIColor

define_grey, define_real_grey, #grey

Methods included from Duration

#format_duration

Methods inherited from Ast::Visitor

#announce, #matches_scenario_names?, #visit_background, #visit_background_name, #visit_comment, #visit_comment_line, #visit_examples, #visit_examples_array, #visit_examples_name, #visit_exception, #visit_feature, #visit_feature_element, #visit_feature_name, #visit_features, #visit_multiline_arg, #visit_outline_table, #visit_py_string, #visit_scenario_name, #visit_step_name, #visit_steps, #visit_table_cell, #visit_table_cell_value, #visit_table_row, #visit_tag_name, #visit_tags

Constructor Details

#initialize(step_mother, io, options) ⇒ Profile

Returns a new instance of Profile.



9
10
11
12
# File 'lib/cucumber/formatter/profile.rb', line 9

def initialize(step_mother, io, options)
  super
  @step_definition_durations = Hash.new { |h,step_definition| h[step_definition] = [] }
end

Instance Method Details



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber/formatter/profile.rb', line 30

def print_summary(features)
  super
  @io.puts "\n\nTop #{NUMBER_OF_STEP_DEFINITONS_TO_SHOW} average slowest steps with #{NUMBER_OF_STEP_INVOCATIONS_TO_SHOW} slowest matches:\n"

  mean_durations = map_to_mean_durations(@step_definition_durations)
  mean_durations = mean_durations.sort_by do |duration_description_location, step_definition, mean_duration| 
    mean_duration
  end.reverse

  mean_durations[0...NUMBER_OF_STEP_DEFINITONS_TO_SHOW].each do |duration_description_location, step_definition, mean_duration|
    print_step_definition(step_definition, mean_duration)
    duration_description_location = duration_description_location.sort_by do |duration, description, location| 
      duration 
    end.reverse
    print_step_definitions(duration_description_location, step_definition)
  end
end

#visit_step(step) ⇒ Object



14
15
16
17
18
# File 'lib/cucumber/formatter/profile.rb', line 14

def visit_step(step)
  @step_duration = Time.now
  @step = step
  super
end

#visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/cucumber/formatter/profile.rb', line 20

def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
  duration = Time.now - @step_duration
  super

  if step_match.step_definition
    description = format_step(keyword, step_match, status, nil)
    @step_definition_durations[step_match.step_definition] << [duration, description, @step.file_colon_line]
  end
end