cucumber-cucumber-expressions 16.1.2 → 17.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -0
  3. data/.rubocop_todo.yml +524 -0
  4. data/Gemfile +2 -1
  5. data/Rakefile +4 -17
  6. data/VERSION +1 -1
  7. data/cucumber-cucumber-expressions.gemspec +11 -9
  8. data/lib/cucumber/cucumber_expressions/argument.rb +6 -3
  9. data/lib/cucumber/cucumber_expressions/ast.rb +24 -59
  10. data/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb +6 -13
  11. data/lib/cucumber/cucumber_expressions/cucumber_expression.rb +9 -11
  12. data/lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb +7 -11
  13. data/lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb +37 -53
  14. data/lib/cucumber/cucumber_expressions/cucumber_expression_tokenizer.rb +13 -18
  15. data/lib/cucumber/cucumber_expressions/errors.rb +119 -101
  16. data/lib/cucumber/cucumber_expressions/expression_factory.rb +2 -0
  17. data/lib/cucumber/cucumber_expressions/generated_expression.rb +2 -0
  18. data/lib/cucumber/cucumber_expressions/group.rb +2 -0
  19. data/lib/cucumber/cucumber_expressions/group_builder.rb +2 -0
  20. data/lib/cucumber/cucumber_expressions/parameter_type.rb +13 -23
  21. data/lib/cucumber/cucumber_expressions/parameter_type_matcher.rb +8 -6
  22. data/lib/cucumber/cucumber_expressions/parameter_type_registry.rb +23 -20
  23. data/lib/cucumber/cucumber_expressions/regular_expression.rb +3 -2
  24. data/lib/cucumber/cucumber_expressions/tree_regexp.rb +5 -4
  25. data/spec/cucumber/cucumber_expressions/argument_spec.rb +4 -2
  26. data/spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb +7 -6
  27. data/spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb +104 -101
  28. data/spec/cucumber/cucumber_expressions/cucumber_expression_parser_spec.rb +2 -0
  29. data/spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb +84 -87
  30. data/spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb +3 -1
  31. data/spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb +2 -0
  32. data/spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb +79 -60
  33. data/spec/cucumber/cucumber_expressions/expression_factory_spec.rb +2 -0
  34. data/spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb +43 -48
  35. data/spec/cucumber/cucumber_expressions/parameter_type_spec.rb +3 -1
  36. data/spec/cucumber/cucumber_expressions/regular_expression_spec.rb +37 -28
  37. data/spec/cucumber/cucumber_expressions/tree_regexp_spec.rb +23 -22
  38. metadata +21 -9
  39. data/.rspec +0 -1
  40. data/scripts/update-gemspec +0 -32
  41. data/spec/capture_warnings.rb +0 -74
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/cucumber_expressions/cucumber_expression_generator'
2
4
  require 'cucumber/cucumber_expressions/cucumber_expression'
3
5
  require 'cucumber/cucumber_expressions/parameter_type'
@@ -14,203 +16,204 @@ module Cucumber
14
16
  @generator = CucumberExpressionGenerator.new(@parameter_type_registry)
15
17
  end
16
18
 
17
- it "documents expression generation" do
19
+ it 'documents expression generation' do
18
20
  parameter_registry = ParameterTypeRegistry.new
19
21
  ### [generate-expression]
20
22
  generator = CucumberExpressionGenerator.new(parameter_registry)
21
- undefined_step_text = "I have 2 cucumbers and 1.5 tomato"
23
+ undefined_step_text = 'I have 2 cucumbers and 1.5 tomato'
22
24
  generated_expression = generator.generate_expressions(undefined_step_text)[0]
23
- expect(generated_expression.source).to eq("I have {int} cucumbers and {float} tomato")
25
+ expect(generated_expression.source).to eq('I have {int} cucumbers and {float} tomato')
24
26
  expect(generated_expression.parameter_types[1].type).to eq(Float)
25
27
  ### [generate-expression]
26
28
  end
27
29
 
28
- it "generates expression for no args" do
29
- assert_expression("hello", [], "hello")
30
+ it 'generates expression for no args' do
31
+ assert_expression('hello', [], 'hello')
30
32
  end
