Class: Cucumber::Formatter::CustomTarantulaFormatter

Inherits:
Object
  • Object
show all
Includes:
Console, FileUtils, Gherkin::Formatter::Escaping, Io
Defined in:
lib/CucumberTarantulaFormatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime, path_or_io, options) ⇒ CustomTarantulaFormatter

Returns a new instance of CustomTarantulaFormatter.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/CucumberTarantulaFormatter.rb', line 33

def initialize(runtime, path_or_io, options)
  @runtime, @io, @options = runtime, ensure_io(path_or_io, "pretty"), options
  @exceptions = []
  @indent = 0
  @prefixes = options[:prefixes] || {}
  @delayed_messages = []
  @feature_name = nil
  @scenario_index = 0
  @scenario_exceptions = []
  @scenario_undefined = false
  @scenario_updated = false
  TarantulaUpdater.config = YAML.load(File.open(SUPPORT+"/tarantula.yml"))
end

Instance Attribute Details

#indent=(value) ⇒ Object (writeonly)

Sets the attribute indent

Parameters:

  • value

    the value to set the attribute indent to.



30
31
32
# File 'lib/CucumberTarantulaFormatter.rb', line 30

def indent=(value)
  @indent = value
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



31
32
33
# File 'lib/CucumberTarantulaFormatter.rb', line 31

def runtime
  @runtime
end

Instance Method Details

#after_background(background) ⇒ Object



108
109
110
111
112
# File 'lib/CucumberTarantulaFormatter.rb', line 108

def after_background(background)
  @in_background = nil
  @io.puts
  @io.flush
end

#after_feature_element(feature_element) ⇒ Object



97
98
99
100
# File 'lib/CucumberTarantulaFormatter.rb', line 97

def after_feature_element(feature_element)
  @io.puts
  @io.flush
end

#after_features(features) ⇒ Object



47
48
49
50
51
52
# File 'lib/CucumberTarantulaFormatter.rb', line 47

def after_features(features)
  print_summary(features) unless @options[:autoformat]
  @io.puts(format_duration_simple(features.duration)) if features && features.duration
  resp = TarantulaUpdater.update_testcase_duration(ENV["project"], ENV["execution"], @feature_name, format_duration_simple(features.duration)) if features && features.duration
  @io.puts ">>>>>>>>>>>>>>>" + resp.to_s
end

#after_multiline_arg(multiline_arg) ⇒ Object



203
204
205
# File 'lib/CucumberTarantulaFormatter.rb', line 203

def after_multiline_arg(multiline_arg)
  @table = nil
end

#after_outline_table(outline_table) ⇒ Object



139
140
141
142
# File 'lib/CucumberTarantulaFormatter.rb', line 139

def after_outline_table(outline_table)
  @table = nil
  @indent = 4
end

#after_steps(steps) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/CucumberTarantulaFormatter.rb', line 238

def after_steps(steps)
  return if @scenario_updated
  result = "PASSED"
  message = ''
  position = @scenario_index
  if not @scenario_exceptions.empty?
    result = "FAILED"
    message = @scenario_exceptions.inspect
    @scenario_updated = true
  elsif @scenario_undefined
    result = "NOT_IMPL"
    message = "Undefined cucumber sentence found"
    @scenario_updated = true
  end
  if @in_background
    message += " !INSIDE BACKGROUND!"
    position = 1
  end
  resp = TarantulaUpdater.update_testcase_step(ENV["project"], ENV["execution"], @feature_name, position, result, message)
  @io.puts ">>>>>>>>>>>>>>>" + resp.to_s
end

#after_table_cell(cell) ⇒ Object



222
223
224
225
# File 'lib/CucumberTarantulaFormatter.rb', line 222

def after_table_cell(cell)
  return unless @table
  @col_index += 1
end

#after_table_row(table_row) ⇒ Object



213
214
215
216
217
218
219
220
# File 'lib/CucumberTarantulaFormatter.rb', line 213

def after_table_row(table_row)
  return if !@table || @hide_this_step
  print_table_row_messages
  @io.puts
  if table_row.exception && !@exceptions.include?(table_row.exception)
    print_exception(table_row.exception, table_row.status, @indent)
  end
end

#after_tags(tags) ⇒ Object



71
72
73
74
75
76
# File 'lib/CucumberTarantulaFormatter.rb', line 71

def after_tags(tags)
  if @indent == 1
    @io.puts
    @io.flush
  end
end

#background_name(keyword, name, file_colon_line, source_indent) ⇒ Object



114
115
116
# File 'lib/CucumberTarantulaFormatter.rb', line 114

def background_name(keyword, name, file_colon_line, source_indent)
  print_feature_element_name(keyword, name, file_colon_line, source_indent)
end

#before_background(background) ⇒ Object



102
103
104
105
106
# File 'lib/CucumberTarantulaFormatter.rb', line 102

def before_background(background)
  @indent = 2
  @scenario_indent = 2
  @in_background = true
end

#before_examples_array(examples_array) ⇒ Object



118
119
120
121
122
# File 'lib/CucumberTarantulaFormatter.rb', line 118

def before_examples_array(examples_array)
  @indent = 4
  @io.puts
  @visiting_first_example_name = true
end

