cucumber-cucumber-expressions 16.1.2 → 17.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +37 -0
  3. data/.rubocop_todo.yml +443 -0
  4. data/Gemfile +2 -1
  5. data/Rakefile +4 -17
  6. data/VERSION +1 -1
  7. data/cucumber-cucumber-expressions.gemspec +22 -17
  8. data/lib/cucumber/cucumber_expressions/argument.rb +7 -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 +17 -19
  12. data/lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb +11 -15
  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 +121 -103
  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 +3 -1
  20. data/lib/cucumber/cucumber_expressions/parameter_type.rb +14 -26
  21. data/lib/cucumber/cucumber_expressions/parameter_type_matcher.rb +9 -7
  22. data/lib/cucumber/cucumber_expressions/parameter_type_registry.rb +27 -22
  23. data/lib/cucumber/cucumber_expressions/regular_expression.rb +3 -2
  24. data/lib/cucumber/cucumber_expressions/tree_regexp.rb +8 -7
  25. data/spec/cucumber/cucumber_expressions/argument_spec.rb +4 -2
  26. data/spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb +41 -0
  27. data/spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb +106 -103
  28. data/spec/cucumber/cucumber_expressions/cucumber_expression_parser_spec.rb +3 -1
  29. data/spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb +90 -93
  30. data/spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb +4 -2
  31. data/spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb +4 -2
  32. data/spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb +80 -61
  33. data/spec/cucumber/cucumber_expressions/expression_factory_spec.rb +3 -1
  34. data/spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb +44 -49
  35. data/spec/cucumber/cucumber_expressions/parameter_type_spec.rb +5 -2
  36. data/spec/cucumber/cucumber_expressions/regular_expression_spec.rb +39 -30
  37. data/spec/cucumber/cucumber_expressions/tree_regexp_spec.rb +49 -49
  38. metadata +80 -25
  39. data/.rspec +0 -1
  40. data/scripts/update-gemspec +0 -32
  41. data/spec/capture_warnings.rb +0 -74
  42. data/spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb +0 -43
@@ -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'
@@ -8,12 +10,12 @@ module Cucumber
8
10
  Dir['../testdata/cucumber-expression/tokenizer/*.yaml'].each do |path|
9
11
  expectation = YAML.load_file(path)
10
12
  it "tokenizes #{path}" do
11
- tokenizer = CucumberExpressionTokenizer.new
13
+ tokenizer = described_class.new
12
14
  if expectation['exception']
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'
@@ -11,11 +13,11 @@ module Cucumber
11
13
  parameter_registry = ParameterTypeRegistry.new
12
14
  if expectation['exception']
13
15
  expect {
14
- cucumber_expression = CucumberExpression.new(expectation['expression'], parameter_registry)
16
+ cucumber_expression = described_class.new(expectation['expression'], parameter_registry)
15
17
  cucumber_expression.match(expectation['text'])
16
18
  }.to raise_error(expectation['exception'])
17
19
  else
18
- cucumber_expression = CucumberExpression.new(expectation['expression'], parameter_registry)
20
+ cucumber_expression = described_class.new(expectation['expression'], parameter_registry)
19
21
  matches = cucumber_expression.match(expectation['text'])
20
22
  values = matches.nil? ? nil : matches.map { |arg| arg.value(nil) }
21
23
  expect(values).to eq(expectation['expected_args'])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/cucumber_expressions/cucumber_expression'
2
4
  require 'cucumber/cucumber_expressions/regular_expression'
3
5
  require 'cucumber/cucumber_expressions/parameter_type_registry'
@@ -40,54 +42,56 @@ module Cucumber
40
42
  end
41
43
  end
42
44
 
43
- describe "Custom parameter type" do
45
+ describe 'Custom parameter type' do
44
46
  before do
45
47
  parameter_type_registry = ParameterTypeRegistry.new
