Class: Cucumber::Formatter::Usage
- Inherits:
-
Ast::Visitor
- Object
- Ast::Visitor
- Cucumber::Formatter::Usage
- Includes:
- Console
- Defined in:
- lib/cucumber/formatter/usage.rb
Overview
The formatter used for --format usage
Constant Summary
Constants included from Console
Constants included from ANSIColor
Instance Attribute Summary
Attributes inherited from Ast::Visitor
Instance Method Summary collapse
-
#initialize(step_mother, io, options) ⇒ Usage
constructor
A new instance of Usage.
- #print_summary(features) ⇒ Object
- #print_unused_step_definitions ⇒ Object
- #visit_features(features) ⇒ Object
- #visit_step(step) ⇒ Object
- #visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object
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
Methods inherited from Ast::Visitor
#announce, #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_multiline_arg, #visit_outline_table, #visit_py_string, #visit_scenario_name, #visit_step_result, #visit_steps, #visit_table_cell, #visit_table_cell_value, #visit_table_row, #visit_tag_name, #visit_tags
Constructor Details
#initialize(step_mother, io, options) ⇒ Usage
Returns a new instance of Usage.
9 10 11 12 13 14 15 16 |
# File 'lib/cucumber/formatter/usage.rb', line 9 def initialize(step_mother, io, ) super(step_mother) @io = io @options = @step_definitions = Hash.new { |h,step_definition| h[step_definition] = [] } @all_step_definitions = step_mother.step_definitions.dup @locations = [] end |
Instance Method Details
#print_summary(features) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cucumber/formatter/usage.rb', line 41 def print_summary(features) sorted_defs = @step_definitions.keys.sort_by{|step_definition| step_definition.backtrace_line} sorted_defs.each do |step_definition| step_matches_and_descriptions = @step_definitions[step_definition].sort_by do |step_match_and_description| step_match = step_match_and_description[0] step_match.step_definition.regexp.inspect end step_matches = step_matches_and_descriptions.map{|step_match_and_description| step_match_and_description[0]} lengths = step_matches_and_descriptions.map do |step_match_and_description| step_match_and_description[2] end lengths << step_definition.text_length max_length = lengths.max @io.print step_definition.regexp.inspect @io.puts format_string(" # #{step_definition.file_colon_line}".indent(max_length - step_definition.text_length), :comment) da = step_matches_and_descriptions.map do |step_match_and_description| step_match = step_match_and_description[0] description = step_match_and_description[1] length = step_match_and_description[2] file_colon_line = step_match_and_description[3] " #{description}" + format_string(" # #{file_colon_line}".indent(max_length - length), :comment) end da.sort.each{|d| puts d} end print_unused_step_definitions end |
#print_unused_step_definitions ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cucumber/formatter/usage.rb', line 73 def print_unused_step_definitions if @all_step_definitions.any? max_length = @all_step_definitions.map{|step_definition| step_definition.text_length}.max @io.puts format_string("(::) UNUSED (::)", :failed) @all_step_definitions.each do |step_definition| @io.print format_string(step_definition.regexp.inspect, :failed) @io.puts format_string(" # #{step_definition.file_colon_line}".indent(max_length - step_definition.text_length), :comment) end end end |
#visit_features(features) ⇒ Object
18 19 20 21 |
# File 'lib/cucumber/formatter/usage.rb', line 18 def visit_features(features) super print_summary(features) end |
#visit_step(step) ⇒ Object
23 24 25 26 |
# File 'lib/cucumber/formatter/usage.rb', line 23 def visit_step(step) @step = step super end |
#visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cucumber/formatter/usage.rb', line 28 def visit_step_name(keyword, step_match, status, source_indent, background) if step_match.step_definition location = @step.file_colon_line return if @locations.index(location) @locations << location description = format_step(keyword, step_match, status, nil) length = (keyword + step_match.format_args).jlength @step_definitions[step_match.step_definition] << [step_match, description, length, location] @all_step_definitions.delete(step_match.step_definition) end end |