#before_feature(feature) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/CucumberTarantulaFormatter.rb', line 54

def before_feature(feature)
  @scenario_index = 0
  @exceptions = []
  @indent = 0
  if @options[:autoformat]
    file = File.join(@options[:autoformat], feature.file)
    dir = File.dirname(file)
    mkdir_p(dir) unless File.directory?(dir)
    @io = ensure_file(file, "pretty")
  end
end

#before_feature_element(feature_element) ⇒ Object



92
93
94
95
# File 'lib/CucumberTarantulaFormatter.rb', line 92

def before_feature_element(feature_element)
  @indent = 2
  @scenario_indent = 2
end

#before_multiline_arg(multiline_arg) ⇒ Object



198
199
200
201
# File 'lib/CucumberTarantulaFormatter.rb', line 198

def before_multiline_arg(multiline_arg)
  return if @options[:no_multiline] || @hide_this_step
  @table = multiline_arg
end

#before_outline_table(outline_table) ⇒ Object



135
136
137
# File 'lib/CucumberTarantulaFormatter.rb', line 135

def before_outline_table(outline_table)
  @table = outline_table
end

#before_step(step) ⇒ Object



151
152
153
154
# File 'lib/CucumberTarantulaFormatter.rb', line 151

def before_step(step)
  @current_step = step
  @indent = 6
end

#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/CucumberTarantulaFormatter.rb', line 156

def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
  @hide_this_step = false
  if exception
    if @exceptions.include?(exception)
      @hide_this_step = true
      return
    end
    @exceptions << exception
    @scenario_exceptions << exception
  end
  if status != :failed && @in_background ^ background
    @hide_this_step = true
    return
  end
  if status == :undefined
    @scenario_undefined = true
  end
  @status = status
end

#before_table_row(table_row) ⇒ Object



207
208
209
210
211
# File 'lib/CucumberTarantulaFormatter.rb', line 207

def before_table_row(table_row)
  return if !@table || @hide_this_step
  @col_index = 0
  @io.print '  |'.indent(@indent-2)
end

#comment_line(comment_line) ⇒ Object



66
67
68
69
# File 'lib/CucumberTarantulaFormatter.rb', line 66

def comment_line(comment_line)
  @io.puts(comment_line.indent(@indent))
  @io.flush
end

#doc_string(string) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/CucumberTarantulaFormatter.rb', line 184

def doc_string(string)
  return if @hide_this_step
  s = %{"""\n#{string}\n"""}.indent(@indent)
  s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n")
  @io.puts(format_string(s, @current_step.status))
  @io.flush
end

#examples_name(keyword, name) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/CucumberTarantulaFormatter.rb', line 124

def examples_name(keyword, name)
  @io.puts unless @visiting_first_example_name
  @visiting_first_example_name = false
  names = name.strip.empty? ? [name.strip] : name.split("\n")
  @io.puts("    #{keyword}: #{names[0]}")
  names[1..-1].each {|s| @io.puts "      #{s}" } unless names.empty?
  @io.flush
  @indent = 6
  @scenario_indent = 6
end

#exception(exception, status) ⇒ Object



192
193
194
195
196
# File 'lib/CucumberTarantulaFormatter.rb', line 192

def exception(exception, status)
  return if @hide_this_step
  print_exception(exception, status, @indent)
  @io.flush
end

#feature_name(keyword, name) ⇒ Object



85
86
87
88
89
90
# File 'lib/CucumberTarantulaFormatter.rb', line 85

def feature_name(keyword, name)
  @feature_name = name
  @io.puts("#{keyword}: #{name}")
  @io.puts
  @io.flush
end

#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object



144
145
146
147
148
149
# File 'lib/CucumberTarantulaFormatter.rb', line 144

def scenario_name(keyword, name, file_colon_line, source_indent)
  @scenario_index += 1
  @scenario_exceptions = []
  @scenario_undefined = false
  print_feature_element_name(keyword, name, file_colon_line, source_indent)
end

#step_name(keyword, step_match, status, source_indent, background, file_colon_line) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/CucumberTarantulaFormatter.rb', line 176

def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
  return if @hide_this_step
  source_indent = nil unless @options[:source]
  name_to_report = format_step(keyword, step_match, status, source_indent)
  @io.puts(name_to_report.indent(@scenario_indent + 2))
  print_messages
end

#table_cell_value(value, status) ⇒ Object



227
228
229
230
231
232
233
234
235
236
# File 'lib/CucumberTarantulaFormatter.rb', line 227

def table_cell_value(value, status)
  return if !@table || @hide_this_step
  status ||= @status || :passed
  width = @table.col_width(@col_index)
  cell_text = escape_cell(value.to_s || '')
  padded = cell_text + (' ' * (width - cell_text.unpack('U*').length))
  prefix = cell_prefix(status)
  @io.print(' ' + format_string("#{prefix}#{padded}", status) + ::Cucumber::Term::ANSIColor.reset(" |"))
  @io.flush
end

#tag_name(tag_name) ⇒ Object



78
79
80
81
82
83
# File 'lib/CucumberTarantulaFormatter.rb', line 78

def tag_name(tag_name)
  tag = format_string(tag_name, :tag).indent(@indent)
  @io.print(tag)
  @io.flush
  @indent = 1
end