31
33
 
32
- it "generates expression with escaped left parenthesis" do
33
- assert_expression(
34
- "\\(iii)", [],
35
- "(iii)")
34
+ it 'generates expression with escaped left parenthesis' do
35
+ assert_expression('\\(iii)', [], '(iii)')
36
36
  end
37
37
 
38
- it "generates expression with escaped left curly brace" do
39
- assert_expression(
40
- "\\{iii}", [],
41
- "{iii}")
38
+ it 'generates expression with escaped left curly brace' do
39
+ assert_expression('\\{iii}', [], '{iii}')
42
40
  end
43
41
 
44
- it "generates expression with escaped slashes" do
45
- assert_expression(
46
- "The {int}\\/{int}\\/{int} hey", ["int", "int2", "int3"],
47
- "The 1814/05/17 hey")
42
+ it 'generates expression with escaped slashes' do
43
+ assert_expression('The {int}\\/{int}\\/{int} hey', ['int', 'int2', 'int3'], 'The 1814/05/17 hey')
48
44
  end
49
45
 
50
- it "generates expression for int float arg" do
51
- assert_expression(
52
- "I have {int} cukes and {float} euro", ["int", "float"],
53
- "I have 2 cukes and 1.5 euro")
46
+ it 'generates expression for int float arg' do
47
+ assert_expression('I have {int} cukes and {float} euro', ['int', 'float'], 'I have 2 cukes and 1.5 euro')
54
48
  end
55
49
 
56
- it "generates expression for strings" do
57
- assert_expression(
58
- "I like {string} and {string}", ["string", "string2"],
59
- 'I like "bangers" and \'mash\'')
50
+ it 'generates expression for strings' do
51
+ assert_expression('I like {string} and {string}', ['string', 'string2'], 'I like "bangers" and \'mash\'')
60
52
  end
61
53
 
62
- it "generates expression with % sign" do
63
- assert_expression(
64
- "I am {int}% foobar", ["int"],
65
- 'I am 20% foobar')
54
+ it 'generates expression with % sign' do
55
+ assert_expression('I am {int}% foobar', ['int'], 'I am 20% foobar')
66
56
  end
67
57
 
68
- it "generates expression for just int" do
69
- assert_expression(
70
- "{int}", ["int"],
71
- "99999")
58
+ it 'generates expression for just int' do
59
+ assert_expression('{int}', ['int'], '99999')
72
60
  end
73
61
 
74
- it "numbers only second argument when builtin type is not reserved keyword" do
75
- assert_expression(
76
- "I have {int} cukes and {int} euro", ["int", "int2"],
77
- "I have 2 cukes and 5 euro")
62
+ it 'numbers only second argument when builtin type is not reserved keyword' do
63
+ assert_expression('I have {int} cukes and {int} euro', ['int', 'int2'], 'I have 2 cukes and 5 euro')
78
64
  end
79
65
 
80
- it "numbers only second argument when type is not reserved keyword" do
81
- @parameter_type_registry.define_parameter_type(ParameterType.new(
82
- 'currency',
83
- '[A-Z]{3}',
84
- Currency,
85
- lambda {|s| Currency.new(s)},
86
- true,
87
- true
88
- ))
66
+ it 'numbers only second argument when type is not reserved keyword' do
67
+ @parameter_type_registry.define_parameter_type(
68
+ ParameterType.new(
69
+ 'currency',
70
+ '[A-Z]{3}',
71
+ Currency,
72
+ ->(s) { Currency.new(s)},
73
+ true,
74
+ true
75
+ )
76
+ )
89
77
 
90
- assert_expression(
91
- "I have a {currency} account and a {currency} account", ["currency", "currency2"],
92
- "I have a EUR account and a GBP account")
78
+ assert_expression('I have a {currency} account and a {currency} account', ['currency', 'currency2'], 'I have a EUR account and a GBP account')
93
79
  end
94
80
 
95
- it "exposes parameters in generated expression" do
96
- expression = @generator.generate_expressions("I have 2 cukes and 1.5 euro")[0]
81
+ it 'exposes parameters in a generated expression' do
82
+ expression = @generator.generate_expressions('I have 2 cukes and 1.5 euro')[0]
97
83
  types = expression.parameter_types.map(&:type)
