Module: Cucumber::Formatter::Console

Extended by:
ANSIColor
Included in:
Pretty, Progress, Usage
Defined in:
lib/cucumber/formatter/console.rb

Constant Summary collapse

FORMATS =
Hash.new{|hash, format| hash[format] = method(format).to_proc}

Constants included from ANSIColor

ANSIColor::ALIASES

Instance Method Summary collapse

Methods included from ANSIColor

grey

Instance Method Details

#announce(announcement) ⇒ Object



90
91
92
93
94
# File 'lib/cucumber/formatter/console.rb', line 90

def announce(announcement)
  @io.puts
  @io.puts(format_string(announcement, :tag))
  @io.flush
end

#format_step(keyword, step_match, status, source_indent) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cucumber/formatter/console.rb', line 9

def format_step(keyword, step_match, status, source_indent)
  comment = if source_indent
    c = (' # ' + step_match.file_colon_line).indent(source_indent)
    format_string(c, :comment)
  else
    ''
  end

  format = format_for(status, :param)
  line = keyword + " " + step_match.format_args(format) + comment
  format_string(line, status)
end

#format_string(string, status) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/cucumber/formatter/console.rb', line 22

def format_string(string, status)
  fmt = format_for(status)
  if Proc === fmt
    fmt.call(string)
  else
    fmt % string
  end
end


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cucumber/formatter/console.rb', line 53

def print_counts
  @io.puts dump_count(step_mother.scenarios.length, "scenario")

  [:failed, :skipped, :undefined, :pending, :passed].each do |status|
    if step_mother.steps(status).any?
      count_string = dump_count(step_mother.steps(status).length, "step", status.to_s)
      @io.puts format_string(count_string, status)
      @io.flush
    end
  end
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cucumber/formatter/console.rb', line 35

def print_elements(elements, status, kind)
  if elements.any?
    @io.puts(format_string("(::) #{status} #{kind} (::)", status))
    @io.puts
    @io.flush
  end

  elements.each_with_index do |element, i|
    if status == :failed
      print_exception(element.exception, status, 0)
    else
      @io.puts(format_string(element.backtrace_line, status))
    end
    @io.puts
    @io.flush
  end
end


65
66
67
68
69
# File 'lib/cucumber/formatter/console.rb', line 65

def print_exception(e, status, indent)
  if @options[:strict] || !(Undefined === e) || e.nested?
    @io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status))
  end
end


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cucumber/formatter/console.rb', line 71

def print_snippets(options)
  return unless options[:snippets]
  undefined = step_mother.steps(:undefined)
  return if undefined.empty?
  snippets = undefined.map do |step|
    step_name = Undefined === step.exception ? step.exception.step_name : step.name
    step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil
    snippet = @step_mother.snippet_text(step.actual_keyword, step_name, step_multiline_class)
    snippet
  end.compact.uniq

  text = "\nYou can implement step definitions for missing steps with these snippets:\n\n"
  text += snippets.join("\n\n")

  @io.puts format_string(text, :undefined)
  @io.puts
  @io.flush
end


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

def print_steps(status)
  print_elements(step_mother.steps(status), status, 'steps')
end