This module contains helper methods that are used by formatters that print output to the terminal.
define @delayed_announcements = [] in your Formatter if you want to activate this feature
# File lib/cucumber/formatter/console.rb, line 134
134: def announce(announcement)
135: if @delayed_announcements
136: @delayed_announcements << announcement
137: else
138: if @io
139: @io.puts
140: @io.puts(format_string(announcement, :tag))
141: @io.flush
142: end
143: end
144: end
# File lib/cucumber/formatter/console.rb, line 128
128: def embed(file, mime_type)
129: # no-op
130: end
# File lib/cucumber/formatter/console.rb, line 163
163: def empty_announcements
164: @delayed_announcements = []
165: end
# File lib/cucumber/formatter/console.rb, line 16
16: def format_step(keyword, step_match, status, source_indent)
17: comment = if source_indent
18: c = (' # ' + step_match.file_colon_line).indent(source_indent)
19: format_string(c, :comment)
20: else
21: ''
22: end
23:
24: format = format_for(status, :param)
25: line = keyword + step_match.format_args(format) + comment
26: format_string(line, status)
27: end
# File lib/cucumber/formatter/console.rb, line 29
29: def format_string(string, status)
30: fmt = format_for(status)
31: if Proc === fmt
32: fmt.call(string)
33: else
34: fmt % string
35: end
36: end
# File lib/cucumber/formatter/console.rb, line 158
158: def print_announcement(announcement)
159: @io.puts(format_string(announcement, :tag).indent(@indent))
160: @io.flush
161: end
# File lib/cucumber/formatter/console.rb, line 146
146: def print_announcements()
147: @delayed_announcements.each {|ann| print_announcement(ann)}
148: empty_announcements
149: end
# File lib/cucumber/formatter/console.rb, line 60
60: def print_counts
61: STDERR.puts("The #print_counts method is deprecated and will be removed in 0.4. Use #print_stats instead")
62: print_stats(nil)
63: end
# File lib/cucumber/formatter/console.rb, line 42
42: def print_elements(elements, status, kind)
43: if elements.any?
44: @io.puts(format_string("(::) #{status} #{kind} (::)", status))
45: @io.puts
46: @io.flush
47: end
48:
49: elements.each_with_index do |element, i|
50: if status == :failed
51: print_exception(element.exception, status, 0)
52: else
53: @io.puts(format_string(element.backtrace_line, status))
54: end
55: @io.puts
56: @io.flush
57: end
58: end
# File lib/cucumber/formatter/console.rb, line 87
87: def print_exception(e, status, indent)
88: @io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status))
89: end
# File lib/cucumber/formatter/console.rb, line 117
117: def print_passing_wip(options)
118: return unless options[:wip]
119: passed = step_mother.scenarios(:passed)
120: if passed.any?
121: @io.puts format_string("\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:", :failed)
122: print_elements(passed, :passed, "scenarios")
123: else
124: @io.puts format_string("\nThe --wip switch was used, so the failures were expected. All is good.\n", :passed)
125: end
126: end
# File lib/cucumber/formatter/console.rb, line 91
91: def print_snippets(options)
92: return unless options[:snippets]
93: undefined = step_mother.steps(:undefined)
94: return if undefined.empty?
95:
96: unknown_programming_language = step_mother.unknown_programming_language?
97: snippets = undefined.map do |step|
98: step_name = Undefined === step.exception ? step.exception.step_name : step.name
99: step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil
100: snippet = @step_mother.snippet_text(step.actual_keyword, step_name, step_multiline_class)
101: snippet
102: end.compact.uniq
103:
104: text = "\nYou can implement step definitions for undefined steps with these snippets:\n\n"
105: text += snippets.join("\n\n")
106: @io.puts format_string(text, :undefined)
107:
108: if unknown_programming_language
109: @io.puts format_string("\nIf you want snippets in a different programming language, just make sure a file\n" +
110: "with the appropriate file extension exists where cucumber looks for step definitions.", :failed)
111: end
112:
113: @io.puts
114: @io.flush
115: end
# File lib/cucumber/formatter/console.rb, line 65
65: def print_stats(features, profiles = [])
66: @failures = step_mother.scenarios(:failed).select { |s| s.is_a?(Cucumber::Ast::Scenario) || s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow) }
67: @failures.collect! { |s| (s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)) ? s.scenario_outline : s }
68:
69: if !@failures.empty?
70: @io.puts format_string("Failing Scenarios:", :failed)
71: @failures.each do |failure|
72: profiles_string = profiles.empty? ? '' : (profiles.map{|profile| "-p #{profile}" }).join(' ') + ' '
73: @io.puts format_string("cucumber #{profiles_string}" + failure.file_colon_line, :failed) +
74: format_string(" # Scenario: " + failure.name, :comment)
75: end
76: @io.puts
77: end
78:
79: @io.puts scenario_summary(step_mother) {|status_count, status| format_string(status_count, status)}
80: @io.puts step_summary(step_mother) {|status_count, status| format_string(status_count, status)}
81:
82: @io.puts(format_duration(features.duration)) if features && features.duration
83:
84: @io.flush
85: end
# File lib/cucumber/formatter/console.rb, line 38
38: def print_steps(status)
39: print_elements(step_mother.steps(status), status, 'steps')
40: end
# File lib/cucumber/formatter/console.rb, line 151
151: def print_table_row_announcements
152: return if @delayed_announcements.empty?
153: @io.print(format_string(@delayed_announcements.join(', '), :tag).indent(2))
154: @io.flush
155: empty_announcements
156: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.