84
+
98
85
  expect(types).to eq([Integer, Float])
99
86
  end
100
87
 
101
- it "matches parameter types with optional capture groups" do
102
- @parameter_type_registry.define_parameter_type(ParameterType.new(
88
+ it 'matches parameter types with optional capture groups' do
89
+ @parameter_type_registry.define_parameter_type(
90
+ ParameterType.new(
103
91
  'optional-flight',
104
92
  /(1st flight)?/,
105
93
  String,
106
- lambda {|s| s},
94
+ ->(s) { s},
107
95
  true,
108
96
  false
109
- ))
110
- @parameter_type_registry.define_parameter_type(ParameterType.new(
97
+ )
98
+ )
99
+ @parameter_type_registry.define_parameter_type(
100
+ ParameterType.new(
111
101
  'optional-hotel',
112
102
  /(1 hotel)?/,
113
103
  String,
114
- lambda {|s| s},
104
+ ->(s) { s},
115
105
  true,
116
106
  false
117
- ))
107
+ )
108
+ )
118
109
 
119
- expression = @generator.generate_expressions("I reach Stage 4: 1st flight -1 hotel")[0]
110
+ expression = @generator.generate_expressions('I reach Stage 4: 1st flight -1 hotel')[0]
120
111
  # While you would expect this to be `I reach Stage {int}: {optional-flight} -{optional-hotel}`
121
112
  # the `-1` causes {int} to match just before {optional-hotel}.
122
- expect(expression.source).to eq("I reach Stage {int}: {optional-flight} {int} hotel")
113
+
114
+ expect(expression.source).to eq('I reach Stage {int}: {optional-flight} {int} hotel')
123
115
  end
124
116
 
125
- it "generates at most 256 expressions" do
117
+ it 'generates at most 256 expressions' do
126
118
  for i in 0..3
127
- @parameter_type_registry.define_parameter_type(ParameterType.new(
119
+ @parameter_type_registry.define_parameter_type(
120
+ ParameterType.new(
128
121
  "my-type-#{i}",
129
122
  /([a-z] )*?[a-z]/,
130
123
  String,
131
- lambda {|s| s},
124
+ ->(s) { s},
132
125
  true,
133
126
  false
134
- ))
127
+ )
128
+ )
135
129
  end
136
130
  # This would otherwise generate 4^11=4194300 expressions and consume just shy of 1.5GB.
137
- expressions = @generator.generate_expressions("a s i m p l e s t e p")
131
+ expressions = @generator.generate_expressions('a s i m p l e s t e p')
132
+
138
133
  expect(expressions.length).to eq(256)
139
134
  end
140
135
 
141
- it "prefers expression with longest non empty match" do
142
- @parameter_type_registry.define_parameter_type(ParameterType.new(
136
+ it 'prefers expression with longest non empty match' do
137
+ @parameter_type_registry.define_parameter_type(
138
+ ParameterType.new(
143
139
  'zero-or-more',
144
140
  /[a-z]*/,
145
141
  String,
146
- lambda {|s| s},
142
+ ->(s) { s},
147
143
  true,
148
144
  false
149
- ))
150
- @parameter_type_registry.define_parameter_type(ParameterType.new(
145
+ )
146
+ )
147
+ @parameter_type_registry.define_parameter_type(
148
+ ParameterType.new(
151
149
  'exactly-one',
152
150
  /[a-z]/,
153
151
  String,
154
- lambda {|s| s},
152
+ ->(s) { s},
155
153
  true,
156
154
  false
157
- ))
155
+ )
156
+ )
157
+ expressions = @generator.generate_expressions('a simple step')
158
158
 
159
- expressions = @generator.generate_expressions("a simple step")
160
159
  expect(expressions.length).to eq(2)
161
- expect(expressions[0].source).to eq("{exactly-one} {zero-or-more} {zero-or-more}")
162
- expect(expressions[1].source).to eq("{zero-or-more} {zero-or-more} {zero-or-more}")
160
+ expect(expressions[0].source).to eq('{exactly-one} {zero-or-more} {zero-or-more}')
161
+ expect(expressions[1].source).to eq('{zero-or-more} {zero-or-more} {zero-or-more}')
163
162
  end
