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
- #announce(announcement) ⇒ Object
- #format_step(keyword, step_match, status, source_indent) ⇒ Object
- #format_string(string, status) ⇒ Object
- #print_counts ⇒ Object
- #print_elements(elements, status, kind) ⇒ Object
- #print_exception(e, status, indent) ⇒ Object
- #print_passing_wip(options) ⇒ Object
- #print_snippets(options) ⇒ Object
- #print_stats(features) ⇒ Object
- #print_steps(status) ⇒ Object
Methods included from ANSIColor
Methods included from Duration
Instance Method Details
#announce(announcement) ⇒ Object
117 118 119 120 121 |
# File 'lib/cucumber/formatter/console.rb', line 117 def announce(announcement) @io.puts @io.puts(format_string(announcement, :tag)) @io.flush end |
#format_step(keyword, step_match, status, source_indent) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cucumber/formatter/console.rb', line 12 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
25 26 27 28 29 30 31 32 |
# File 'lib/cucumber/formatter/console.rb', line 25 def format_string(string, status) fmt = format_for(status) if Proc === fmt fmt.call(string) else fmt % string end end |
#print_counts ⇒ Object
56 57 58 59 |
# File 'lib/cucumber/formatter/console.rb', line 56 def print_counts STDERR.puts("The #print_counts method is deprecated and will be removed in 0.4. Use #print_stats instead") print_stats(nil) end |
#print_elements(elements, status, kind) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cucumber/formatter/console.rb', line 38 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 |
#print_exception(e, status, indent) ⇒ Object
85 86 87 |
# File 'lib/cucumber/formatter/console.rb', line 85 def print_exception(e, status, indent) @io.puts(format_string("#{e.} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status)) end |
#print_passing_wip(options) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/cucumber/formatter/console.rb', line 108 def print_passing_wip() return unless [:wip] passed = step_mother.scenarios(:passed) if passed.any? @io.puts "\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:" print_elements(passed, :passed, "scenarios") end end |
#print_snippets(options) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cucumber/formatter/console.rb', line 89 def print_snippets() return unless [: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 undefined steps with these snippets:\n\n" text += snippets.join("\n\n") @io.puts format_string(text, :undefined) @io.puts @io.flush end |
#print_stats(features) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cucumber/formatter/console.rb', line 61 def print_stats(features) @failures = step_mother.scenarios(:failed).select { |s| s.is_a?(Cucumber::Ast::Scenario) } if !@failures.empty? @io.puts format_string("Failing Scenarios:", :failed) @failures.each do |failure| @io.puts format_string("cucumber " + failure.file_colon_line, :failed) + format_string(" # Scenario: " + failure.name, :comment) end @io.puts end @io.print dump_count(step_mother.scenarios.length, "scenario") print_status_counts{|status| step_mother.scenarios(status)} @io.print dump_count(step_mother.steps.length, "step") print_status_counts{|status| step_mother.steps(status)} @io.puts(format_duration(features.duration)) if features @io.flush end |
#print_steps(status) ⇒ Object
34 35 36 |
# File 'lib/cucumber/formatter/console.rb', line 34 def print_steps(status) print_elements(step_mother.steps(status), status, 'steps') end |