Module: Cucumber::Formatter::Console
Constant Summary collapse
- FORMATS =
Hash.new{|hash, format| hash[format] = method(format).to_proc}
Constants included from ANSIColor
Instance Method Summary collapse
- #format_step(keyword, step_name, status, step_definition, source_indent) ⇒ Object
- #format_string(string, status) ⇒ Object
- #print_counts(features) ⇒ Object
- #print_elements(elements, status, kind) ⇒ Object
- #print_exception(e, indent) ⇒ Object
- #print_snippets(features, options) ⇒ Object
- #print_steps(features, status) ⇒ Object
- #print_undefined_scenarios(features) ⇒ Object
Methods included from ANSIColor
Instance Method Details
#format_step(keyword, step_name, status, step_definition, source_indent) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cucumber/formatter/console.rb', line 9 def format_step(keyword, step_name, status, step_definition, source_indent) comment = if source_indent && step_definition c = (' # ' + step_definition.file_colon_line).indent(source_indent) format_string(c, :comment) else '' end begin line = keyword + " " + step_definition.format_args(step_name, format_for(status, :param)) + comment rescue # It didn't match. This often happens for :outline steps line = keyword + " " + step_name + comment end format_string(line, status) end |
#format_string(string, status) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cucumber/formatter/console.rb', line 27 def format_string(string, status) fmt = format_for(status) if Proc === fmt fmt.call(string) else fmt % string end end |
#print_counts(features) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cucumber/formatter/console.rb', line 63 def print_counts(features) @io.puts dump_count(features.scenarios.length, "scenario") [:failed, :skipped, :undefined, :pending, :passed].each do |status| if features.steps[status].any? count_string = dump_count(features.steps[status].length, "step", status.to_s) @io.puts format_string(count_string, status) @io.flush end end end |
#print_elements(elements, status, kind) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cucumber/formatter/console.rb', line 45 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, 0) else @io.puts(format_string(element.backtrace_line, status)) end @io.puts @io.flush end end |
#print_exception(e, indent) ⇒ Object
75 76 77 78 |
# File 'lib/cucumber/formatter/console.rb', line 75 def print_exception(e, indent) status = Cucumber::EXCEPTION_STATUS[e.class] @io.puts(format_string("#{e.} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status)) end |
#print_snippets(features, options) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cucumber/formatter/console.rb', line 80 def print_snippets(features, ) return unless [:snippets] undefined = features.steps[:undefined] return if undefined.empty? snippets = undefined.map do |step| step_name = Undefined === step.exception ? step.exception.step_name : step.name snippet = @step_mother.snippet_text(step.actual_keyword, step_name) 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 |
#print_steps(features, status) ⇒ Object
41 42 43 |
# File 'lib/cucumber/formatter/console.rb', line 41 def print_steps(features, status) print_elements(features.steps[status], status, 'steps') end |
#print_undefined_scenarios(features) ⇒ Object
36 37 38 39 |
# File 'lib/cucumber/formatter/console.rb', line 36 def print_undefined_scenarios(features) elements = features.scenarios.select{|scenario| scenario.undefined?} print_elements(elements, :undefined, 'scenarios') end |