164
163
 
165
- context "does not suggest parameter when match is" do
164
+ context 'does not suggest parameter when match is' do
166
165
  before do
167
- @parameter_type_registry.define_parameter_type(ParameterType.new(
166
+ @parameter_type_registry.define_parameter_type(
167
+ ParameterType.new(
168
168
  'direction',
169
169
  /(up|down)/,
170
170
  String,
171
- lambda {|s| s},
171
+ ->(s) { s},
172
172
  true,
173
173
  false
174
- ))
174
+ )
175
+ )
175
176
  end
176
177
 
177
- it "at the beginning of a word" do
178
- expect(@generator.generate_expressions("When I download a picture")[0].source).not_to eq("When I {direction}load a picture")
179
- expect(@generator.generate_expressions("When I download a picture")[0].source).to eq("When I download a picture")
178
+ it 'at the beginning of a word' do
179
+ expect(@generator.generate_expressions('When I download a picture')[0].source).not_to eq('When I {direction}load a picture')
180
+ expect(@generator.generate_expressions('When I download a picture')[0].source).to eq('When I download a picture')
180
181
  end
181
182
 
182
- it "inside a word" do
183
- expect(@generator.generate_expressions("When I watch the muppet show")[0].source).not_to eq("When I watch the m{direction}pet show")
184
- expect(@generator.generate_expressions("When I watch the muppet show")[0].source).to eq("When I watch the muppet show")
183
+ it 'inside a word' do
184
+ expect(@generator.generate_expressions('When I watch the muppet show')[0].source).not_to eq('When I watch the m{direction}pet show')
185
+ expect(@generator.generate_expressions('When I watch the muppet show')[0].source).to eq('When I watch the muppet show')
185
186
  end
186
187
 
187
- it "at the end of a word" do
188
- expect(@generator.generate_expressions("When I create a group")[0].source).not_to eq("When I create a gro{direction}")
189
- expect(@generator.generate_expressions("When I create a group")[0].source).to eq("When I create a group")
188
+ it 'at the end of a word' do
189
+ expect(@generator.generate_expressions('When I create a group')[0].source).not_to eq('When I create a gro{direction}')
190
+ expect(@generator.generate_expressions('When I create a group')[0].source).to eq('When I create a group')
190
191
  end
191
192
  end
192
193
 
193
- context "does suggest parameter when match is" do
194
+ context 'does suggest parameter when match is' do
194
195
  before do
195
- @parameter_type_registry.define_parameter_type(ParameterType.new(
196
+ @parameter_type_registry.define_parameter_type(
197
+ ParameterType.new(
196
198
  'direction',
197
199
  /(up|down)/,
198
200
  String,
199
- lambda {|s| s},
201
+ ->(s) { s},
200
202
  true,
201
203
  false
202
- ))
204
+ )
205
+ )
203
206
  end
204
207
 
205
- it "a full word" do
206
- expect(@generator.generate_expressions("When I go down the road")[0].source).to eq("When I go {direction} the road")
207
- expect(@generator.generate_expressions("When I walk up the hill")[0].source).to eq("When I walk {direction} the hill")
208
- expect(@generator.generate_expressions("up the hill, the road goes down")[0].source).to eq("{direction} the hill, the road goes {direction}")
208
+ it 'a full word' do
209
+ expect(@generator.generate_expressions('When I go down the road')[0].source).to eq('When I go {direction} the road')
210
+ expect(@generator.generate_expressions('When I walk up the hill')[0].source).to eq('When I walk {direction} the hill')
211
+ expect(@generator.generate_expressions('up the hill, the road goes down')[0].source).to eq('{direction} the hill, the road goes {direction}')
209
212
  end
210
213
 
211
214
  it 'wrapped around punctuation characters' do
212
- expect(@generator.generate_expressions("When direction is:down")[0].source).to eq("When direction is:{direction}")
213
- expect(@generator.generate_expressions("Then direction is down.")[0].source).to eq("Then direction is {direction}.")
215
+ expect(@generator.generate_expressions('When direction is:down')[0].source).to eq('When direction is:{direction}')
216
+ expect(@generator.generate_expressions('Then direction is down.')[0].source).to eq('Then direction is {direction}.')
214
217
  end