46
- parameter_type_registry.define_parameter_type(ParameterType.new(
48
+ parameter_type_registry.define_parameter_type(
49
+ ParameterType.new(
47
50
  'color', # name
48
51
  /red|blue|yellow/, # regexp
49
52
  Color, # type
50
- lambda {|s| Color.new(s)}, # transform
53
+ ->(s) { Color.new(s) }, # transform
51
54
  true, # use_for_snippets
52
55
  false # prefer_for_regexp_match
53
- ))
56
+ )
57
+ )
54
58
  @parameter_type_registry = parameter_type_registry
55
59
  end
56
60
 
57
- it "throws exception for illegal character in parameter name" do
61
+ it 'throws exception for illegal character in parameter name' do
58
62
  expect do
59
63
  ParameterType.new(
60
- '[string]',
61
- /.*/,
62
- String,
63
- lambda {|s| s},
64
- true,
65
- false
64
+ '[string]',
65
+ /.*/,
66
+ String,
67
+ ->(s) { s },
68
+ true,
69
+ false
66
70
  )
67
71
  end.to raise_error("Illegal character in parameter name {[string]}. Parameter names may not contain '[]()$.|?*+'")
68
72
  end
69
73
 
70
74
  describe CucumberExpression do
71
- it "matches parameters with custom parameter type" do
72
- expression = CucumberExpression.new("I have a {color} ball", @parameter_type_registry)
73
- transformed_argument_value = expression.match("I have a red ball")[0].value(nil)
75
+ it 'matches parameters with custom parameter type' do
76
+ expression = described_class.new('I have a {color} ball', @parameter_type_registry)
77
+ transformed_argument_value = expression.match('I have a red ball')[0].value(nil)
78
+
74
79
  expect(transformed_argument_value).to eq(Color.new('red'))
75
80
  end
76
81
 
77
- it "matches parameters with multiple capture groups" do
78
- @parameter_type_registry.define_parameter_type(ParameterType.new(
82
+ it 'matches parameters with multiple capture groups' do
83
+ @parameter_type_registry.define_parameter_type(
84
+ ParameterType.new(
79
85
  'coordinate',
80
86
  /(\d+),\s*(\d+),\s*(\d+)/,
81
87
  Coordinate,
82
- lambda {|x, y, z| Coordinate.new(x.to_i, y.to_i, z.to_i)},
88
+ ->(x, y, z) { Coordinate.new(x.to_i, y.to_i, z.to_i) },
83
89
  true,
84
90
  false
85
- ))
86
-
87
- expression = CucumberExpression.new(
88
- 'A {int} thick line from {coordinate} to {coordinate}',
89
- @parameter_type_registry
91
+ )
90
92
  )
93
+
94
+ expression = described_class.new('A {int} thick line from {coordinate} to {coordinate}', @parameter_type_registry)
91
95
  args = expression.match('A 5 thick line from 10,20,30 to 40,50,60')
92
96
 
93
97
  thick = args[0].value(nil)
@@ -100,95 +104,110 @@ module Cucumber
100
104
  expect(to).to eq(Coordinate.new(40, 50, 60))
101
105
  end
102
106
 
103
- it "matches parameters with custom parameter type using optional capture group" do
107
+ it 'matches parameters with custom parameter type using optional capture group' do
104
108
  parameter_type_registry = ParameterTypeRegistry.new
105
- parameter_type_registry.define_parameter_type(ParameterType.new(
109
+ parameter_type_registry.define_parameter_type(
110
+ ParameterType.new(
106
111
  'color',
107
112
  [/red|blue|yellow/, /(?:dark|light) (?:red|blue|yellow)/],
108
113
  Color,
109
- lambda {|s| Color.new(s)},
114
+ ->(s) { Color.new(s) },
110
115
  true,
111
116
  false
112
- ))
113
- expression = CucumberExpression.new("I have a {color} ball", parameter_type_registry)
114
- transformed_argument_value = expression.match("I have a dark red ball")[0].value(nil)
117
+ )
118
+ )
119
+ expression = described_class.new('I have a {color} ball', parameter_type_registry)
120
+ transformed_argument_value = expression.match('I have a dark red ball')[0].value(nil)
121
+
115
122
  expect(transformed_argument_value).to eq(Color.new('dark red'))
116
123
  end
117
124
 
118
- it "defers transformation until queried from argument" do
119
- @parameter_type_registry.define_parameter_type(ParameterType.new(
125
+ it 'defers transformation until queried from argument' do
126
+ @parameter_type_registry.define_parameter_type(
127
+ ParameterType.new(
120
128
  'throwing',
121
129
  /bad/,
122
130
  CssColor,
123
- lambda {|s| raise "Can't transform [#{s}]"},
131
+ ->(s) { raise "Can't transform [#{s}]" },
124
132
  true,
125
133
  false
126
- ))
127
- expression = CucumberExpression.new("I have a {throwing} parameter", @parameter_type_registry)
128
- args = expression.match("I have a bad parameter")
129
- expect {args[0].value(nil)}.to raise_error("Can't transform [bad]")
134
+ )
135
+ )
136
+ expression = described_class.new('I have a {throwing} parameter', @parameter_type_registry)
137
+ args = expression.match('I have a bad parameter')
138
+
139
+ expect { args[0].value(nil) }.to raise_error("Can't transform [bad]")
130
140
  end
131
141
 
132
- describe "conflicting parameter type" do
133
- it "is detected for type name" do
142
+ describe 'conflicting parameter type' do
143
+ it 'is detected for type name' do
134
144
  expect {
135
- @parameter_type_registry.define_parameter_type(ParameterType.new(
145
+ @parameter_type_registry.define_parameter_type(
146
+ ParameterType.new(
136
147
  'color',
137
148
  /.*/,
138
149
  CssColor,
139
- lambda {|s| CssColor.new(s)},
150
+ ->(s) { CssColor.new(s) },
140
151
  true,
141
152
  false
142
- ))
143
- }.to raise_error("There is already a parameter with name color")
153
+ )
154
+ )
155
+ }.to raise_error('There is already a parameter with name color')
144
156
  end
