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 |
# File 'lib/cucumber/formatter/console.rb', line 9 def format_step(keyword, step_name, status, step_definition, source_indent) line = if step_definition # nil for :outline comment = if source_indent c = (' # ' + step_definition.file_colon_line).indent(source_indent) format_string(c, :comment) else '' end keyword + " " + step_definition.format_args(step_name, format_for(status, :param)) + comment else keyword + " " + step_name end format_string(line, status) end |
#format_string(string, status) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/cucumber/formatter/console.rb', line 24 def format_string(string, status) fmt = format_for(status) if Proc === fmt fmt.call(string) else fmt % string end end |
#print_counts(features) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cucumber/formatter/console.rb', line 60 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cucumber/formatter/console.rb', line 42 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
72 73 74 75 |
# File 'lib/cucumber/formatter/console.rb', line 72 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cucumber/formatter/console.rb', line 77 def print_snippets(features, ) return unless [:snippets] undefined = features.steps[:undefined] return if undefined.empty? snippets = undefined.map do |step| step_name = StepMother::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
38 39 40 |
# File 'lib/cucumber/formatter/console.rb', line 38 def print_steps(features, status) print_elements(features.steps[status], status, 'steps') end |
#print_undefined_scenarios(features) ⇒ Object
33 34 35 36 |
# File 'lib/cucumber/formatter/console.rb', line 33 def print_undefined_scenarios(features) elements = features.scenarios.select{|scenario| scenario.undefined?} print_elements(elements, :undefined, 'scenarios') end |