215
218
  end
216
219
 
@@ -221,9 +224,9 @@ module Cucumber
221
224
 
222
225
  cucumber_expression = CucumberExpression.new(generated_expression.source, @parameter_type_registry)
223
226
  match = cucumber_expression.match(text)
224
- if match.nil?
225
- raise "Expected text '#{text}' to match generated expression '#{generated_expression.source}'"
226
- end
227
+
228
+ raise "Expected text '#{text}' to match generated expression '#{generated_expression.source}'" if match.nil?
229
+
227
230
  expect(match.length).to eq(expected_argument_names.length)
228
231
  end
229
232
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'cucumber/cucumber_expressions/cucumber_expression_parser'
3
5
  require 'cucumber/cucumber_expressions/errors'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'cucumber/cucumber_expressions/cucumber_expression'
3
5
  require 'cucumber/cucumber_expressions/parameter_type_registry'
@@ -5,9 +7,9 @@ require 'cucumber/cucumber_expressions/parameter_type_registry'
5
7
  module Cucumber
6
8
  module CucumberExpressions
7
9
  describe CucumberExpression do
8
-
9
10
  Dir['../testdata/cucumber-expression/matching/*.yaml'].each do |path|
10
11
  expectation = YAML.load_file(path)
12
+
11
13
  it "matches #{path}" do
12
14
  parameter_registry = ParameterTypeRegistry.new
13
15
  if expectation['exception']
@@ -36,115 +38,110 @@ module Cucumber
36
38
  end
37
39
  end
38
40
 
39
- it "documents match arguments" do
41
+ it 'documents match arguments' do
40
42
  parameter_registry = ParameterTypeRegistry.new
41
43
 
42
44
  ### [capture-match-arguments]
43
- expr = "I have {int} cuke(s)"
45
+ expr = 'I have {int} cuke(s)'
44
46
  expression = CucumberExpression.new(expr, parameter_registry)
45
- args = expression.match("I have 7 cukes")
47
+ args = expression.match('I have 7 cukes')
48
+
46
49
  expect(args[0].value(nil)).to eq(7)
47
50
  ### [capture-match-arguments]
48
51
  end
49
52
 