145
157
 
146
- it "is not detected for type" do
147
- @parameter_type_registry.define_parameter_type(ParameterType.new(
158
+ it 'is not detected for type' do
159
+ @parameter_type_registry.define_parameter_type(
160
+ ParameterType.new(
148
161
  'whatever',
149
162
  /.*/,
150
163
  Color,
151
- lambda {|s| Color.new(s)},
164
+ ->(s) { Color.new(s) },
152
165
  false,
153
166
  false
154
- ))
167
+ )
168
+ )
155
169
  end
156
170
 
157
- it "is not detected for regexp" do
158
- @parameter_type_registry.define_parameter_type(ParameterType.new(
171
+ it 'is not detected for regexp' do
172
+ @parameter_type_registry.define_parameter_type(
173
+ ParameterType.new(
159
174
  'css-color',
160
175
  /red|blue|yellow/,
161
176
  CssColor,
162
- lambda {|s| CssColor.new(s)},
177
+ ->(s) { CssColor.new(s) },
163
178
  true,
164
179
  false
165
- ))
180
+ )
181
+ )
182
+ css_color = described_class.new('I have a {css-color} ball', @parameter_type_registry)
183
+ css_color_value = css_color.match('I have a blue ball')[0].value(nil)
184
+
185
+ expect(css_color_value).to eq(CssColor.new('blue'))
166
186
 
167
- css_color = CucumberExpression.new("I have a {css-color} ball", @parameter_type_registry)
168
- css_color_value = css_color.match("I have a blue ball")[0].value(nil)
169
- expect(css_color_value).to eq(CssColor.new("blue"))
187
+ color = described_class.new('I have a {color} ball', @parameter_type_registry)
188
+ color_value = color.match('I have a blue ball')[0].value(nil)
170
189
 
171
- color = CucumberExpression.new("I have a {color} ball", @parameter_type_registry)
172
- color_value = color.match("I have a blue ball")[0].value(nil)
173
- expect(color_value).to eq(Color.new("blue"))
190
+ expect(color_value).to eq(Color.new('blue'))
174
191
  end
