Object
# File lib/gherkin/formatter/pretty_formatter.rb, line 34 34: def background(statement) 35: @io.puts 36: print_comments(statement.comments, ' ') 37: @io.puts " #{statement.keyword}: #{statement.name}#{indented_element_uri!(statement.keyword, statement.name, statement.line)}" 38: print_description(statement.description, ' ') 39: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 78 78: def eof 79: # NO-OP 80: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 53 53: def examples(examples) 54: @io.puts 55: print_comments(examples.comments, ' ') 56: print_tags(examples.tags, ' ') 57: @io.puts " #{examples.keyword}: #{examples.name}" 58: print_description(examples.description, ' ') 59: table(examples.rows) 60: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 27 27: def feature(feature) 28: print_comments(feature.comments, '') 29: print_tags(feature.tags, '') 30: @io.puts "#{feature.keyword}: #{feature.name}" 31: print_description(feature.description, ' ', false) 32: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 41 41: def scenario(statement) 42: @io.puts 43: print_comments(statement.comments, ' ') 44: print_tags(statement.tags, ' ') 45: @io.puts " #{statement.keyword}: #{statement.name}#{indented_element_uri!(statement.keyword, statement.name, statement.line)}" 46: print_description(statement.description, ' ') 47: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 49 49: def scenario_outline(scenario_outline) 50: scenario(scenario_outline) 51: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 62 62: def step(step) 63: name = Gherkin::Formatter::Argument.format(step.name, @format, (step.result ? step.result.arguments : [])) 64: 65: step_text = "#{step.keyword}#{step.name}" 66: step_text = self.__send__(step.result.status, step_text, @monochrome) if step.result 67: 68: print_comments(step.comments, ' ') 69: @io.puts(" #{step_text}#{indented_step_location!(step.result ? step.result.stepdef_location : nil)}") 70: case step.multiline_arg 71: when Model::PyString 72: py_string(step.multiline_arg) 73: when Array 74: table(step.multiline_arg) 75: end 76: end
This method can be invoked before a #, to ensure location arguments are aligned
# File lib/gherkin/formatter/pretty_formatter.rb, line 83 83: def steps(steps) 84: @step_lengths = steps.map {|keyword, name| (keyword+name).unpack("U*").length} 85: @max_step_length = @step_lengths.max 86: @step_index = 1 87: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 89 89: def table(rows) 90: cell_lengths = rows.map do |row| 91: row.cells.map do |cell| 92: escape_cell(cell).unpack("U*").length 93: end 94: end 95: max_lengths = cell_lengths.transpose.map { |col_lengths| col_lengths.max }.flatten 96: 97: rows.each_with_index do |row, i| 98: row.comments.each do |comment| 99: @io.puts " #{comment.value}" 100: end 101: j = 1 102: @io.puts ' | ' + row.cells.zip(max_lengths).map { |cell, max_length| 103: j += 1 104: color(cell, nil, j) + ' ' * (max_length - cell_lengths[i][j]) 105: }.join(' | ') + ' |' 106: end 107: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 120 120: def color(cell, statuses, col) 121: if statuses 122: self.__send__(statuses[col], escape_cell(cell), @monochrome) + (@monochrome ? '' : reset) 123: else 124: escape_cell(cell) 125: end 126: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 140 140: def escape_triple_quotes(s) 141: s.gsub(TRIPLE_QUOTES, '\"\"\"') 142: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 115 115: def exception(exception) 116: exception_text = "#{exception.message} (#{exception.class})\n#{(exception.backtrace || []).join("\n")}".gsub(/^/, ' ') 117: @io.puts(failed(exception_text, @monochrome)) 118: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 136 136: def indent(string, indentation) 137: string.gsub(START, indentation) 138: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 159 159: def indented_element_uri!(keyword, name, line) 160: return '' if @max_step_length.nil? 161: l = (keyword+name).unpack("U*").length 162: @max_step_length = [@max_step_length, l].max 163: indent = @max_step_length - l 164: ' ' * indent + ' ' + comments("# #{@uri}:#{line}", @monochrome) 165: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 167 167: def indented_step_location!(location) 168: return '' if location.nil? 169: indent = @max_step_length - @step_lengths[@step_index+=1] 170: ' ' * indent + ' ' + comments("# #{location}", @monochrome) 171: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 148 148: def print_comments(comments, indent) 149: @io.write(comments.empty? ? '' : indent + comments.map{|comment| comment.value}.join("\n#{indent}") + "\n") 150: end
# File lib/gherkin/formatter/pretty_formatter.rb, line 152 152: def print_description(description, indent, newline=true) 153: if description != "" 154: @io.puts indent(description, indent) 155: @io.puts if newline 156: end 157: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.