Class: Cucumber::Formatters::PrettyFormatter

Inherits:
Object
  • Object
show all
Includes:
ANSIColor
Defined in:
lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb

Constant Summary collapse

INDENT =
"\n      "

Constants included from ANSIColor

ANSIColor::ALIASES

Constants included from Term::ANSIColor

Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP

Instance Method Summary collapse

Methods included from ANSIColor

#grey

Methods included from Term::ANSIColor

attributes, coloring=, coloring?, #uncolored

Constructor Details

#initialize(io, step_mother, options = {}) ⇒ PrettyFormatter

Returns a new instance of PrettyFormatter.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 10

def initialize(io, step_mother, options={})
  @io = (io == STDOUT) ? Kernel : io
  @options = options
  @step_mother = step_mother
  @pending_scenarios  = []
  @passed             = []
  @failed             = []
  @pending_steps      = []
  @skipped            = []
  @last_executed_was_row = false
  @pending_messages = {}
  @forced_pending_step_count = 0
  
  @total_scenario_count = 0
end

Instance Method Details

#dumpObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 176

def dump
  @io.puts

  print_pending_messages if @pending_messages.any?

  @io.puts dump_count(@total_scenario_count, "scenario")

  @io.puts pending(dump_count(@pending_scenarios.length, "scenario", "pending")) if @pending_scenarios.any?

  @io.puts passed(dump_count(@passed.length, "step", "passed"))   if @passed.any?
  @io.puts failed(dump_count(@failed.length, "step", "failed"))   if @failed.any?
  @io.puts skipped(dump_count(@skipped.length, "step", "skipped")) if @skipped.any?

  if @pending_steps.any?
    @io.print pending(dump_count(@pending_steps.length, "step", "pending")) 
    @io.print pending(" (#{number_of_unimplemented_steps} with no step definition)") if number_of_unimplemented_steps > 0
    @io.puts
  end

  @io.print reset

  print_snippets if @options[:snippets]
end

#dump_count(count, what, state = nil) ⇒ Object



200
201
202
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 200

def dump_count(count, what, state=nil)
  return [count, "#{what}#{count == 1 ? '' : 's'}", state].compact.join(" ")
end

#feature_executing(feature) ⇒ Object



26
27
28
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 26

def feature_executing(feature)
  @feature = feature
end

#header_executing(header) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 30

def header_executing(header)
  @io.puts if @feature_newline
  @feature_newline = true

  header_lines = header.split("\n")
  header_lines.each_with_index do |line, index|
    @io.print line
    if @options[:source] && index==0
      @io.print padding_spaces(@feature)
      @io.print comment("# #{@feature.file}")
    end
    @io.puts
  end
end

#output_failing_step(step) ⇒ Object



171
172
173
174
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 171

def output_failing_step(step)
  @io.puts failed("      #{step.error.message.split("\n").join(INDENT)} (#{step.error.class})")
  @io.puts failed("      #{step.error.cucumber_backtrace.join(INDENT)}")
end


204
205
206
207
208
209
210
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 204

def print_pending_messages
  @io.puts "Pending Notes:"
  @pending_messages.each_value do |message|
    @io.puts message
  end
  @io.puts
end


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 212

def print_snippets
  snippets = @pending_steps
  snippets.delete_if {|snippet| snippet.row? || @step_mother.has_step_definition?(snippet.name)}

  unless snippets.empty?
    @io.puts "\nYou can use these snippets to implement pending steps which have no step definition:\n\n"

    prev_keyword = nil
    snippets = snippets.map do |step|
      snippet = "#{step.actual_keyword} /^#{escape_regexp_characters(step.name)}$/ do\nend\n\n"
      prev_keyword = step.keyword
      snippet
    end.compact.uniq

    snippets.each do |snippet|
      @io.puts snippet
    end
  end
end

#scenario_executed(scenario) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 74