175
192
  end
176
193
  end
177
194
 
178
195
  describe RegularExpression do
179
- it "matches arguments with custom parameter type without name" do
196
+ it 'matches arguments with custom parameter types without a name' do
180
197
  parameter_type_registry = ParameterTypeRegistry.new
181
- parameter_type_registry.define_parameter_type(ParameterType.new(
198
+ parameter_type_registry.define_parameter_type(
199
+ ParameterType.new(
182
200
  nil,
183
201
  /red|blue|yellow/,
184
202
  Color,
185
- lambda {|s| Color.new(s)},
203
+ ->(s) { Color.new(s) },
186
204
  true,
187
205
  false
188
- ))
206
+ )
207
+ )
208
+ expression = described_class.new(/I have a (red|blue|yellow) ball/, parameter_type_registry)
209
+ value = expression.match('I have a red ball')[0].value(nil)
189
210
 
190
- expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, parameter_type_registry)
191
- value = expression.match("I have a red ball")[0].value(nil)
192
211
  expect(value).to eq(Color.new('red'))
193
212
  end
194
213
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/cucumber_expressions/expression_factory'
2
4
 
3
5
  module Cucumber
4
6
  module CucumberExpressions
5
7
  describe ExpressionFactory do
6
8
  before do
7
- @expression_factory = ExpressionFactory.new(ParameterTypeRegistry.new)
9
+ @expression_factory = described_class.new(ParameterTypeRegistry.new)
8
10
  end
9
11
 
10
12
  it 'creates a RegularExpression' do
@@ -1,86 +1,81 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/cucumber_expressions/parameter_type_registry'
2
4
  require 'cucumber/cucumber_expressions/parameter_type'
3
5
  require 'cucumber/cucumber_expressions/errors'
4
6
 
5
7
  module Cucumber
6
8
  module CucumberExpressions
9
+ CAPITALISED_WORD = /[A-Z]+\w+/.freeze
7
10
 
8
- CAPITALISED_WORD = /[A-Z]+\w+/
9
-
10
- class Name
11
- end
12
-
13
- class Person
14
- end
15
-
16
- class Place
17
- end
11
+ class Name; end
12
+ class Person; end
13
+ class Place; end
18
14
 
19
15
  describe ParameterTypeRegistry do
20
16
  before do
21
- @registry = ParameterTypeRegistry.new
17
+ @registry = described_class.new
22
18
  end
23
19
 
24
20
  it 'does not allow more than one prefer_for_regexp_match parameter type for each regexp' do
25
- @registry.define_parameter_type(ParameterType.new("name", CAPITALISED_WORD, Name, lambda {|s| Name.new}, true, true))
26
- @registry.define_parameter_type(ParameterType.new("person", CAPITALISED_WORD, Person, lambda {|s| Person.new}, true, false))
21
+ @registry.define_parameter_type(ParameterType.new('name', CAPITALISED_WORD, Name, ->(_) { Name.new }, true, true))
22
+ @registry.define_parameter_type(ParameterType.new('person', CAPITALISED_WORD, Person, ->(_) { Person.new }, true, false))
27
23
  expect do
28
- @registry.define_parameter_type(ParameterType.new("place", CAPITALISED_WORD, Place, lambda {|s| Place.new}, true, true))
24
+ @registry.define_parameter_type(ParameterType.new('place', CAPITALISED_WORD, Place, ->(_) { Place.new }, true, true))
29
25
  end.to raise_error(
30
- CucumberExpressionError,
31
- "There can only be one preferential parameter type per regexp. The regexp /[A-Z]+\\w+/ is used for two preferential parameter types, {name} and {place}"
32
- )
26
+ CucumberExpressionError,
27
+ 'There can only be one preferential parameter type per regexp. The regexp /[A-Z]+\\w+/ is used for two: {name} and {place}'
28
+ )
33
29
  end
34
30
 