50
- it "matches float" do
51
- expect(match("{float}", "")).to eq(nil)
52
- expect(match("{float}", ".")).to eq(nil)
53
- expect(match("{float}", ",")).to eq(nil)
54
- expect(match("{float}", "-")).to eq(nil)
55
- expect(match("{float}", "E")).to eq(nil)
56
- expect(match("{float}", "1,")).to eq(nil)
57
- expect(match("{float}", ",1")).to eq(nil)
58
- expect(match("{float}", "1.")).to eq(nil)
59
-
60
- expect(match("{float}", "1")).to eq([1])
61
- expect(match("{float}", "-1")).to eq([-1])
62
- expect(match("{float}", "1.1")).to eq([1.1])
63
- expect(match("{float}", "1,000")).to eq(nil)
64
- expect(match("{float}", "1,000,0")).to eq(nil)
65
- expect(match("{float}", "1,000.1")).to eq(nil)
66
- expect(match("{float}", "1,000,10")).to eq(nil)
67
- expect(match("{float}", "1,0.1")).to eq(nil)
68
- expect(match("{float}", "1,000,000.1")).to eq(nil)
69
- expect(match("{float}", "-1.1")).to eq([-1.1])
70
-
71
- expect(match("{float}", ".1")).to eq([0.1])
72
- expect(match("{float}", "-.1")).to eq([-0.1])
73
- expect(match("{float}", "-.1000001")).to eq([-0.1000001])
74
- expect(match("{float}", "1E1")).to eq([10.0])
75
- expect(match("{float}", ".1E1")).to eq([1])
76
- expect(match("{float}", "E1")).to eq(nil)
77
- expect(match("{float}", "-.1E-1")).to eq([-0.01])
78
- expect(match("{float}", "-.1E-2")).to eq([-0.001])
79
- expect(match("{float}", "-.1E+1")).to eq([-1])
80
- expect(match("{float}", "-.1E+2")).to eq([-10])
81
- expect(match("{float}", "-.1E1")).to eq([-1])
82
- expect(match("{float}", "-.1E2")).to eq([-10])
53
+ it 'matches float' do
54
+ expect(match('{float}', '')).to eq(nil)
55
+ expect(match('{float}', '.')).to eq(nil)
56
+ expect(match('{float}', ',')).to eq(nil)
57
+ expect(match('{float}', '-')).to eq(nil)
58
+ expect(match('{float}', 'E')).to eq(nil)
59
+ expect(match('{float}', '1,')).to eq(nil)
60
+ expect(match('{float}', ',1')).to eq(nil)
61
+ expect(match('{float}', '1.')).to eq(nil)
62
+
63
+ expect(match('{float}', '1')).to eq([1])
64
+ expect(match('{float}', '-1')).to eq([-1])
65
+ expect(match('{float}', '1.1')).to eq([1.1])
66
+ expect(match('{float}', '1,000')).to eq(nil)
67
+ expect(match('{float}', '1,000,0')).to eq(nil)
68
+ expect(match('{float}', '1,000.1')).to eq(nil)
69
+ expect(match('{float}', '1,000,10')).to eq(nil)
70
+ expect(match('{float}', '1,0.1')).to eq(nil)
71
+ expect(match('{float}', '1,000,000.1')).to eq(nil)
72
+ expect(match('{float}', '-1.1')).to eq([-1.1])
73
+
74
+ expect(match('{float}', '.1')).to eq([0.1])
75
+ expect(match('{float}', '-.1')).to eq([-0.1])
76
+ expect(match('{float}', '-.1000001')).to eq([-0.1000001])
77
+ expect(match('{float}', '1E1')).to eq([10.0])
78
+ expect(match('{float}', '.1E1')).to eq([1])
79
+ expect(match('{float}', 'E1')).to eq(nil)
80
+ expect(match('{float}', '-.1E-1')).to eq([-0.01])
81
+ expect(match('{float}', '-.1E-2')).to eq([-0.001])
82
+ expect(match('{float}', '-.1E+1')).to eq([-1])
83
+ expect(match('{float}', '-.1E+2')).to eq([-10])
84
+ expect(match('{float}', '-.1E1')).to eq([-1])
85
+ expect(match('{float}', '-.1E2')).to eq([-10])
83
86
  end
84
87
 
85
- it "float with zero" do
86
- expect(match("{float}", "0")).to eq([0.0])
88
+ it 'float with zero' do
89
+ expect(match('{float}', '0')).to eq([0.0])
87
90
  end
88
91
 
89
- it "matches anonymous" do
90
- expect(match("{}", "0.22")).to eq(["0.22"])
92
+ it 'matches anonymous' do
93
+ expect(match('{}', '0.22')).to eq(['0.22'])
91
94
  end
92
95
 
93
- it "exposes source" do
94
- expr = "I have {int} cuke(s)"
96
+ it 'exposes source' do
97
+ expr = 'I have {int} cuke(s)'
98
+
95
99
  expect(CucumberExpression.new(expr, ParameterTypeRegistry.new).source).to eq(expr)
96
100
  end
97
101
 
98
- it "exposes source via #to_s" do
99
- expr = "I have {int} cuke(s)"
102
+ it 'exposes source via #to_s' do
103
+ expr = 'I have {int} cuke(s)'
104
+
100
105
  expect(CucumberExpression.new(expr, ParameterTypeRegistry.new).to_s).to eq(expr.inspect)
101
106
  end
102
107
 
103
- it "unmatched optional groups have undefined values" do
108
+ it 'unmatched optional groups have undefined values' do
104
109
  parameter_type_registry = ParameterTypeRegistry.new