def scenario_executed(scenario)
  @io.puts
  if !scenario.row? && scenario.table_header
    @table_column_widths = scenario.table_column_widths
    @current_column = -1
    @io.print "    |"
    print_row(scenario.table_header)
    @io.puts
  elsif scenario.row? && @scenario_failed
    @io.puts
    output_failing_step(@failed.last)
  end
  @total_scenario_count += 1
end

#scenario_executing(scenario) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 45

def scenario_executing(scenario)
  scenario_or_scenario_outline_keyword = scenario.outline? ? Cucumber.language['scenario_outline'] : Cucumber.language['scenario']
  
  @scenario_failed = false
  @io.puts if @last_executed_was_row && !scenario.row?
  if scenario.row?
    @last_executed_was_row = true
    @io.print "    |"
  else
    scenario_text = "#{scenario_or_scenario_outline_keyword}: #{scenario.name}"
    
    if scenario.pending?
      @pending_scenarios << scenario
      @io.print pending("  #{scenario_text}")
    elsif scenario.outline?
      @io.print skipped("  #{scenario_text}")
    else
      @io.print passed("  #{scenario_text}")
    end
    @last_executed_was_row = false

    if @options[:source]
      @io.print padding_spaces(scenario)
      @io.print comment("# #{scenario.file}:#{scenario.line}")
    end
    @io.puts
  end
end

#step_failed(step, regexp, args) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 105

def step_failed(step, regexp, args)
  @scenario_failed = true
  if step.row?
    args = step.visible_args if step.outline?
    @failed << step
    print_failed_args(args)
  else
    @failed << step
    @io.print failed("    #{step.keyword} #{step.format(regexp){|param| failed_param(param) << failed}}")
    if @options[:source]
      @io.print padding_spaces(step)
      @io.print source_comment(step)
    end
    @io.puts
    output_failing_step(step)
  end
end

#step_passed(step, regexp, args) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 89

def step_passed(step, regexp, args)
  if step.row?
    args = step.visible_args if step.outline?
    @passed << step
    print_passed_args(args)
  else
    @passed << step
    @io.print passed("    #{step.keyword} #{step.format(regexp){|param| passed_param(param) << passed}}")
    if @options[:source]
      @io.print padding_spaces(step)
      @io.print source_comment(step)
    end
    @io.puts
  end
end

#step_pending(step, regexp, args) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 142

def step_pending(step, regexp, args)
  if step.row?
    args = step.visible_args if step.outline?
    @pending_steps << step
    print_pending_args(args)
  else
    @pending_steps << step
    @io.print pending("    #{step.keyword} #{step.name}")
    if @options[:source]
      @io.print padding_spaces(step)
      @io.print comment("# #{step.file}:#{step.line}")
    end
    @io.puts
  end
  if step.forced_to_pending?
    @pending_messages[regexp.inspect] ||= "#{step.keyword} #{regexp.inspect} (#{step.error.message}) #{source_comment(step)}" 
    @forced_pending_step_count += 1
  end
end

#step_skipped(step, regexp, args) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 123

def step_skipped(step, regexp, args)
  @skipped << step
  if step.row?
    args = step.visible_args if step.outline?
    print_skipped_args(args)
  else
    @io.print skipped("    #{step.keyword} #{step.format(regexp){|param| skipped_param(param) << skipped}}")
    if @options[:source]
      @io.print padding_spaces(step)
      if step.outline?
        @io.print comment("# #{step.file}:#{step.line}")
      else
        @io.print source_comment(step)
      end
    end
    @io.puts
  end
end

#step_traced(step, regexp, args) ⇒ Object



162
163
164
165
166
167
168
169
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/pretty_formatter.rb', line 162

def step_traced(step, regexp, args)
  @io.print skipped("    #{step.keyword} #{step.format(regexp){|param| skipped_param(param) << skipped}}")
  if @options[:source]
    @io.print padding_spaces(step)
    @io.print comment("# #{step.file}:#{step.line}")
  end
  @io.puts
end