35
31
  it 'looks up prefer_for_regexp_match parameter type by regexp' do
36
- name = ParameterType.new("name", CAPITALISED_WORD, Name, lambda {|s| Name.new}, true, false)
37
- person = ParameterType.new("person", CAPITALISED_WORD, Person, lambda {|s| Person.new}, true, true)
38
- place = ParameterType.new("place", CAPITALISED_WORD, Place, lambda {|s| Place.new}, true, false)
32
+ name = ParameterType.new('name', CAPITALISED_WORD, Name, ->(_) { Name.new }, true, false)
33
+ person = ParameterType.new('person', CAPITALISED_WORD, Person, ->(_) { Person.new }, true, true)
34
+ place = ParameterType.new('place', CAPITALISED_WORD, Place, ->(_) { Place.new }, true, false)
39
35
 
40
36
  @registry.define_parameter_type(name)
41
37
  @registry.define_parameter_type(person)
42
38
  @registry.define_parameter_type(place)
43
39
 
44
- expect(@registry.lookup_by_regexp(CAPITALISED_WORD.source, /([A-Z]+\w+) and ([A-Z]+\w+)/, "Lisa and Bob")).to eq(person)
40
+ expect(@registry.lookup_by_regexp(CAPITALISED_WORD.source, /([A-Z]+\w+) and ([A-Z]+\w+)/, 'Lisa and Bob')).to eq(person)
45
41
  end
46
42
 
47
43
  it 'throws ambiguous exception when no parameter types are prefer_for_regexp_match' do
48
- name = ParameterType.new("name", CAPITALISED_WORD, Name, lambda {|s| Name.new}, true, false)
49
- person = ParameterType.new("person", CAPITALISED_WORD, Person, lambda {|s| Person.new}, true, false)
50
- place = ParameterType.new("place", CAPITALISED_WORD, Place, lambda {|s| Place.new}, true, false)
44
+ name = ParameterType.new('name', CAPITALISED_WORD, Name, ->(_) { Name.new }, true, false)
45
+ person = ParameterType.new('person', CAPITALISED_WORD, Person, ->(_) { Person.new }, true, false)
46
+ place = ParameterType.new('place', CAPITALISED_WORD, Place, ->(_) { Place.new }, true, false)
51
47
 
52
48
  @registry.define_parameter_type(name)
53
49
  @registry.define_parameter_type(person)
54
50
  @registry.define_parameter_type(place)
55
51
 
56
52
  expect do
57
- expect(@registry.lookup_by_regexp(CAPITALISED_WORD.source, /([A-Z]+\w+) and ([A-Z]+\w+)/, "Lisa and Bob")).to eq(person)
53
+ expect(@registry.lookup_by_regexp(CAPITALISED_WORD.source, /([A-Z]+\w+) and ([A-Z]+\w+)/, 'Lisa and Bob')).to eq(person)
58
54
  end.to raise_error(
59
- CucumberExpressionError,
60
- "Your Regular Expression /([A-Z]+\\w+) and ([A-Z]+\\w+)/\n" +
61
- "matches multiple parameter types with regexp /[A-Z]+\\w+/:\n" +
62
- " {name}\n" +
63
- " {person}\n" +
64
- " {place}\n" +
65
- "\n" +
66
- "I couldn't decide which one to use. You have two options:\n" +
67
- "\n" +
68
- "1) Use a Cucumber Expression instead of a Regular Expression. Try one of these:\n" +
69
- " {name} and {name}\n" +
70
- " {name} and {person}\n" +
71
- " {name} and {place}\n" +
72
- " {person} and {name}\n" +
73
- " {person} and {person}\n" +
74
- " {person} and {place}\n" +
75
- " {place} and {name}\n" +
76
- " {place} and {person}\n" +
77
- " {place} and {place}\n" +
78
- "\n" +
79
- "2) Make one of the parameter types preferential and continue to use a Regular Expression.\n" +
80
- "\n"
81
- )
55
+ CucumberExpressionError,
56
+ "Your Regular Expression /([A-Z]+\\w+) and ([A-Z]+\\w+)/\n" \
57
+ "matches multiple parameter types with regexp /[A-Z]+\\w+/:\n " \
58
+ "{name}\n " \
59
+ "{person}\n " \
60
+ "{place}\n" \
61
+ "\n" \
62
+ "I couldn't decide which one to use. You have two options:\n" \
63
+ "\n" \
64
+ "1) Use a Cucumber Expression instead of a Regular Expression. Try one of these:\n " \
65
+ "{name} and {name}\n " \
66
+ "{name} and {person}\n " \
67
+ "{name} and {place}\n " \
68
+ "{person} and {name}\n " \
69
+ "{person} and {person}\n " \
70
+ "{person} and {place}\n " \
71
+ "{place} and {name}\n " \
72
+ "{place} and {person}\n " \
73
+ "{place} and {place}\n" \
74
+ "\n" \
75
+ "2) Make one of the parameter types preferential and continue to use a Regular Expression.\n" \
76
+ "\n"
77
+ )
82
78
  end