105
110
  parameter_type_registry.define_parameter_type(
106
- ParameterType.new(
107
- 'textAndOrNumber',
108
- /([A-Z]+)?(?: )?([0-9]+)?/,
109
- Object,
110
- -> (s1, s2) {
111
- [s1, s2]
112
- },
113
- false,
114
- true
115
- )
116
- )
117
- expression = CucumberExpression.new(
118
- '{textAndOrNumber}',
119
- parameter_type_registry
111
+ ParameterType.new(
112
+ 'textAndOrNumber',
113
+ /([A-Z]+)?(?: )?([0-9]+)?/,
114
+ Object,
115
+ ->(s1, s2) { [s1, s2] },
116
+ false,
117
+ true
118
+ )
120
119
  )
120
+ expression = CucumberExpression.new('{textAndOrNumber}', parameter_type_registry)
121
121
 
122
- class World
123
- end
122
+ class World; end
124
123
 
125
- expect(expression.match("TLA")[0].value(World.new)).to eq(["TLA", nil])
126
- expect(expression.match("123")[0].value(World.new)).to eq([nil, "123"])
124
+ expect(expression.match('TLA')[0].value(World.new)).to eq(['TLA', nil])
125
+ expect(expression.match('123')[0].value(World.new)).to eq([nil, '123'])
127
126
  end
128
127
 
129
128
  # Ruby specific
130
129
 
131
- it "delegates transform to custom object" do
130
+ it 'delegates transform to custom object' do
132
131
  parameter_type_registry = ParameterTypeRegistry.new
133
132
  parameter_type_registry.define_parameter_type(
134
- ParameterType.new(
135
- 'widget',
136
- /\w+/,
137
- Object,
138
- -> (s) {
139
- self.create_widget(s)
140
- },
141
- false,
142
- true
143
- )
133
+ ParameterType.new(
134
+ 'widget',
135
+ /\w+/,
136
+ Object,
137
+ ->(s) { self.create_widget(s) },
138
+ false,
139
+ true
140
+ )
144
141
  )
145
142
  expression = CucumberExpression.new(
146
- 'I have a {widget}',
147
- parameter_type_registry
143
+ 'I have a {widget}',
144
+ parameter_type_registry
148
145
  )
149
146
 
150
147
  class World
@@ -153,27 +150,27 @@ module Cucumber
153
150
  end
154
151
  end
155
152
 
156
- args = expression.match("I have a bolt")
153
+ args = expression.match('I have a bolt')
154
+
157
155
  expect(args[0].value(World.new)).to eq('widget:bolt')
158
156
  end
159
157
 
160
- it "reports undefined parameter type name" do
158
+ it 'reports undefined parameter type name' do
161
159
  parameter_type_registry = ParameterTypeRegistry.new
162
160
 
163
- begin
164
- CucumberExpression.new(
165
- 'I have {int} {widget}(s) in {word}',
166
- parameter_type_registry
167
- )
168
- rescue UndefinedParameterTypeError => e
169
- expect(e.undefined_parameter_type_name).to eq('widget')
170
- end
161
+ CucumberExpression.new(
162
+ 'I have {int} {widget}(s) in {word}',
163
+ parameter_type_registry
164
+ )
165
+ rescue UndefinedParameterTypeError => e
166
+ expect(e.undefined_parameter_type_name).to eq('widget')
171
167
  end
172
168
 
173
169
  def match(expression, text)
174
170
  cucumber_expression = CucumberExpression.new(expression, ParameterTypeRegistry.new)
175
171
  args = cucumber_expression.match(text)
176
172
  return nil if args.nil?
173
+
177
174
  args.map { |arg| arg.value(nil) }
178
175
  end
179
176
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'cucumber/cucumber_expressions/cucumber_expression_tokenizer'
3
5
  require 'cucumber/cucumber_expressions/errors'
@@ -13,7 +15,7 @@ module Cucumber
13
15
  expect { tokenizer.tokenize(expectation['expression']) }.to raise_error(expectation['exception'])
14
16
  else
15
17
  tokens = tokenizer.tokenize(expectation['expression'])
16
- token_hashes = tokens.map{|token| token.to_hash}
18
+ token_hashes = tokens.map {|token| token.to_hash}
17
19
  expect(token_hashes).to eq(expectation['expected_tokens'])
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'cucumber/cucumber_expressions/cucumber_expression'
3
5
  require 'cucumber/cucumber_expressions/parameter_type_registry'