Method: Cucumber::Formatter::Console#print_snippets

Defined in:
lib/cucumber/formatter/console.rb


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cucumber/formatter/console.rb', line 116

def print_snippets(options)
  return unless options[:snippets]
  undefined = runtime.steps(:undefined)
  return if undefined.empty?

  unknown_programming_language = runtime.unknown_programming_language?
  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 = @runtime.snippet_text(step.actual_keyword, step_name, step_multiline_class)
    snippet
  end.compact.uniq

  text = "\nYou can implement step definitions for undefined steps with these snippets:\n\n"
  text += snippets.join("\n\n")
  @io.puts format_string(text, :undefined)

  if unknown_programming_language
    @io.puts format_string("\nIf you want snippets in a different programming language," +
                           "\njust make sure a file with the appropriate file extension" +
                           "\nexists where cucumber looks for step definitions.", :failed)
  end

  @io.puts
  @io.flush
end