83
79
  end
84
80
  end
85
81
  end
86
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/cucumber_expressions/parameter_type'
2
4
 
3
5
  module Cucumber
@@ -5,10 +7,11 @@ module Cucumber
5
7
  describe ParameterType do
6
8
  it 'does not allow ignore flag on regexp' do
7
9
  expect do
8
- ParameterType.new("case-insensitive", /[a-z]+/i, String, lambda {|s| s}, true, true)
10
+ described_class.new('case-insensitive', /[a-z]+/i, String, ->(s) { s }, true, true)
9
11
  end.to raise_error(
10
12
  CucumberExpressionError,
11
- "ParameterType Regexps can't use option Regexp::IGNORECASE")
13
+ "ParameterType Regexps can't use option Regexp::IGNORECASE"
14
+ )
12
15
  end
13
16
  end
14
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'cucumber/cucumber_expressions/regular_expression'
3
5
  require 'cucumber/cucumber_expressions/parameter_type_registry'
@@ -7,68 +9,74 @@ module Cucumber
7
9
  describe RegularExpression do
8
10
  Dir['../testdata/regular-expression/matching/*.yaml'].each do |path|
9
11
  expectation = YAML.load_file(path)
12
+
10
13
  it "matches #{path}" do
11
14
  parameter_registry = ParameterTypeRegistry.new
12
- expression = RegularExpression.new(Regexp.new(expectation['expression']), parameter_registry)
15
+ expression = described_class.new(Regexp.new(expectation['expression']), parameter_registry)
13
16
  matches = expression.match(expectation['text'])
14
17
  values = matches.map { |arg| arg.value(nil) }
18
+
15
19
  expect(values).to eq(expectation['expected_args'])
16
20
  end
17
21
  end
18
22
 
19
- it "does no transform by default" do
20
- expect( match(/(\d\d)/, "22") ).to eq(["22"])
23
+ it 'does not transform by default' do
24
+ expect(match(/(\d\d)/, '22')).to eq(['22'])
21
25
  end
22
26
 
23
- it "does not transform anonymous" do
24
- expect( match(/(.*)/, "22") ).to eq(["22"])
27
+ it 'does not transform anonymous' do
28
+ expect(match(/(.*)/, '22')).to eq(['22'])
25
29
  end
26
30
 
27
- it "transforms negative int" do
28
- expect( match(/(-?\d+)/, "-22") ).to eq([-22])
31
+ it 'transforms negative int' do
32
+ expect(match(/(-?\d+)/, '-22')).to eq([-22])
29
33
  end
30
34
 
31
- it "transforms positive int" do
32
- expect( match(/(\d+)/, "22") ).to eq([22])
35
+ it 'transforms positive int' do
36
+ expect(match(/(\d+)/, '22')).to eq([22])
33
37
  end
34
38
 
