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,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'cucumber/step_match'
4
- require 'cucumber/core_ext/string'
5
4
  require 'cucumber/glue/invoke_in_world'
6
5
 
7
6
  module Cucumber
@@ -26,6 +25,7 @@ module Cucumber
26
25
  class << self
27
26
  def new(id, registry, string_or_regexp, proc_or_sym, options)
28
27
  raise MissingProc if proc_or_sym.nil?
28
+
29
29
  super id, registry, registry.create_expression(string_or_regexp), create_proc(proc_or_sym, options)
30
30
  end
31
31
 
@@ -34,6 +34,7 @@ module Cucumber
34
34
  def create_proc(proc_or_sym, options)
35
35
  return proc_or_sym if proc_or_sym.is_a?(Proc)
36
36
  raise ArgumentError unless proc_or_sym.is_a?(Symbol)
37
+
37
38
  message = proc_or_sym
38
39
  target_proc = parse_target_proc_from(options)
39
40
  patch_location_onto lambda { |*args|
@@ -50,6 +51,7 @@ module Cucumber
50
51
 
51
52
  def parse_target_proc_from(options)
52
53
  return -> { self } unless options.key?(:on)
54
+
53
55
  target = options[:on]
54
56
  case target
55
57
  when Proc
@@ -66,6 +68,7 @@ module Cucumber
66
68
 
67
69
  def initialize(id, registry, expression, proc)
68
70
  raise 'No regexp' if expression.is_a?(Regexp)
71
+
69
72
  @id = id
70
73
  @registry = registry
71
74
  @expression = expression
@@ -77,7 +80,7 @@ module Cucumber
77
80
  Cucumber::Messages::Envelope.new(
78
81
  step_definition: Cucumber::Messages::StepDefinition.new(
79
82
  id: id,
80
- pattern: Cucumber::Messages::StepDefinition::StepDefinitionPattern.new(
83
+ pattern: Cucumber::Messages::StepDefinitionPattern.new(
81
84
  source: expression.source.to_s,
82
85
  type: expression_type
83
86
  ),
@@ -92,8 +95,9 @@ module Cucumber
92
95
  end
93
96
 
94
97
  def expression_type
95
- return Cucumber::Messages::StepDefinition::StepDefinitionPattern::StepDefinitionPatternType::CUCUMBER_EXPRESSION if expression.is_a?(CucumberExpressions::CucumberExpression)
96
- Cucumber::Messages::StepDefinition::StepDefinitionPattern::StepDefinitionPatternType::REGULAR_EXPRESSION
98
+ return Cucumber::Messages::StepDefinitionPatternType::CUCUMBER_EXPRESSION if expression.is_a?(CucumberExpressions::CucumberExpression)
99
+
100
+ Cucumber::Messages::StepDefinitionPatternType::REGULAR_EXPRESSION
97
101
  end
98
102
 
99
103
  # @api private
@@ -123,9 +127,7 @@ module Cucumber
123
127
 
124
128
  # @api private
125
129
  def arguments_from(step_name)
126
- args = @expression.match(step_name)
127
- # @registry.invoked_step_definition(regexp_source, location) if args
128
- args
130
+ @expression.match(step_name)
129
131
  end
130
132
 
131
133
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  module Glue
3
5
  class WorldFactory
@@ -19,6 +19,7 @@ module Cucumber
19
19
 
20
20
  def after_step_hook(id, test_step, location, &block)
21
21
  raise ArgumentError if test_step.hook?
22
+
22
23
  build_hook_step(id, location, block, AfterStepHook, Core::Test::Action)
23
24
  end
24
25
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  module MultilineArgument
3
5
  class DataTable
4
- class DiffMatrices #:nodoc:
6
+ class DiffMatrices # :nodoc:
5
7
  attr_accessor :cell_matrix, :other_table_cell_matrix, :options
6
8
 
7
9
  def initialize(cell_matrix, other_table_cell_matrix, options)
@@ -95,7 +97,7 @@ module Cucumber
95
97
  def changes
96
98
  require 'diff/lcs'
97
99
  diffable_cell_matrix = cell_matrix.dup.extend(::Diff::LCS)
98
- diffable_cell_matrix.diff(other_table_cell_matrix).flatten
100
+ diffable_cell_matrix.diff(other_table_cell_matrix).flatten(1)
99
101
  end
100
102
 
101
103
  def inspect_rows(missing_row, inserted_row)
@@ -113,6 +115,7 @@ module Cucumber
113
115
  row_index = row_indices.index(i)
114
116
  row = cell_matrix[row_index] if row_index
115
117
  next unless row
118
+
116
119
  (original_width..padded_width).each do |col_index|
117
120
  surplus_cell = other_row[col_index]
118
121
  row[col_index].value = surplus_cell.value if row[col_index]
@@ -27,7 +27,7 @@ module Cucumber
27
27
  # This will store <tt>[['a', 'b'], ['c', 'd']]</tt> in the <tt>data</tt> variable.
28
28
  #
29
29
  class DataTable
30
- def self.default_arg_name #:nodoc:
30
+ def self.default_arg_name
31
31
  'table'
32
32
  end
33
33
 
@@ -78,11 +78,12 @@ module Cucumber
78
78
  NULL_CONVERSIONS = Hash.new(strict: false, proc: ->(cell_value) { cell_value }).freeze
79
79
 
80
80
  # @param data [Core::Test::DataTable] the data for the table
81
- # @param conversion_procs [Hash] see map_columns!
82
- # @param header_mappings [Hash] see map_headers!
83
- # @param header_conversion_proc [Proc] see map_headers!
81
+ # @param conversion_procs [Hash] see map_column
82
+ # @param header_mappings [Hash] see map_headers
83
+ # @param header_conversion_proc [Proc] see map_headers
84
84
  def initialize(data, conversion_procs = NULL_CONVERSIONS.dup, header_mappings = {}, header_conversion_proc = nil)
85
85
  raise ArgumentError, 'data must be a Core::Test::DataTable' unless data.is_a? Core::Test::DataTable
86
+
86
87
  ast_table = data
87
88
  # Verify that it's square
88
89
  ast_table.transpose
@@ -107,13 +108,6 @@ module Cucumber
107
108
  @ast_table.location
108
109
  end
109
110
 
110
- # Creates a copy of this table, inheriting any column and header mappings
111
- # registered with #map_column! and #map_headers!.
112
- #
113
- def dup
114
- self.class.new(Core::Test::DataTable.new(raw), @conversion_procs.dup, @header_mappings.dup, @header_conversion_proc)
115
- end
116
-
117
111
  # Returns a new, transposed table. Example:
118
112
  #
119
113
  # | a | 7 | 4 |
@@ -141,7 +135,7 @@ module Cucumber
141
135
  #
142
136
  # [{'a' => '2', 'b' => '3', 'sum' => '5'}, {'a' => '7', 'b' => '9', 'sum' => '16'}]
143
137
  #
144
- # Use #map_column! to specify how values in a column are converted.
138
+ # Use #map_column to specify how values in a column are converted.
145
139
  #
146
140
  def hashes
147
141
  @hashes ||= build_hashes
@@ -161,7 +155,7 @@ module Cucumber
161
155
  def symbolic_hashes
162
156
  @symbolic_hashes ||=
163
157
  hashes.map do |string_hash|
164
- Hash[string_hash.map { |a, b| [symbolize_key(a), b] }]
158
+ string_hash.transform_keys { |a| symbolize_key(a) }
165
159
  end
166
160
  end
167
161
 
@@ -179,6 +173,7 @@ module Cucumber
179
173
  #
180
174
  def rows_hash
181
175
  return @rows_hash if @rows_hash
176
+
182
177
  verify_table_width(2)
183
178
  @rows_hash = transpose.hashes[0]
184
179
  end
@@ -199,17 +194,17 @@ module Cucumber
199
194
  end
200
195
  end
201
196
 
202
- def column_names #:nodoc:
197
+ def column_names
203
198
  @column_names ||= cell_matrix[0].map(&:value)
204
199
  end
205
200
 
206
201
  def rows
207
202
  hashes.map do |hash|
208
- hash.values_at *headers
203
+ hash.values_at(*headers)
209
204
  end
210
205
  end
211
206
 
212
- def each_cells_row(&proc) #:nodoc:
207
+ def each_cells_row(&proc)
213
208
  cells_rows.each(&proc)
214
209
  end
215
210
 
@@ -228,7 +223,8 @@ module Cucumber
228
223
  pattern.match(header_to_match)
229
224
  end
230
225
 
231
- # Redefines the table headers. This makes it possible to use
226
+ # Returns a new Table where the headers are redefined.
227
+ # This makes it possible to use
232
228
  # prettier and more flexible header names in the features. The
233
229
  # keys of +mappings+ are Strings or regular expressions
234
230
  # (anything that responds to #=== will work) that may match
@@ -244,54 +240,41 @@ module Cucumber
244
240
  # A StepDefinition receiving this table can then map the columns
245
241
  # with both Regexp and String:
246
242
  #
247
- # table.map_headers!(/phone( number)?/i => :phone, 'Address' => :address)
243
+ # table.map_headers(/phone( number)?/i => :phone, 'Address' => :address)
248
244
  # table.hashes
249
245
  # # => [{:phone => '123456', :address => 'xyz'}, {:phone => '345678', :address => 'abc'}]
250
246
  #
251
247
  # You may also pass in a block if you wish to convert all of the headers:
252
248
  #
253
- # table.map_headers! { |header| header.downcase }
249
+ # table.map_headers { |header| header.downcase }
254
250
  # table.hashes.keys
255
251
  # # => ['phone number', 'address']
256
252
  #
257
253
  # When a block is passed in along with a hash then the mappings in the hash take precendence:
258
254
  #
259
- # table.map_headers!('Address' => 'ADDRESS') { |header| header.downcase }
255
+ # table.map_headers('Address' => 'ADDRESS') { |header| header.downcase }
260
256
  # table.hashes.keys
261
257
  # # => ['phone number', 'ADDRESS']
262
258
  #
263
- def map_headers!(mappings = {}, &block)
264
- # TODO: Remove this method for 2.0
265
- clear_cache!
266
- @header_mappings = mappings
267
- @header_conversion_proc = block
268
- end
269
-
270
- # Returns a new Table where the headers are redefined. See #map_headers!
271
259
  def map_headers(mappings = {}, &block)
272
260
  self.class.new(Core::Test::DataTable.new(raw), @conversion_procs.dup, mappings, block)
273
261
  end
274
262
 
263
+ # Returns a new Table with an additional column mapping.
264
+ #
275
265
  # Change how #hashes converts column values. The +column_name+ argument identifies the column
276
266
  # and +conversion_proc+ performs the conversion for each cell in that column. If +strict+ is
277
267
  # true, an error will be raised if the column named +column_name+ is not found. If +strict+
278
268
  # is false, no error will be raised. Example:
279
269
  #
280
270
  # Given /^an expense report for (.*) with the following posts:$/ do |table|
281
- # posts_table.map_column!('amount') { |a| a.to_i }
271
+ # posts_table = posts_table.map_column('amount') { |a| a.to_i }
282
272
  # posts_table.hashes.each do |post|
283
273
  # # post['amount'] is a Fixnum, rather than a String
284
274
  # end
285
275
  # end
286
276
  #
287
- def map_column!(column_name, strict = true, &conversion_proc)
288
- # TODO: Remove this method for 2.0
289
- @conversion_procs[column_name.to_s] = { strict: strict, proc: conversion_proc }
290
- self
291
- end
292
-
293
- # Returns a new Table with an additional column mapping. See #map_column!
294
- def map_column(column_name, strict = true, &conversion_proc)
277
+ def map_column(column_name, strict: true, &conversion_proc)
295
278
  conversion_procs = @conversion_procs.dup
296
279
  conversion_procs[column_name.to_s] = { strict: strict, proc: conversion_proc }
297
280
  self.class.new(Core::Test::DataTable.new(raw), conversion_procs, @header_mappings.dup, @header_conversion_proc)
@@ -312,8 +295,8 @@ module Cucumber
312
295
  # where the difference actually is.
313
296
  #
314
297
  # Since all tables that are passed to StepDefinitions always have String
315
- # objects in their cells, you may want to use #map_column! before calling
316
- # #diff!. You can use #map_column! on either of the tables.
298
+ # objects in their cells, you may want to use #map_column before calling
299
+ # #diff!. You can use #map_column on either of the tables.
317
300
  #
318
301
  # A Different error is raised if there are missing rows or columns, or
319
302
  # surplus rows. An error is <em>not</em> raised for surplus columns. An
@@ -346,6 +329,7 @@ module Cucumber
346
329
 
347
330
  class Different < StandardError
348
331
  attr_reader :table
332
+
349
333
  def initialize(table)
350
334
  @table = table
351
335
  super("Tables were not identical:\n#{table}")
@@ -356,7 +340,7 @@ module Cucumber
356
340
  cells_rows.map { |cells| cells.map(&:value) }
357
341
  end
358
342
 
359
- def cells_to_hash(cells) #:nodoc:
343
+ def cells_to_hash(cells)
360
344
  hash = Hash.new do |hash_inner, key|
361
345
  hash_inner[key.to_s] if key.is_a?(Symbol)
362
346
  end
@@ -366,51 +350,51 @@ module Cucumber
366
350
  hash
367
351
  end
368
352
 
369
- def index(cells) #:nodoc:
353
+ def index(cells)
370
354
  cells_rows.index(cells)
371
355
  end
372
356
 
373
- def verify_column(column_name) #:nodoc:
357
+ def verify_column(column_name)
374
358
  raise %(The column named "#{column_name}" does not exist) unless raw[0].include?(column_name)
375
359
  end
376
360
 
377
- def verify_table_width(width) #:nodoc:
361
+ def verify_table_width(width)
378
362
  raise %(The table must have exactly #{width} columns) unless raw[0].size == width
379
363
  end
380
364
 
381
365
  # TODO: remove the below function if it's not actually being used.
382
366
  # Nothing else in this repo calls it.
383
- def text?(text) #:nodoc:
367
+ def text?(text)
384
368
  raw.flatten.compact.detect { |cell_value| cell_value.index(text) }
385
369
  end
386
370
 
387
- def cells_rows #:nodoc:
388
- @rows ||= cell_matrix.map do |cell_row| # rubocop:disable Naming/MemoizedInstanceVariableName
371
+ def cells_rows
372
+ @rows ||= cell_matrix.map do |cell_row|
389
373
  Cells.new(self, cell_row)
390
374
  end
391
375
  end
392
376
 
393
- def headers #:nodoc:
377
+ def headers
394
378
  raw.first
395
379
  end
396
380
 
397
- def header_cell(col) #:nodoc:
381
+ def header_cell(col)
398
382
  cells_rows[0][col]
399
383
  end
400
384
 
401
385
  attr_reader :cell_matrix
402
386
 
403
- def col_width(col) #:nodoc:
387
+ def col_width(col)
404
388
  columns[col].__send__(:width)
405
389
  end
406
390
 
407
- def to_s(options = {}) #:nodoc:
391
+ def to_s(options = {})
408
392
  indentation = options.key?(:indent) ? options[:indent] : 2
409
393
  prefixes = options.key?(:prefixes) ? options[:prefixes] : TO_S_PREFIXES
410
394
  DataTablePrinter.new(self, indentation, prefixes).to_s
411
395
  end
412
396
 
413
- class DataTablePrinter #:nodoc:
397
+ class DataTablePrinter
414
398
  include Cucumber::Gherkin::Formatter::Escaping
415
399
  attr_reader :data_table, :indentation, :prefixes
416
400
  private :data_table, :indentation, :prefixes
@@ -424,7 +408,7 @@ module Cucumber
424
408
  def to_s
425
409
  leading_row = "\n"
426
410
  end_indentation = indentation - 2
427
- trailing_row = "\n" + (' ' * end_indentation)
411
+ trailing_row = "\n#{' ' * end_indentation}"
428
412
  table_rows = data_table.cell_matrix.map { |row| format_row(row) }
429
413
  leading_row + table_rows.join("\n") + trailing_row
430
414
  end
@@ -432,7 +416,7 @@ module Cucumber
432
416
  private
433
417
 
434
418
  def format_row(row)
435
- row_start = (' ' * indentation) + '| '
419
+ row_start = "#{' ' * indentation}| "
436
420
  row_end = '|'
437
421
  cells = row.map.with_index do |cell, i|
438
422
  format_cell(cell, data_table.col_width(i))
@@ -449,7 +433,7 @@ module Cucumber
449
433
  end
450
434
  end
451
435
 
452
- def columns #:nodoc:
436
+ def columns
453
437
  @columns ||= cell_matrix.transpose.map do |cell_row|
454
438
  Cells.new(self, cell_row)
455
439
  end
@@ -469,23 +453,23 @@ module Cucumber
469
453
  def build_hashes
470
454
  convert_headers!
471
455
  convert_columns!
472
- cells_rows[1..-1].map(&:to_hash)
456
+ cells_rows[1..].map(&:to_hash)
473
457
  end
474
458
 
475
- def create_cell_matrix(ast_table) #:nodoc:
459
+ def create_cell_matrix(ast_table)
476
460
  ast_table.raw.map do |raw_row|
477
461
  line = begin
478
- raw_row.line
479
- rescue StandardError
480
- -1
481
- end
462
+ raw_row.line
463
+ rescue StandardError
464
+ -1
465
+ end
482
466
  raw_row.map do |raw_cell|
483
467
  Cell.new(raw_cell, self, line)
484
468
  end
485
469
  end
486
470
  end
487
471
 
488
- def convert_columns! #:nodoc:
472
+ def convert_columns!
489
473
  @conversion_procs.each do |column_name, conversion_proc|
490
474
  verify_column(column_name) if conversion_proc[:strict]
491
475
  end
@@ -493,13 +477,13 @@ module Cucumber
493
477
  cell_matrix.transpose.each do |col|
494
478
  column_name = col[0].value
495
479
  conversion_proc = @conversion_procs[column_name][:proc]
496
- col[1..-1].each do |cell|
480
+ col[1..].each do |cell|
497
481
  cell.value = conversion_proc.call(cell.value)
498
482
  end
499
483
  end
500
484
  end
501
485
 
502
- def convert_headers! #:nodoc:
486
+ def convert_headers!
503
487
  header_cells = cell_matrix[0]
504
488
 
505
489
  if @header_conversion_proc
@@ -508,20 +492,22 @@ module Cucumber
508
492
  end
509
493
 
510
494
  @header_mappings.each_pair do |pre, post|
511
- mapped_cells = header_cells.reject { |cell| cell.value.match(pre).nil? }
495
+ mapped_cells = header_cells.select { |cell| pre.is_a?(Regexp) ? cell.value.match?(pre) : cell.value == pre }
512
496
  raise "No headers matched #{pre.inspect}" if mapped_cells.empty?
513
497
  raise "#{mapped_cells.length} headers matched #{pre.inspect}: #{mapped_cells.map(&:value).inspect}" if mapped_cells.length > 1
498
+
514
499
  mapped_cells[0].value = post
515
500
  @conversion_procs[post] = @conversion_procs.delete(pre) if @conversion_procs.key?(pre)
516
501
  end
517
502
  end
518
503
 
519
- def clear_cache! #:nodoc:
504
+ def clear_cache!
520
505
  @hashes = @rows_hash = @column_names = @rows = @columns = nil
521
506
  end
522
507
 
523
- def ensure_table(table_or_array) #:nodoc:
524
- return table_or_array if DataTable == table_or_array.class
508
+ def ensure_table(table_or_array)
509
+ return table_or_array if table_or_array.instance_of?(DataTable)
510
+
525
511
  DataTable.from(table_or_array)
526
512
  end
527
513
 
@@ -530,7 +516,7 @@ module Cucumber
530
516
  end
531
517
 
532
518
  # Represents a row of cells or columns of cells
533
- class Cells #:nodoc:
519
+ class Cells
534
520
  include Enumerable
535
521
  include Cucumber::Gherkin::Formatter::Escaping
536
522
 
@@ -543,27 +529,27 @@ module Cucumber
543
529
 
544
530
  def accept(visitor)
545
531
  return if Cucumber.wants_to_quit
532
+
546
533
  each do |cell|
547
534
  visitor.visit_table_cell(cell)
548
535
  end
549
536
  nil
550
537
  end
551
538
 
552
- # For testing only
553
- def to_sexp #:nodoc:
539
+ def to_sexp
554
540
  [:row, line, *@cells.map(&:to_sexp)]
555
541
  end
556
542
 
557
- def to_hash #:nodoc:
543
+ def to_hash
558
544
  @to_hash ||= @table.cells_to_hash(self)
559
545
  end
560
546
 
561
- def value(n) #:nodoc:
562
- self[n].value
547
+ def value(index)
548
+ self[index].value
563
549
  end
564
550
 
565
- def [](n)
566
- @cells[n]
551
+ def [](index)
552
+ @cells[index]
567
553
  end
568
554
 
569
555
  def line
@@ -589,7 +575,7 @@ module Cucumber
589
575
  end
590
576
  end
591
577
 
592
- class Cell #:nodoc:
578
+ class Cell
593
579
  attr_reader :line, :table
594
580
  attr_accessor :status, :value
595
581
 
@@ -604,7 +590,7 @@ module Cucumber
604
590
  end
605
591
 
606
592
  def ==(other)
607
- SurplusCell == other.class || value == other.value
593
+ other.class == SurplusCell || value == other.value
608
594
  end
609
595
 
610
596
  def eql?(other)
@@ -616,12 +602,12 @@ module Cucumber
616
602
  end
617
603
 
618
604
  # For testing only
619
- def to_sexp #:nodoc:
605
+ def to_sexp
620
606
  [:cell, @value]
621
607
  end
622
608
  end
623
609
 
624
- class SurplusCell < Cell #:nodoc:
610
+ class SurplusCell < Cell
625
611
  def status
626
612
  :comment
627
613
  end
@@ -1,27 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Detect the platform we're running on so we can tweak behaviour
4
- # in various places.
3
+ # Detect the platform we're running on so we can tweak behaviour in various places.
5
4
  require 'rbconfig'
6
5
  require 'cucumber/core/platform'
7
6
 
8
7
  module Cucumber
9
- unless defined?(Cucumber::VERSION)
10
- VERSION = File.read(File.expand_path('version', __dir__)).strip
11
- BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/cucumber')
12
- LIBDIR = File.expand_path(File.dirname(__FILE__) + '/../../lib')
13
- RAILS = defined?(Rails)
14
- RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
15
- RUBY = defined? RUBY_VERSION
8
+ VERSION = File.read(File.expand_path('../../VERSION', __dir__)).strip
9
+ BINARY = File.expand_path("#{File.dirname(__FILE__)}/../../bin/cucumber")
10
+ LIBDIR = File.expand_path("#{File.dirname(__FILE__)}/../../lib")
11
+ RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
16
12
 
17
- class << self
18
- attr_accessor :use_full_backtrace
13
+ class << self
14
+ attr_accessor :use_full_backtrace
19
15
 
20
- # @private
21
- def file_mode(mode, encoding = 'UTF-8')
22
- "#{mode}:#{encoding}"
23
- end
16
+ # @private
17
+ def file_mode(mode, encoding = 'UTF-8')
18
+ "#{mode}:#{encoding}"
24
19
  end
25
- self.use_full_backtrace = false
26
20
  end
21
+ self.use_full_backtrace = false
27
22
  end
@@ -2,13 +2,7 @@
2
2
 
3
3
  require 'cucumber/platform'
4
4
  require 'cucumber/gherkin/formatter/ansi_escapes'
5
- begin
6
- # Support Rake > 0.8.7
7
- require 'rake/dsl_definition'
8
- # rubocop:disable Lint/HandleExceptions
9
- rescue LoadError
10
- # rubocop:enable Lint/HandleExceptions
11
- end
5
+ require 'rake/dsl_definition'
12
6
 
13
7
  module Cucumber
14
8
  module Rake
@@ -32,13 +26,14 @@ module Cucumber
32
26
  include Cucumber::Gherkin::Formatter::AnsiEscapes
33
27
  include ::Rake::DSL if defined?(::Rake::DSL)
34
28
 
35
- class InProcessCucumberRunner #:nodoc:
29
+ class InProcessCucumberRunner # :nodoc:
36
30
  include ::Rake::DSL if defined?(::Rake::DSL)
37
31
 
38
32
  attr_reader :args
39
33
 
40
34
  def initialize(libs, cucumber_opts, feature_files)
41
- raise 'libs must be an Array when running in-process' unless Array == libs.class
35
+ raise 'libs must be an Array when running in-process' unless libs.instance_of? Array
36
+
42
37
  libs.reverse_each { |lib| $LOAD_PATH.unshift(lib) }
43
38
  @args = (
44
39
  cucumber_opts +
@@ -53,7 +48,7 @@ module Cucumber
53
48
  end
54
49
  end
55
50
 
56
- class ForkedCucumberRunner #:nodoc:
51
+ class ForkedCucumberRunner # :nodoc:
57
52
  include ::Rake::DSL if defined?(::Rake::DSL)
58
53
 
59
54
  def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files)
@@ -112,8 +107,17 @@ module Cucumber
112
107
  # Extra options to pass to the cucumber binary. Can be overridden by the CUCUMBER_OPTS environment variable.
113
108
  # It's recommended to pass an Array, but if it's a String it will be #split by ' '.
114
109
  attr_reader :cucumber_opts
115
- def cucumber_opts=(opts) #:nodoc:
116
- @cucumber_opts = String == opts.class ? opts.split(' ') : opts
110
+
111
+ def cucumber_opts=(opts) # :nodoc:
112
+ unless opts.instance_of? String
113
+ @cucumber_opts = opts
114
+ return
115
+ end
116
+
117
+ @cucumber_opts = opts.split(' ')
118
+ return if @cucumber_opts.length <= 1
119
+
120
+ $stderr.puts 'WARNING: consider using an array rather than a space-delimited string with cucumber_opts to avoid undesired behavior.'
117
121
  end
118
122
 
119
123
  # Whether or not to fork a new ruby interpreter. Defaults to true. You may gain
@@ -147,24 +151,25 @@ module Cucumber
147
151
  define_task
148
152
  end
149
153
 
150
- def define_task #:nodoc:
154
+ def define_task # :nodoc:
151
155
  desc @desc
152
156
  task @task_name do
153
157
  runner.run
154
158
  end
155
159
  end
156
160
 
157
- def runner(_task_args = nil) #:nodoc:
158
- cucumber_opts = [(ENV['CUCUMBER_OPTS'] ? ENV['CUCUMBER_OPTS'].split(/\s+/) : nil) || cucumber_opts_with_profile]
161
+ def runner(_task_args = nil) # :nodoc:
162
+ cucumber_opts = [ENV['CUCUMBER_OPTS']&.split(/\s+/) || cucumber_opts_with_profile]
159
163
  return ForkedCucumberRunner.new(libs, binary, cucumber_opts, bundler, feature_files) if fork
164
+
160
165
  InProcessCucumberRunner.new(libs, cucumber_opts, feature_files)
161
166
  end
162
167
 
163
- def cucumber_opts_with_profile #:nodoc:
168
+ def cucumber_opts_with_profile # :nodoc:
164
169
  Array(cucumber_opts).concat(Array(@profile).flat_map { |p| ['--profile', p] })
165
170
  end
166
171
 
167
- def feature_files #:nodoc:
172
+ def feature_files # :nodoc:
168
173
  make_command_line_safe(FileList[ENV['FEATURE'] || []])
169
174
  end
170
175