Class: Cucumber::Formatter::Usage

Inherits:
Progress
  • Object
show all
Includes:
Console
Defined in:
lib/cucumber/formatter/usage.rb

Direct Known Subclasses

Stepdefs

Defined Under Namespace

Classes: StepDefKey

Constant Summary

Constants included from ANSIColor

ANSIColor::ALIASES

Constants included from Term::ANSIColor

Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP

Instance Method Summary collapse

Methods included from Console

#attach, #collect_snippet_data, #collect_undefined_parameter_type_names, #do_print_passing_wip, #do_print_profile_information, #do_print_snippets, #do_print_undefined_parameter_type_snippet, #exception_message_string, #format_step, #format_string, #indent, #linebreaks, #print_element_messages, #print_elements, #print_exception, #print_passing_wip, #print_profile_information, #print_snippets, #print_statistics

Methods included from ANSIColor

apply_custom_colors, #cukes, #green_cukes, #red_cukes, #yellow_cukes

Methods included from Term::ANSIColor

#attributes, included, #uncolored

Methods included from Duration

#format_duration

Methods inherited from Progress

#on_step_activated, #on_test_case_finished, #on_test_case_started, #on_test_run_finished

Methods included from Io

ensure_dir, ensure_file, ensure_io, included, io?, url?

Constructor Details

#initialize(config) ⇒ Usage

Returns a new instance of Usage.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cucumber/formatter/usage.rb', line 15

def initialize(config)
  super
  @stepdef_to_match = Hash.new { |h, stepdef_key| h[stepdef_key] = [] }
  @total_duration = 0
  @matches = {}
  config.on_event :step_activated do |event|
    test_step, step_match = *event.attributes
    @matches[test_step.to_s] = step_match
  end
  config.on_event :step_definition_registered, &method(:on_step_definition_registered)
end

Instance Method Details

#on_step_definition_registered(event) ⇒ Object



27
28
29
30
# File 'lib/cucumber/formatter/usage.rb', line 27

def on_step_definition_registered(event)
  stepdef_key = StepDefKey.new(event.step_definition.expression.to_s, event.step_definition.location)
  @stepdef_to_match[stepdef_key] = []
end

#on_step_match(event) ⇒ Object



32
33
34
35
# File 'lib/cucumber/formatter/usage.rb', line 32

def on_step_match(event)
  @matches[event.test_step.to_s] = event.step_match
  super
end

#on_test_step_finished(event) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cucumber/formatter/usage.rb', line 37

def on_test_step_finished(event)
  return if event.test_step.hook?

  test_step = event.test_step
  result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
  step_match = @matches[test_step.to_s]

  unless step_match.nil?
    step_definition = step_match.step_definition
    stepdef_key = StepDefKey.new(step_definition.expression.to_s, step_definition.location)
    unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location
      duration = DurationExtractor.new(result).result_duration
      keyword = @ast_lookup.step_source(test_step).step.keyword

      @stepdef_to_match[stepdef_key] << {
        keyword: keyword,
        step_match: step_match,
        status: result.to_sym,
        location: test_step.location,
        duration: duration
      }
    end
  end

  super
end