The formatter used for --format pretty (the default formatter).
This formatter prints features to plain text - exactly how they were parsed, just prettier. That means with proper indentation and alignment of table columns.
If the output is STDOUT (and not a file), there are bright colours to watch too.
# File lib/cucumber/formatter/pretty.rb, line 23 23: def initialize(step_mother, path_or_io, options) 24: @step_mother, @io, @options = step_mother, ensure_io(path_or_io, "pretty"), options 25: @exceptions = [] 26: @indent = 0 27: @prefixes = options[:prefixes] || {} 28: @delayed_announcements = [] 29: end
# File lib/cucumber/formatter/pretty.rb, line 87 87: def after_background(background) 88: @in_background = nil 89: @io.puts 90: @io.flush 91: end
# File lib/cucumber/formatter/pretty.rb, line 76 76: def after_feature_element(feature_element) 77: @io.puts 78: @io.flush 79: end
# File lib/cucumber/formatter/pretty.rb, line 31 31: def after_features(features) 32: print_summary(features) unless @options[:autoformat] 33: end
# File lib/cucumber/formatter/pretty.rb, line 175 175: def after_multiline_arg(multiline_arg) 176: @table = nil 177: end
# File lib/cucumber/formatter/pretty.rb, line 118 118: def after_outline_table(outline_table) 119: @table = nil 120: @indent = 4 121: end
# File lib/cucumber/formatter/pretty.rb, line 194 194: def after_table_cell(cell) 195: return unless @table 196: @col_index += 1 197: end
# File lib/cucumber/formatter/pretty.rb, line 185 185: def after_table_row(table_row) 186: return if !@table || @hide_this_step 187: print_table_row_announcements 188: @io.puts 189: if table_row.exception && !@exceptions.include?(table_row.exception) 190: print_exception(table_row.exception, table_row.status, @indent) 191: end 192: end
# File lib/cucumber/formatter/pretty.rb, line 93 93: def background_name(keyword, name, file_colon_line, source_indent) 94: print_feature_element_name(keyword, name, file_colon_line, source_indent) 95: end
# File lib/cucumber/formatter/pretty.rb, line 81 81: def before_background(background) 82: @indent = 2 83: @scenario_indent = 2 84: @in_background = true 85: end
# File lib/cucumber/formatter/pretty.rb, line 97 97: def before_examples_array(examples_array) 98: @indent = 4 99: @io.puts 100: @visiting_first_example_name = true 101: end
# File lib/cucumber/formatter/pretty.rb, line 35 35: def before_feature(feature) 36: @exceptions = [] 37: @indent = 0 38: if @options[:autoformat] 39: file = File.join(@options[:autoformat], feature.file) 40: dir = File.dirname(file) 41: mkdir_p(dir) unless File.directory?(dir) 42: @io = ensure_file(file, "pretty") 43: end 44: end
# File lib/cucumber/formatter/pretty.rb, line 71 71: def before_feature_element(feature_element) 72: @indent = 2 73: @scenario_indent = 2 74: end
# File lib/cucumber/formatter/pretty.rb, line 170 170: def before_multiline_arg(multiline_arg) 171: return if @options[:no_multiline] || @hide_this_step 172: @table = multiline_arg 173: end
# File lib/cucumber/formatter/pretty.rb, line 114 114: def before_outline_table(outline_table) 115: @table = outline_table 116: end
# File lib/cucumber/formatter/pretty.rb, line 127 127: def before_step(step) 128: @current_step = step 129: @indent = 6 130: end
# File lib/cucumber/formatter/pretty.rb, line 132 132: def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) 133: @hide_this_step = false 134: if exception 135: if @exceptions.include?(exception) 136: @hide_this_step = true 137: return 138: end 139: @exceptions << exception 140: end 141: if status != :failed && @in_background ^ background 142: @hide_this_step = true 143: return 144: end 145: @status = status 146: end
# File lib/cucumber/formatter/pretty.rb, line 179 179: def before_table_row(table_row) 180: return if !@table || @hide_this_step 181: @col_index = 0 182: @io.print ' |'.indent(@indent-2) 183: end
# File lib/cucumber/formatter/pretty.rb, line 103 103: def examples_name(keyword, name) 104: puts unless @visiting_first_example_name 105: @visiting_first_example_name = false 106: names = name.strip.empty? ? [name.strip] : name.split("\n") 107: @io.puts(" #{keyword}: #{names[0]}") 108: names[1..1].each {|s| @io.puts " #{s}" } unless names.empty? 109: @io.flush 110: @indent = 6 111: @scenario_indent = 6 112: end
# File lib/cucumber/formatter/pretty.rb, line 164 164: def exception(exception, status) 165: return if @hide_this_step 166: print_exception(exception, status, @indent) 167: @io.flush 168: end
# File lib/cucumber/formatter/pretty.rb, line 65 65: def feature_name(keyword, name) 66: @io.puts("#{keyword}: #{name}") 67: @io.puts 68: @io.flush 69: end
# File lib/cucumber/formatter/pretty.rb, line 156 156: def py_string(string) 157: return if @hide_this_step 158: s = %{"""\n#{string}\n"""}.indent(@indent) 159: s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n") 160: @io.puts(format_string(s, @current_step.status)) 161: @io.flush 162: end
# File lib/cucumber/formatter/pretty.rb, line 123 123: def scenario_name(keyword, name, file_colon_line, source_indent) 124: print_feature_element_name(keyword, name, file_colon_line, source_indent) 125: end
# File lib/cucumber/formatter/pretty.rb, line 148 148: def step_name(keyword, step_match, status, source_indent, background) 149: return if @hide_this_step 150: source_indent = nil unless @options[:source] 151: name_to_report = format_step(keyword, step_match, status, source_indent) 152: @io.puts(name_to_report.indent(@scenario_indent + 2)) 153: print_announcements 154: end
# File lib/cucumber/formatter/pretty.rb, line 199 199: def table_cell_value(value, status) 200: return if !@table || @hide_this_step 201: status ||= @status || :passed 202: width = @table.col_width(@col_index) 203: cell_text = escape_cell(value.to_s || '') 204: padded = cell_text + (' ' * (width - cell_text.unpack('U*').length)) 205: prefix = cell_prefix(status) 206: @io.print(' ' + format_string("#{prefix}#{padded}", status) + ::Term::ANSIColor.reset(" |")) 207: @io.flush 208: end
# File lib/cucumber/formatter/pretty.rb, line 226 226: def cell_prefix(status) 227: @prefixes[status] 228: end
# File lib/cucumber/formatter/pretty.rb, line 212 212: def print_feature_element_name(keyword, name, file_colon_line, source_indent) 213: @io.puts if @scenario_indent == 6 214: names = name.empty? ? [name] : name.split("\n") 215: line = "#{keyword}: #{names[0]}".indent(@scenario_indent) 216: @io.print(line) 217: if @options[:source] 218: line_comment = " # #{file_colon_line}".indent(source_indent) 219: @io.print(format_string(line_comment, :comment)) 220: end 221: @io.puts 222: names[1..1].each {|s| @io.puts " #{s}"} 223: @io.flush 224: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.