Parent

Included Modules

Gherkin::Formatter::PrettyFormatter

Constants

START
TRIPLE_QUOTES
START
TRIPLE_QUOTES

Public Class Methods

new(io, monochrome) click to toggle source
    # File lib/gherkin/formatter/pretty_formatter.rb, line 17
17:       def initialize(io, monochrome)
18:         @io = io
19:         @monochrome = monochrome
20:         @format = MonochromeFormat.new #@monochrome ? MonochromeFormat.new : AnsiColorFormat.new
21:       end

Public Instance Methods

background(statement) click to toggle source
    # 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
eof() click to toggle source
    # File lib/gherkin/formatter/pretty_formatter.rb, line 78
78:       def eof
79:         # NO-OP
80:       end
examples(examples) click to toggle source
    # 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
feature(feature) click to toggle source
    # 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
scenario(statement) click to toggle source
    # 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
scenario_outline(scenario_outline) click to toggle source
    # File lib/gherkin/formatter/pretty_formatter.rb, line 49
49:       def scenario_outline(scenario_outline)
50:         scenario(scenario_outline)
51:       end
step(step) click to toggle source
    # 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
steps(steps) click to toggle source

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
table(rows) click to toggle source
     # 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
uri(uri) click to toggle source
    # File lib/gherkin/formatter/pretty_formatter.rb, line 23
23:       def uri(uri)
24:         @uri = uri
25:       end

Private Instance Methods

color(cell, statuses, col) click to toggle source
     # 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
escape_triple_quotes(s) click to toggle source
     # File lib/gherkin/formatter/pretty_formatter.rb, line 140
140:       def escape_triple_quotes(s)
141:         s.gsub(TRIPLE_QUOTES, '\"\"\"')
142:       end
exception(exception) click to toggle source
     # 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
indent(string, indentation) click to toggle source
     # File lib/gherkin/formatter/pretty_formatter.rb, line 136
136:       def indent(string, indentation)
137:         string.gsub(START, indentation)
138:       end
indented_element_uri!(keyword, name, line) click to toggle source
     # 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
indented_step_location!(location) click to toggle source
     # 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
py_string(py_string) click to toggle source
     # File lib/gherkin/formatter/pretty_formatter.rb, line 111
111:       def py_string(py_string)
112:         @io.puts "      \"\"\"\n" + escape_triple_quotes(indent(py_string.value, '      ')) + "\n      \"\"\""
113:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.