35
- it "returns nil when there is no match" do
36
- expect( match(/hello/, "world") ).to be_nil
39
+ it 'returns nil when there is no match' do
40
+ expect(match(/hello/, 'world')).to be_nil
37
41
  end
38
42
 
39
- it "matches empty string when there is an empty string match" do
40
- expect( match(/^The value equals "([^"]*)"$/, 'The value equals ""') ).to eq([''])
43
+ it 'matches empty string when there is an empty string match' do
44
+ expect(match(/^The value equals "([^"]*)"$/, 'The value equals ""')).to eq([''])
41
45
  end
42
46
 
43
- it "matches nested capture group without match" do
44
- expect( match(/^a user( named "([^"]*)")?$/, 'a user') ).to eq([nil])
47
+ it 'matches nested capture group without match' do
48
+ expect(match(/^a user( named "([^"]*)")?$/, 'a user')).to eq([nil])
45
49
  end
46
50
 
47
- it "matches nested capture group with match" do
48
- expect( match(/^a user( named "([^"]*)")?$/, 'a user named "Charlie"') ).to eq(['Charlie'])
51
+ it 'matches nested capture group with match' do
52
+ expect(match(/^a user( named "([^"]*)")?$/, 'a user named "Charlie"')).to eq(['Charlie'])
49
53
  end
50
54
 
51
- it "ignores non capturing groups" do
52
- expect( match(
53
- /(\S+) ?(can|cannot) (?:delete|cancel) the (\d+)(?:st|nd|rd|th) (attachment|slide) ?(?:upload)?/,
54
- "I can cancel the 1st slide upload")
55
- ).to eq(["I", "can", 1, "slide"])
55
+ it 'ignores non capturing groups' do
56
+ expect(
57
+ match(
58
+ /(\S+) ?(can|cannot) (?:delete|cancel) the (\d+)(?:st|nd|rd|th) (attachment|slide) ?(?:upload)?/,
59
+ 'I can cancel the 1st slide upload'
60
+ )
61
+ ).to eq(['I', 'can', 1, 'slide'])
56
62
  end
57
63
 
58
- it "matches capture group nested in optional one" do
64
+ it 'matches capture group nested in optional one' do
59
65
  regexp = /^a (pre-commercial transaction |pre buyer fee model )?purchase(?: for \$(\d+))?$/
60
- expect( match(regexp, 'a purchase') ).to eq([nil, nil])
61
- expect( match(regexp, 'a purchase for $33') ).to eq([nil, 33])
62
- expect( match(regexp, 'a pre buyer fee model purchase') ).to eq(['pre buyer fee model ', nil])
66
+
67
+ expect(match(regexp, 'a purchase')).to eq([nil, nil])
68
+ expect(match(regexp, 'a purchase for $33')).to eq([nil, 33])
69
+ expect(match(regexp, 'a pre buyer fee model purchase')).to eq(['pre buyer fee model ', nil])
63
70
  end
64
71
 
65
- it "works with escaped parenthesis" do
66
- expect( match(/Across the line\(s\)/, 'Across the line(s)') ).to eq([])
72
+ it 'works with escaped parentheses' do
73
+ expect(match(/Across the line\(s\)/, 'Across the line(s)')).to eq([])
67
74
  end
68
75
 
69
- it "exposes source and regexp" do
76
+ it 'exposes source and regexp' do
70
77
  regexp = /I have (\d+) cukes? in my (\+) now/
71
- expression = RegularExpression.new(regexp, ParameterTypeRegistry.new)
78
+ expression = described_class.new(regexp, ParameterTypeRegistry.new)
79
+
72
80
  expect(expression.regexp).to eq(regexp)
73
81
  expect(expression.source).to eq(regexp.source)
74
82
  end
@@ -77,6 +85,7 @@ module Cucumber
77
85
  regular_expression = RegularExpression.new(expression, ParameterTypeRegistry.new)
78
86
  arguments = regular_expression.match(text)
79
87
  return nil if arguments.nil?
88
+
80
89
  arguments.map { |arg| arg.value(nil) }
81
90
  end
82
91
  end