cucumber 4.1.0 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +134 -21
  3. data/VERSION +1 -0
  4. data/lib/cucumber/cli/configuration.rb +27 -2
  5. data/lib/cucumber/cli/main.rb +5 -4
  6. data/lib/cucumber/cli/options.rb +102 -65
  7. data/lib/cucumber/cli/profile_loader.rb +6 -10
  8. data/lib/cucumber/cli/rerun_file.rb +1 -1
  9. data/lib/cucumber/configuration.rb +26 -13
  10. data/lib/cucumber/constantize.rb +1 -1
  11. data/lib/cucumber/deprecate.rb +6 -46
  12. data/lib/cucumber/errors.rb +4 -3
  13. data/lib/cucumber/events/envelope.rb +2 -0
  14. data/lib/cucumber/events/gherkin_source_parsed.rb +2 -0
  15. data/lib/cucumber/events/gherkin_source_read.rb +2 -0
  16. data/lib/cucumber/events/hook_test_step_created.rb +1 -2
  17. data/lib/cucumber/events/step_activated.rb +0 -6
  18. data/lib/cucumber/events/step_definition_registered.rb +0 -5
  19. data/lib/cucumber/events/test_case_created.rb +1 -2
  20. data/lib/cucumber/events/test_case_finished.rb +2 -0
  21. data/lib/cucumber/events/test_case_started.rb +2 -0
  22. data/lib/cucumber/events/test_run_finished.rb +2 -1
  23. data/lib/cucumber/events/test_step_created.rb +1 -2
  24. data/lib/cucumber/events/test_step_finished.rb +2 -0
  25. data/lib/cucumber/events/test_step_started.rb +2 -0
  26. data/lib/cucumber/events/undefined_parameter_type.rb +3 -2
  27. data/lib/cucumber/events.rb +2 -2
  28. data/lib/cucumber/file_specs.rb +2 -1
  29. data/lib/cucumber/filters/activate_steps.rb +1 -0
  30. data/lib/cucumber/filters/retry.rb +20 -1
  31. data/lib/cucumber/filters/tag_limits/verifier.rb +1 -3
  32. data/lib/cucumber/filters/tag_limits.rb +1 -3
  33. data/lib/cucumber/formatter/ansicolor.rb +70 -85
  34. data/lib/cucumber/formatter/ast_lookup.rb +16 -10
  35. data/lib/cucumber/formatter/backtrace_filter.rb +3 -1
  36. data/lib/cucumber/formatter/console.rb +34 -16
  37. data/lib/cucumber/formatter/console_counts.rb +3 -1
  38. data/lib/cucumber/formatter/console_issues.rb +10 -3
  39. data/lib/cucumber/formatter/curl_option_parser.rb +49 -0
  40. data/lib/cucumber/formatter/duration_extractor.rb +1 -0
  41. data/lib/cucumber/formatter/errors.rb +3 -0
  42. data/lib/cucumber/formatter/fail_fast.rb +1 -1
  43. data/lib/cucumber/formatter/fanout.rb +1 -1
  44. data/lib/cucumber/formatter/html.rb +3 -1
  45. data/lib/cucumber/formatter/http_io.rb +10 -136
  46. data/lib/cucumber/formatter/ignore_missing_messages.rb +1 -1
  47. data/lib/cucumber/formatter/interceptor.rb +4 -3
  48. data/lib/cucumber/formatter/io.rb +50 -12
  49. data/lib/cucumber/formatter/io_http_buffer.rb +88 -0
  50. data/lib/cucumber/formatter/json.rb +36 -37
  51. data/lib/cucumber/formatter/junit.rb +29 -9
  52. data/lib/cucumber/formatter/message.rb +3 -2
  53. data/lib/cucumber/formatter/message_builder.rb +32 -16
  54. data/lib/cucumber/formatter/pretty.rb +44 -29
  55. data/lib/cucumber/formatter/progress.rb +2 -1
  56. data/lib/cucumber/formatter/publish_banner_printer.rb +75 -0
  57. data/lib/cucumber/formatter/query/hook_by_test_step.rb +3 -0
  58. data/lib/cucumber/formatter/query/pickle_by_test.rb +2 -0
  59. data/lib/cucumber/formatter/query/pickle_step_by_test_step.rb +2 -0
  60. data/lib/cucumber/formatter/query/step_definitions_by_test_step.rb +2 -0
  61. data/lib/cucumber/formatter/query/test_case_started_by_test_case.rb +4 -0
  62. data/lib/cucumber/formatter/rerun.rb +7 -5
  63. data/lib/cucumber/formatter/steps.rb +6 -3
  64. data/lib/cucumber/formatter/summary.rb +2 -1
  65. data/lib/cucumber/formatter/unicode.rb +7 -7
  66. data/lib/cucumber/formatter/url_reporter.rb +19 -0
  67. data/lib/cucumber/formatter/usage.rb +9 -7
  68. data/lib/cucumber/gherkin/data_table_parser.rb +2 -1
  69. data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +25 -27
  70. data/lib/cucumber/gherkin/steps_parser.rb +1 -1
  71. data/lib/cucumber/glue/dsl.rb +30 -16
  72. data/lib/cucumber/glue/hook.rb +6 -3
  73. data/lib/cucumber/glue/invoke_in_world.rb +5 -5
  74. data/lib/cucumber/glue/proto_world.rb +37 -57
  75. data/lib/cucumber/glue/registry_and_more.rb +31 -12
  76. data/lib/cucumber/glue/registry_wrapper.rb +31 -0
  77. data/lib/cucumber/glue/snippet.rb +4 -2
  78. data/lib/cucumber/glue/step_definition.rb +9 -7
  79. data/lib/cucumber/glue/world_factory.rb +2 -0
  80. data/lib/cucumber/hooks.rb +1 -0
  81. data/lib/cucumber/multiline_argument/data_table/diff_matrices.rb +5 -2
  82. data/lib/cucumber/multiline_argument/data_table.rb +65 -79
  83. data/lib/cucumber/platform.rb +11 -16
  84. data/lib/cucumber/rake/task.rb +22 -17
  85. data/lib/cucumber/rspec/disable_option_parser.rb +6 -3
  86. data/lib/cucumber/rspec/doubles.rb +3 -5
  87. data/lib/cucumber/running_test_case.rb +2 -1
  88. data/lib/cucumber/runtime/for_programming_languages.rb +1 -2
  89. data/lib/cucumber/runtime/meta_message_builder.rb +108 -0
  90. data/lib/cucumber/runtime/support_code.rb +3 -0
  91. data/lib/cucumber/runtime/user_interface.rb +7 -6
  92. data/lib/cucumber/runtime.rb +50 -24
  93. data/lib/cucumber/step_match.rb +7 -11
  94. data/lib/cucumber/step_match_search.rb +3 -2
  95. data/lib/cucumber/term/ansicolor.rb +74 -50
  96. data/lib/cucumber/term/banner.rb +59 -0
  97. data/lib/cucumber.rb +2 -1
  98. data/lib/simplecov_setup.rb +1 -1
  99. metadata +103 -229
  100. data/CHANGELOG.md +0 -2682
  101. data/CONTRIBUTING.md +0 -71
  102. data/lib/autotest/cucumber.rb +0 -8
  103. data/lib/autotest/cucumber_mixin.rb +0 -132
  104. data/lib/autotest/cucumber_rails.rb +0 -8
  105. data/lib/autotest/cucumber_rails_rspec.rb +0 -8
  106. data/lib/autotest/cucumber_rails_rspec2.rb +0 -8
  107. data/lib/autotest/cucumber_rspec.rb +0 -8
  108. data/lib/autotest/cucumber_rspec2.rb +0 -8
  109. data/lib/autotest/discover.rb +0 -13
  110. data/lib/cucumber/core_ext/string.rb +0 -11
  111. data/lib/cucumber/version +0 -1
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'cucumber/formatter/backtrace_filter'
3
5
  require 'cucumber/formatter/query/hook_by_test_step'
