Class: Cucumber::Formatter::Usage

Inherits:
Progress
  • Object
show all
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 Attribute Summary

Attributes inherited from Progress

#config, #runtime, #summary

Instance Method Summary collapse

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

Methods included from Console

#collect_snippet_data, #do_print_passing_wip, #do_print_profile_information, #do_print_snippets, #embed, #empty_messages, #exception_message_string, #format_step, #format_string, #linebreaks, #print_element_messages, #print_elements, #print_exception, #print_message, #print_messages, #print_passing_wip, #print_profile_information, #print_snippets, #print_statistics, #print_table_row_messages, #puts

Methods included from ANSIColor

#cukes, define_grey, define_real_grey, #green_cukes, #red_cukes, #yellow_cukes

Methods included from Term::ANSIColor

attributes, coloring=, coloring?, included, #uncolored

Methods included from Duration

#format_duration

Constructor Details

#initialize(config) ⇒ Usage

Returns a new instance of Usage



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

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.source] = step_match
  end
  config.on_event :step_definition_registered, &method(:on_step_definition_registered)
end

Instance Method Details

#on_step_definition_registered(event) ⇒ Object



25
26
27
28
# File 'lib/cucumber/formatter/usage.rb', line 25

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



30
31
32
33
# File 'lib/cucumber/formatter/usage.rb', line 30

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

#on_test_step_finished(event) ⇒ Object



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

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

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

  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

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

  super
end