@@ -40,20 +42,21 @@ module Cucumber
40
42
  raise 'To be implemented'
41
43
  end
42
44
 
43
- def attach(src, media_type)
45
+ def attach(src, media_type, filename)
44
46
  attachment_data = {
45
47
  test_step_id: @current_test_step_id,
46
48
  test_case_started_id: @current_test_case_started_id,
47
- media_type: media_type
49
+ media_type: media_type,
50
+ file_name: filename
48
51
  }
49
52
 
50
53
  if media_type.start_with?('text/')
51
- attachment_data[:content_encoding] = Cucumber::Messages::Attachment::ContentEncoding::IDENTITY
54
+ attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::IDENTITY
52
55
  attachment_data[:body] = src
53
56
  else
54
57
  body = src.respond_to?(:read) ? src.read : src
55
58
 
56
- attachment_data[:content_encoding] = Cucumber::Messages::Attachment::ContentEncoding::BASE64
59
+ attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::BASE64
57
60
  attachment_data[:body] = Base64.strict_encode64(body)
58
61
  end
59
62
 
@@ -101,7 +104,7 @@ module Cucumber
101
104
  def test_step_to_message(step)
102
105
  return hook_step_to_message(step) if step.hook?
103
106
 
104
- Cucumber::Messages::TestCase::TestStep.new(
107
+ Cucumber::Messages::TestStep.new(
105
108
  id: step.id,
106
109
  pickle_step_id: @pickle_step_by_test_step.pickle_step_id(step),
107
110
  step_definition_ids: @step_definitions_by_test_step.step_definition_ids(step),
@@ -110,7 +113,7 @@ module Cucumber
110
113
  end
111
114
 
112
115
  def hook_step_to_message(step)
113
- Cucumber::Messages::TestCase::TestStep.new(
116
+ Cucumber::Messages::TestStep.new(
114
117
  id: step.id,
115
118
  hook_id: @hook_by_test_step.hook_id(step)
116
119
  )
@@ -118,7 +121,7 @@ module Cucumber
118
121
 
119
122
  def step_match_arguments_lists(step)
120
123
  match_arguments = step_match_arguments(step)
121
- [Cucumber::Messages::TestCase::TestStep::StepMatchArgumentsList.new(
124
+ [Cucumber::Messages::StepMatchArgumentsList.new(
122
125
  step_match_arguments: match_arguments
123
126
  )]
124
127
  rescue Cucumber::Formatter::TestStepUnknownError
@@ -127,21 +130,25 @@ module Cucumber
127
130
 
128
131
  def step_match_arguments(step)
129
132
  @step_definitions_by_test_step.step_match_arguments(step).map do |argument|
130
- Cucumber::Messages::TestCase::TestStep::StepMatchArgumentsList::StepMatchArgument.new(
133
+ Cucumber::Messages::StepMatchArgument.new(
131
134
  group: argument_group_to_message(argument.group),
132
- parameter_type_name: argument.parameter_type.name
135
+ parameter_type_name: parameter_type_name(argument)
133
136
  )
134
137
  end
135
138
  end
136
139
 
137
140
  def argument_group_to_message(group)
138
- Cucumber::Messages::TestCase::TestStep::StepMatchArgumentsList::StepMatchArgument::Group.new(
141
+ Cucumber::Messages::Group.new(
139
142
  start: group.start,
140
143
  value: group.value,
141
144
  children: group.children.map { |child| argument_group_to_message(child) }
142
145
  )
143
146
  end
144
147
 
148
+ def parameter_type_name(step_match_argument)
149
+ step_match_argument.parameter_type&.name if step_match_argument.respond_to?(:parameter_type)
150
+ end
151
+
145
152
  def on_test_run_started(*)
146
153
  message = Cucumber::Messages::Envelope.new(
147
154
  test_run_started: Cucumber::Messages::TestRunStarted.new(
@@ -190,10 +197,13 @@ module Cucumber
190
197
 
191
198
  result_message = result.to_message
192
199
  if result.failed? || result.pending?
193
- result_message = Cucumber::Messages::TestStepFinished::TestStepResult.new(
200
+ message_element = result.failed? ? result.exception : result
201
+
202
+ result_message = Cucumber::Messages::TestStepResult.new(
194
203
  status: result_message.status,
195
204
  duration: result_message.duration,
196
- message: create_error_message(result)
205
+ message: create_error_message(message_element),
206
+ exception: create_exception_object(result, message_element)
197
207
  )
198
208
  end
199
209
 
@@ -209,12 +219,17 @@ module Cucumber
209
219
  output_envelope(message)
210
220
  end
211
221
 
212
- def create_error_message(result)
213
- message_element = result.failed? ? result.exception : result
222
+ def create_error_message(message_element)
214
223
  message = "#{message_element.message} (#{message_element.class})"
215
224
  ([message] + message_element.backtrace).join("\n")
216
225
  end
217
226
 
227
+ def create_exception_object(result, message_element)
228
+ return unless result.failed?
229
+
230
+ Cucumber::Messages::Exception.from_h({ type: message_element.class, message: message_element.message })
231
+ end
232
+
218
233
  def on_test_case_finished(event)
219
234
  message = Cucumber::Messages::Envelope.new(
220
235
  test_case_finished: Cucumber::Messages::TestCaseFinished.new(
@@ -226,10 +241,11 @@ module Cucumber
226
241
  output_envelope(message)
227
242
  end
228
243
 
229
- def on_test_run_finished(*)
244
+ def on_test_run_finished(event)
230
245
  message = Cucumber::Messages::Envelope.new(
231
246
  test_run_finished: Cucumber::Messages::TestRunFinished.new(
232
- timestamp: time_to_timestamp(Time.now)
247
+ timestamp: time_to_timestamp(Time.now),
248
+ success: event.success
233
249
  )
234
250
  )
235
251
 
@@ -19,20 +19,18 @@ module Cucumber
19
19
  #
20
20
  # If the output is STDOUT (and not a file), there are bright colours to watch too.
21
21
  #
22
- class Pretty # rubocop:disable Metrics/ClassLength
22
+ class Pretty
23
23
  include FileUtils
24
24
  include Console
25
25
  include Io
26
26
  include Cucumber::Gherkin::Formatter::Escaping
27
- attr_reader :config, :options
27
+ attr_reader :config, :options, :current_feature_uri, :current_scenario_outline, :current_examples, :current_test_case, :in_scenario_outline, :print_background_steps
28
28
  private :config, :options
29
- attr_reader :current_feature_uri, :current_scenario_outline, :current_examples, :current_test_case
30
29
  private :current_feature_uri, :current_scenario_outline, :current_examples, :current_test_case
31
- attr_reader :in_scenario_outline, :print_background_steps
32
30
  private :in_scenario_outline, :print_background_steps
33
31
 
34
32
  def initialize(config)
35
- @io = ensure_io(config.out_stream)
33
+ @io = ensure_io(config.out_stream, config.error_stream)
36
34
  @config = config
37
35
  @options = config.to_hash
38
36
  @snippets_input = []
@@ -105,16 +103,19 @@ module Cucumber
105
103
 
106
104
  def on_test_step_started(event)
107
105
  return if event.test_step.hook?
106
+
108
107
  print_step_header(current_test_case) if first_step_after_printing_background_steps?(event.test_step)
109
108
  end
110
109
 
111
110
  def on_test_step_finished(event)
112
111
  collect_snippet_data(event.test_step, @ast_lookup) if event.result.undefined?
113
112
  return if in_scenario_outline && !options[:expand]
113
+
114
114
  exception_to_be_printed = find_exception_to_be_printed(event.result)
115
115
  print_step_data(event.test_step, event.result) if print_step_data?(event, exception_to_be_printed)
116
116
  print_step_output
117
117
  return unless exception_to_be_printed
118
+
118
119
  print_exception(exception_to_be_printed, event.result.to_sym, 6)
119
120
  @exceptions << exception_to_be_printed
120
121
  end
@@ -127,6 +128,7 @@ module Cucumber
127
128
  else
128
129
  exception_to_be_printed = find_exception_to_be_printed(event.result)
129
130
  return unless exception_to_be_printed
131
+
130
132
  print_exception(exception_to_be_printed, event.result.to_sym, 6)
131
133
  @exceptions << exception_to_be_printed
132
134
  end
@@ -138,18 +140,25 @@ module Cucumber
138
140
  print_summary
139
141
  end
140
142
 
141
- def attach(src, media_type)
143
+ def attach(src, media_type, filename)
142
144
  return unless media_type == 'text/x.cucumber.log+plain'
143
- @test_step_output.push src
145
+
146
+ if filename
147
+ @test_step_output.push("#{filename}: #{src}")
148
+ else
149
+ @test_step_output.push(src)
150
+ end
144
151
  end
145
152
 
146
153
  private
147
154
 
148
155
  def find_exception_to_be_printed(result)
149
- return nil if result.ok?(options[:strict])
156
+ return nil if result.ok?(strict: options[:strict])
157
+
150
158
  result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
151
159
  exception = result.failed? ? result.exception : result
152
160
  return nil if @exceptions.include?(exception)
161
+
153
162
  exception
154
163
  end
155
164
 
@@ -181,7 +190,7 @@ module Cucumber
181
190
  end
182
191
 
183
192
  def print_step_output
184
- @test_step_output.each { |message| @io.puts(format_string(message, :tag).indent(6)) }
193
+ @test_step_output.each { |message| @io.puts(indent(format_string(message, :tag), 6)) }
185
194
  @test_step_output = []
186
195
  end
187
196
 
@@ -196,6 +205,7 @@ module Cucumber
196
205
  def feature_has_background?
197
206
  feature_children = gherkin_document.feature.children
198
207
  return false if feature_children.empty?
208
+
199
209
  !feature_children.first.background.nil?
200
210
  end
201
211
 
@@ -239,6 +249,7 @@ module Cucumber
239
249
  def first_step_after_printing_background_steps?(test_step)
240
250
  return false unless print_background_steps
241
251
  return false unless test_step.location.lines.max >= current_test_case.location.lines.max
252
+
242
253
  @print_background_steps = false
243
254
  true
244
255
  end
@@ -259,33 +270,35 @@ module Cucumber
259
270
  end
260
271
  end
261
272
 
262
- def print_comments(up_to_line, indent)
273
+ def print_comments(up_to_line, indent_amount)
263
274
  comments = gherkin_document.comments
264
275
  return if comments.empty? || comments.length <= @next_comment_to_be_printed
265
- comments[@next_comment_to_be_printed..-1].each do |comment|
276
+
277
+ comments[@next_comment_to_be_printed..].each do |comment|
266
278
  if comment.location.line <= up_to_line
267
- @io.puts(format_string(comment.text.strip, :comment).indent(indent))
279
+ @io.puts(indent(format_string(comment.text.strip, :comment), indent_amount))
268
280
  @next_comment_to_be_printed += 1
269
281
  end
270
282
  break if @next_comment_to_be_printed >= comments.length
271
283
  end
272
284
  end
273
285
 
274
- def print_tags(tags, indent)
286
+ def print_tags(tags, indent_amount)
275
287
  return if !tags || tags.empty?
276
- @io.puts(tags.map { |tag| format_string(tag.name, :tag) }.join(' ').indent(indent))
288
+
289
+ @io.puts(indent(tags.map { |tag| format_string(tag.name, :tag) }.join(' '), indent_amount))
277
290
  end
278
291
 
279
292
  def print_feature_line(feature)
280
293
  print_keyword_name(feature.keyword, feature.name, 0)
281
294
  end
282
295
 
283
- def print_keyword_name(keyword, name, indent, location = nil)
296
+ def print_keyword_name(keyword, name, indent_amount, location = nil)
284
297
  line = "#{keyword}:"
285
298
  line += " #{name}"
286
- @io.print(line.indent(indent))
299
+ @io.print(indent(line, indent_amount))
287
300
  if location && options[:source]
288
- line_comment = format_string("# #{location}", :comment).indent(@source_indent - line.length - indent)
301
+ line_comment = indent(format_string("# #{location}", :comment), @source_indent - line.length - indent_amount)
289
302
  @io.print(line_comment)
290
303
  end
291
304
  @io.puts
@@ -293,6 +306,7 @@ module Cucumber
293
306
 
294
307
  def print_description(description)
295
308
  return unless description
309
+
296
310
  description.split("\n").each do |line|
297
311
  @io.puts(line)
298
312
  end
@@ -339,7 +353,7 @@ module Cucumber
339
353
  indent = options[:source] ? @source_indent - step_keyword.length - test_step.text.length - base_indent : nil
340
354
  print_comments(test_step.location.lines.max, base_indent)
341
355
  name_to_report = format_step(step_keyword, @step_matches.fetch(test_step.to_s) { NoStepMatch.new(test_step, test_step.text) }, result.to_sym, indent)
342
- @io.puts(name_to_report.indent(base_indent))
356
+ @io.puts(indent(name_to_report, base_indent))
343
357
  print_multiline_argument(test_step, result, base_indent + 2) unless options[:no_multiline]
344
358
  @io.flush
345
359
  end
@@ -374,14 +388,14 @@ module Cucumber
374
388
  end
375
389
  end
376
390
 
377
- def print_data_table(data_table, status, indent)
391
+ def print_data_table(data_table, status, indent_amount)
378
392
  data_table.rows.each do |row|
379
- print_comments(row.location.line, indent)
380
- @io.puts format_string(gherkin_source.split("\n")[row.location.line - 1].strip, status).indent(indent)
393
+ print_comments(row.location.line, indent_amount)
394
+ @io.puts indent(format_string(gherkin_source.split("\n")[row.location.line - 1].strip, status), indent_amount)
381
395
  end
382
396
  end
383
397
 
384
- def print_outline_data(scenario_outline) # rubocop:disable Metrics/AbcSize
398
+ def print_outline_data(scenario_outline)
385
399
  print_comments(scenario_outline.location.line, 2)
386
400
  print_tags(scenario_outline.tags, 2)
387
401
  @source_indent = calculate_source_indent_for_ast_node(scenario_outline) if options[:source]
@@ -393,18 +407,19 @@ module Cucumber
393
407
  @io.print(format_string(step_line, :skipped))
394
408
  if options[:source]
395
409
  comment_line = format_string("# #{current_feature_uri}:#{step.location.line}", :comment)
396
- @io.print(comment_line.indent(@source_indent - step_line.length))
410
+ @io.print(indent(comment_line, @source_indent - step_line.length))
397
411
  end
398
412
  @io.puts
399
413
  next if options[:no_multiline]
414
+
400
415
  print_doc_string(step.doc_string.content, :skipped, 6) unless step.doc_string.nil?
401
416
  print_data_table(step.data_table, :skipped, 6) unless step.data_table.nil?
402
417
  end
403
418
  @io.flush
404
419
  end
405
420
 
406
- def print_doc_string(content, status, indent)
407
- s = %("""\n#{content}\n""").indent(indent)
421
+ def print_doc_string(content, status, indent_amount)
422
+ s = indent(%("""\n#{content}\n"""), indent_amount)
408
423
  s = s.split("\n").map { |l| l =~ /^\s+$/ ? '' : l }.join("\n")
409
424
  @io.puts(format_string(s, status))
410
425
  end
@@ -416,15 +431,15 @@ module Cucumber
416
431
  print_description(examples.description)
417
432
  unless options[:expand]
418
433
  print_comments(examples.table_header.location.line, 6)
419
- @io.puts(gherkin_source.split("\n")[examples.table_header.location.line - 1].strip.indent(6))
434
+ @io.puts(indent(gherkin_source.split("\n")[examples.table_header.location.line - 1].strip, 6))
420
435
  end
421
436
  @io.flush
422
437
  end
423
438
 
424
439
  def print_row_data(test_case, result)
425
440
  print_comments(test_case.location.lines.max, 6)
426
- @io.print(format_string(gherkin_source.split("\n")[test_case.location.lines.max - 1].strip, result.to_sym).indent(6))
427
- @io.print(format_string(@test_step_output.join(', '), :tag).indent(2)) unless @test_step_output.empty?
441
+ @io.print(indent(format_string(gherkin_source.split("\n")[test_case.location.lines.max - 1].strip, result.to_sym), 6))
442
+ @io.print(indent(format_string(@test_step_output.join(', '), :tag), 2)) unless @test_step_output.empty?
428
443
  @test_step_output = []
429
444
  @io.puts
430
445
  if result.failed? || result.pending?
@@ -444,7 +459,7 @@ module Cucumber
444
459
  language = ::Gherkin::Dialect.for(language_code)
445
460
  scenario_keyword = language.scenario_keywords[0]
446
461
  row = scenario_source(test_case).row
447
- expanded_name = '| ' + row.cells.map(&:value).join(' | ') + ' |'
462
+ expanded_name = "| #{row.cells.map(&:value).join(' | ')} |"
448
463
  @source_indent = calculate_source_indent_for_expanded_test_case(test_case, scenario_keyword, expanded_name)
449
464
  @io.puts
450
465
  print_keyword_name(scenario_keyword, expanded_name, 6, test_case.location)
@@ -19,7 +19,7 @@ module Cucumber
19
19
 
20
20
  def initialize(config)
21
21
  @config = config
22
- @io = ensure_io(config.out_stream)
22
+ @io = ensure_io(config.out_stream, config.error_stream)
23
23
  @snippets_input = []
24
24
  @undefined_parameter_types = []
25
25
  @total_duration = 0
@@ -58,6 +58,7 @@ module Cucumber
58
58
  progress(result.to_sym) if !test_step.hook? || result.failed?
59
59
 
60
60
  return if test_step.hook?
61
+
61
62
  collect_snippet_data(test_step, @ast_lookup) if result.undefined?
62
63
  @pending_step_matches << @matches[test_step.to_s] if result.pending?
63
64
  @failed_results << result if result.failed?
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cucumber/term/banner'
4
+
5
+ module Cucumber
6
+ module Formatter
7
+ class PublishBannerPrinter
8
+ include Term::Banner
9
+
10
+ def initialize(configuration)
11
+ return if configuration.publish_enabled?
12
+
13
+ configuration.on_event :test_run_finished do |_event|
14
+ display_publish_ad(configuration.error_stream)
15
+ end
16
+ end
17
+
18
+ def display_publish_ad(io)
19
+ display_banner(
20
+ [
21
+ [
22
+ 'Share your Cucumber Report with your team at ',
23
+ link('https://reports.cucumber.io')
24
+ ],
25
+ '',
26
+ [
27
+ 'Command line option: ',
28
+ highlight('--publish')
29
+ ],
30
+ [
31
+ 'Environment variable: ',
32
+ highlight('CUCUMBER_PUBLISH_ENABLED'),
33
+ '=',
34
+ highlight('true')
35
+ ],
36
+ [
37
+ 'cucumber.yml: ',
38
+ highlight('default: --publish')
39
+ ],
40
+ '',
41
+ [
42
+ 'More information at ',
43
+ link('https://cucumber.io/docs/cucumber/environment-variables/')
44
+ ],
45
+ '',
46
+ [
47
+ 'To disable this message, specify ',
48
+ pre('CUCUMBER_PUBLISH_QUIET=true'),
49
+ ' or use the '
50
+ ],
51
+ [
52
+ pre('--publish-quiet'),
53
+ ' option. You can also add this to your ',
54
+ pre('cucumber.yml:')
55
+ ],
56
+ [pre('default: --publish-quiet')]
57
+ ],
58
+ io
59
+ )
60
+ end
61
+
62
+ def highlight(text)
63
+ [text, :cyan]
64
+ end
65
+
66
+ def link(text)
67
+ [text, :cyan, :bold, :underline]
68
+ end
69
+
70
+ def pre(text)
71
+ [text, :bold]
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/formatter/errors'
2
4
 
3
5
  module Cucumber
@@ -13,6 +15,7 @@ module Cucumber
13
15
 
14
16
  def hook_id(test_step)
15
17
  return @hook_id_by_test_step_id[test_step.id] if @hook_id_by_test_step_id.key?(test_step.id)
18
+
16
19
  raise TestStepUnknownError, "No hook found for #{test_step.id} }. Known: #{@hook_id_by_test_step_id.keys}"
17
20
  end
18
21
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/formatter/errors'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/formatter/errors'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/formatter/errors'
2
4
 
3
5
  module Cucumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/formatter/errors'
2
4
 
3
5
  module Cucumber
@@ -15,11 +17,13 @@ module Cucumber
15
17
 
16
18
  def attempt_by_test_case(test_case)
17
19
  raise TestCaseUnknownError, "No test case found for #{test_case.id} }. Known: #{@attempts_by_test_case_id.keys}" unless @attempts_by_test_case_id.key?(test_case.id)
20
+
18
21
  @attempts_by_test_case_id[test_case.id]
19
22
  end
20
23
 
21
24
  def test_case_started_id_by_test_case(test_case)
22
25
  raise TestCaseUnknownError, "No test case found for #{test_case.id} }. Known: #{@test_case_started_id_by_test_case_id.keys}" unless @test_case_started_id_by_test_case_id.key?(test_case.id)
26
+
23
27
  @test_case_started_id_by_test_case_id[test_case.id]
24
28
  end
25
29
 
@@ -7,30 +7,32 @@ module Cucumber
7
7
  class Rerun
8
8
  include Formatter::Io
9
9
 
10
- def initialize(config) # rubocop:disable Metrics/PerceivedComplexity
11
- @io = ensure_io(config.out_stream)
10
+ def initialize(config)
11
+ @io = ensure_io(config.out_stream, config.error_stream)
12
12
  @config = config
13
13
  @failures = {}
14
14
  config.on_event :test_case_finished do |event|
15
15
  test_case, result = *event.attributes
16
16
  if @config.strict.strict?(:flaky)
17
- next if result.ok?(@config.strict)
17
+ next if result.ok?(strict: @config.strict)
18
+
18
19
  add_to_failures(test_case)
19
20
  else
20
21
  unless @latest_failed_test_case.nil?
21
22
  if @latest_failed_test_case != test_case
22
23
  add_to_failures(@latest_failed_test_case)
23
24
  @latest_failed_test_case = nil
24
- elsif result.ok?(@config.strict)
25
+ elsif result.ok?(strict: @config.strict)
25
26
  @latest_failed_test_case = nil
26
27
  end
27
28
  end
28
- @latest_failed_test_case = test_case unless result.ok?(@config.strict)
29
+ @latest_failed_test_case = test_case unless result.ok?(strict: @config.strict)
29
30
  end
30
31
  end
31
32
  config.on_event :test_run_finished do
32
33
  add_to_failures(@latest_failed_test_case) unless @latest_failed_test_case.nil?
33
34
  next if @failures.empty?
35
+
34
36
  @io.print file_failures.join("\n")
35
37
  end
36
38
  end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cucumber/formatter/console'
4
+
3
5
  module Cucumber
4
6
  module Formatter
5
7
  # The formatter used for <tt>--format steps</tt>
6
8
  class Steps
9
+ include Console
7
10
  def initialize(runtime, path_or_io, options)
8
- @io = ensure_io(path_or_io)
11
+ @io = ensure_io(path_or_io, nil)
9
12
  @options = options
10
13
  @step_definition_files = collect_steps(runtime)
11
14
  end
@@ -24,8 +27,8 @@ module Cucumber
24
27
  sources = @step_definition_files[step_definition_file]
25
28
  source_indent = source_indent(sources)
26
29
  sources.sort.each do |file_colon_line, regexp_source|
27
- @io.print regexp_source.indent(2)
28
- @io.print " # #{file_colon_line}".indent(source_indent - regexp_source.unpack('U*').length)
30
+ @io.print indent(regexp_source, 2)
31
+ @io.print indent(" # #{file_colon_line}", source_indent - regexp_source.unpack('U*').length)
29
32
  @io.puts
30
33
  end
31
34
  @io.puts
@@ -16,7 +16,7 @@ module Cucumber
16
16
 
17
17
  def initialize(config)
18
18
  @config = config
19
- @io = ensure_io(config.out_stream)
19
+ @io = ensure_io(config.out_stream, config.error_stream)
20
20
  @ast_lookup = AstLookup.new(config)
21
21
  @counts = ConsoleCounts.new(@config)
22
22
  @issues = ConsoleIssues.new(@config, @ast_lookup)
@@ -47,6 +47,7 @@ module Cucumber
47
47
  def print_feature(test_case)
48
48
  uri = test_case.location.file
49
49
  return if @current_feature_uri == uri
50
+
50
51
  feature_name = gherkin_document(uri).feature.name
51
52
  @io.puts unless @current_feature_uri.nil?
52
53
  @io.puts feature_name
@@ -10,14 +10,14 @@ if Cucumber::WINDOWS
10
10
  Cucumber::CODEPAGE = ENV['CUCUMBER_OUTPUT_ENCODING']
11
11
  elsif `cmd /c chcp` =~ /(\d+)/
12
12
  if [65_000, 65_001].include? Regexp.last_match(1).to_i
13
- Cucumber::CODEPAGE = 'UTF-8'.freeze
13
+ Cucumber::CODEPAGE = 'UTF-8'
14
14
  ENV['ANSICON_API'] = 'ruby'
15
15
  else
16
- Cucumber::CODEPAGE = "cp#{Regexp.last_match(1).to_i}".freeze
16
+ Cucumber::CODEPAGE = "cp#{Regexp.last_match(1).to_i}"
17
17
  end
18
18
  else
19
- Cucumber::CODEPAGE = 'cp1252'.freeze
20
- STDERR.puts("WARNING: Couldn't detect your output codepage. Assuming it is 1252. You may have to chcp 1252 or SET CUCUMBER_OUTPUT_ENCODING=cp1252.")
19
+ Cucumber::CODEPAGE = 'cp1252'
20
+ $stderr.puts("WARNING: Couldn't detect your output codepage. Assuming it is 1252. You may have to chcp 1252 or SET CUCUMBER_OUTPUT_ENCODING=cp1252.")
21
21
  end
22
22
 
23
23
  module Cucumber
@@ -28,7 +28,7 @@ if Cucumber::WINDOWS
28
28
  def cucumber_preprocess_output(*out)
29
29
  out.map { |arg| arg.to_s.encode(Encoding.default_external) }
30
30
  rescue Encoding::UndefinedConversionError => e
31
- STDERR.cucumber_puts("WARNING: #{e.message}")
31
+ $stderr.cucumber_puts("WARNING: #{e.message}")
32
32
  out
33
33
  end
34
34
 
@@ -45,8 +45,8 @@ if Cucumber::WINDOWS
45
45
  end
46
46
 
47
47
  Kernel.extend(self)
48
- STDOUT.extend(self)
49
- STDERR.extend(self)
48
+ $stdout.extend(self)
49
+ $stderr.extend(self)
50
50
  end
51
51
  end
52
52
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cucumber
4
+ module Formatter
5
+ class URLReporter
6
+ def initialize(io)
7
+ @io = io
8
+ end
9
+
10
+ def report(banner)
11
+ @io.puts(banner)
12
+ end
13
+ end
14
+
15
+ class NoReporter
16
+ def report(_banner); end
17
+ end
18
+ end
19
+ end