cucumber-gherkin 19.0.3 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/gherkin +1 -1
- data/lib/gherkin.rb +3 -3
- data/lib/gherkin/ast_builder.rb +43 -43
- data/lib/gherkin/gherkin-languages.json +42 -1
- data/lib/gherkin/pickles/compiler.rb +74 -74
- data/lib/gherkin/query.rb +19 -16
- data/lib/gherkin/stream/parser_message_stream.rb +22 -19
- data/spec/gherkin/query_spec.rb +49 -45
- data/spec/gherkin/stream/parser_message_stream_spec.rb +5 -5
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad9f2d6bb3c1594a8a5d18f8da1bdd37c4e19398f96786332291710beae19124
|
4
|
+
data.tar.gz: 983b5a2d737845653dcec99d6e9f7c3c055c592de4f120c118d31db375fd30ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d52892a66d0bd8bdf409c8024c07dd0761ad4451501379113ff30845b4a66258611ea14e7dd8f087daede5a10ecf42214bc4e55ed6b484096f52fb7258fbaa
|
7
|
+
data.tar.gz: 460f947e61b2401924bb6899fd08a4b35205432e6b3eb312037a17ffa249d98effc30e10b686d63c15676b74c265351ed4451f4df0dbff5bce6a0be5efe8a246
|
data/bin/gherkin
CHANGED
data/lib/gherkin.rb
CHANGED
@@ -30,10 +30,10 @@ module Gherkin
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def self.encode_source_message(uri, data)
|
33
|
-
|
33
|
+
Cucumber::Messages::Source.new(
|
34
34
|
uri: uri,
|
35
35
|
data: data,
|
36
|
-
|
37
|
-
|
36
|
+
media_type: 'text/x.cucumber.gherkin+plain'
|
37
|
+
)
|
38
38
|
end
|
39
39
|
end
|
data/lib/gherkin/ast_builder.rb
CHANGED
@@ -24,10 +24,10 @@ module Gherkin
|
|
24
24
|
|
25
25
|
def build(token)
|
26
26
|
if token.matched_type == :Comment
|
27
|
-
@comments.push(
|
27
|
+
@comments.push(Cucumber::Messages::Comment.new(
|
28
28
|
location: get_location(token, 0),
|
29
29
|
text: token.matched_text
|
30
|
-
|
30
|
+
))
|
31
31
|
else
|
32
32
|
current_node.add(token.matched_type, token)
|
33
33
|
end
|
@@ -43,10 +43,10 @@ module Gherkin
|
|
43
43
|
|
44
44
|
def get_location(token, column)
|
45
45
|
column = column == 0 ? token.location[:column] : column
|
46
|
-
|
46
|
+
Cucumber::Messages::Location.new(
|
47
47
|
line: token.location[:line],
|
48
48
|
column: column
|
49
|
-
|
49
|
+
)
|
50
50
|
end
|
51
51
|
|
52
52
|
def get_tags(node)
|
@@ -56,11 +56,11 @@ module Gherkin
|
|
56
56
|
|
57
57
|
tags_node.get_tokens(:TagLine).each do |token|
|
58
58
|
token.matched_items.each do |tag_item|
|
59
|
-
tags.push(
|
59
|
+
tags.push(Cucumber::Messages::Tag.new(
|
60
60
|
location: get_location(token, tag_item.column),
|
61
61
|
name: tag_item.text,
|
62
62
|
id: @id_generator.new_id
|
63
|
-
|
63
|
+
))
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -69,11 +69,11 @@ module Gherkin
|
|
69
69
|
|
70
70
|
def get_table_rows(node)
|
71
71
|
rows = node.get_tokens(:TableRow).map do |token|
|
72
|
-
|
72
|
+
Cucumber::Messages::TableRow.new(
|
73
73
|
id: @id_generator.new_id,
|
74
74
|
location: get_location(token, 0),
|
75
75
|
cells: get_cells(token)
|
76
|
-
|
76
|
+
)
|
77
77
|
end
|
78
78
|
ensure_cell_count(rows)
|
79
79
|
rows
|
@@ -81,20 +81,20 @@ module Gherkin
|
|
81
81
|
|
82
82
|
def ensure_cell_count(rows)
|
83
83
|
return if rows.empty?
|
84
|
-
cell_count = rows[0]
|
84
|
+
cell_count = rows[0].cells.length
|
85
85
|
rows.each do |row|
|
86
|
-
if row
|
87
|
-
raise AstBuilderException.new("inconsistent cell count within the table", row
|
86
|
+
if row.cells.length != cell_count
|
87
|
+
raise AstBuilderException.new("inconsistent cell count within the table", row.location.to_h)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
def get_cells(table_row_token)
|
93
93
|
table_row_token.matched_items.map do |cell_item|
|
94
|
-
|
94
|
+
Cucumber::Messages::TableCell.new(
|
95
95
|
location: get_location(table_row_token, cell_item.column),
|
96
96
|
value: cell_item.text
|
97
|
-
|
97
|
+
)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -113,45 +113,45 @@ module Gherkin
|
|
113
113
|
data_table = node.get_single(:DataTable)
|
114
114
|
doc_string = node.get_single(:DocString)
|
115
115
|
|
116
|
-
step =
|
116
|
+
step = Cucumber::Messages::Step.new(
|
117
117
|
location: get_location(step_line, 0),
|
118
118
|
keyword: step_line.matched_keyword,
|
119
119
|
text: step_line.matched_text,
|
120
|
-
|
121
|
-
|
120
|
+
data_table: data_table,
|
121
|
+
doc_string: doc_string,
|
122
122
|
id: @id_generator.new_id
|
123
|
-
|
123
|
+
)
|
124
124
|
when :DocString
|
125
125
|
separator_token = node.get_tokens(:DocStringSeparator)[0]
|
126
126
|
media_type = separator_token.matched_text == '' ? nil : separator_token.matched_text
|
127
127
|
line_tokens = node.get_tokens(:Other)
|
128
128
|
content = line_tokens.map { |t| t.matched_text }.join("\n")
|
129
129
|
|
130
|
-
|
130
|
+
Cucumber::Messages::DocString.new(
|
131
131
|
location: get_location(separator_token, 0),
|
132
132
|
content: content,
|
133
133
|
delimiter: separator_token.matched_keyword,
|
134
|
-
|
135
|
-
|
134
|
+
media_type: media_type
|
135
|
+
)
|
136
136
|
when :DataTable
|
137
137
|
rows = get_table_rows(node)
|
138
|
-
|
139
|
-
location: rows[0]
|
140
|
-
rows: rows
|
141
|
-
|
138
|
+
Cucumber::Messages::DataTable.new(
|
139
|
+
location: rows[0].location,
|
140
|
+
rows: rows
|
141
|
+
)
|
142
142
|
when :Background
|
143
143
|
background_line = node.get_token(:BackgroundLine)
|
144
144
|
description = get_description(node)
|
145
145
|
steps = get_steps(node)
|
146
146
|
|
147
|
-
|
147
|
+
Cucumber::Messages::Background.new(
|
148
148
|
id: @id_generator.new_id,
|
149
149
|
location: get_location(background_line, 0),
|
150
150
|
keyword: background_line.matched_keyword,
|
151
151
|
name: background_line.matched_text,
|
152
152
|
description: description,
|
153
153
|
steps: steps
|
154
|
-
|
154
|
+
)
|
155
155
|
when :ScenarioDefinition
|
156
156
|
tags = get_tags(node)
|
157
157
|
scenario_node = node.get_single(:Scenario)
|
@@ -159,7 +159,7 @@ module Gherkin
|
|
159
159
|
description = get_description(scenario_node)
|
160
160
|
steps = get_steps(scenario_node)
|
161
161
|
examples = scenario_node.get_items(:ExamplesDefinition)
|
162
|
-
|
162
|
+
Cucumber::Messages::Scenario.new(
|
163
163
|
id: @id_generator.new_id,
|
164
164
|
tags: tags,
|
165
165
|
location: get_location(scenario_line, 0),
|
@@ -168,7 +168,7 @@ module Gherkin
|
|
168
168
|
description: description,
|
169
169
|
steps: steps,
|
170
170
|
examples: examples
|
171
|
-
|
171
|
+
)
|
172
172
|
when :ExamplesDefinition
|
173
173
|
tags = get_tags(node)
|
174
174
|
examples_node = node.get_single(:Examples)
|
@@ -179,16 +179,16 @@ module Gherkin
|
|
179
179
|
table_header = rows.nil? ? nil : rows.first
|
180
180
|
table_body = rows.nil? ? [] : rows[1..-1]
|
181
181
|
|
182
|
-
|
182
|
+
Cucumber::Messages::Examples.new(
|
183
183
|
id: @id_generator.new_id,
|
184
184
|
tags: tags,
|
185
185
|
location: get_location(examples_line, 0),
|
186
186
|
keyword: examples_line.matched_keyword,
|
187
187
|
name: examples_line.matched_text,
|
188
188
|
description: description,
|
189
|
-
|
190
|
-
|
191
|
-
|
189
|
+
table_header: table_header,
|
190
|
+
table_body: table_body
|
191
|
+
)
|
192
192
|
when :ExamplesTable
|
193
193
|
get_table_rows(node)
|
194
194
|
when :Description
|
@@ -205,17 +205,17 @@ module Gherkin
|
|
205
205
|
return unless feature_line
|
206
206
|
children = []
|
207
207
|
background = node.get_single(:Background)
|
208
|
-
children.push(
|
208
|
+
children.push(Cucumber::Messages::FeatureChild.new(background: background)) if background
|
209
209
|
node.get_items(:ScenarioDefinition).each do |scenario|
|
210
|
-
children.push(
|
210
|
+
children.push(Cucumber::Messages::FeatureChild.new(scenario: scenario))
|
211
211
|
end
|
212
212
|
node.get_items(:Rule).each do |rule|
|
213
|
-
children.push(
|
213
|
+
children.push(Cucumber::Messages::FeatureChild.new(rule: rule))
|
214
214
|
end
|
215
215
|
description = get_description(header)
|
216
216
|
language = feature_line.matched_gherkin_dialect
|
217
217
|
|
218
|
-
|
218
|
+
Cucumber::Messages::Feature.new(
|
219
219
|
tags: tags,
|
220
220
|
location: get_location(feature_line, 0),
|
221
221
|
language: language,
|
@@ -223,7 +223,7 @@ module Gherkin
|
|
223
223
|
name: feature_line.matched_text,
|
224
224
|
description: description,
|
225
225
|
children: children,
|
226
|
-
|
226
|
+
)
|
227
227
|
when :Rule
|
228
228
|
header = node.get_single(:RuleHeader)
|
229
229
|
return unless header
|
@@ -232,13 +232,13 @@ module Gherkin
|
|
232
232
|
tags = get_tags(header)
|
233
233
|
children = []
|
234
234
|
background = node.get_single(:Background)
|
235
|
-
children.push(
|
235
|
+
children.push(Cucumber::Messages::RuleChild.new(background: background)) if background
|
236
236
|
node.get_items(:ScenarioDefinition).each do |scenario|
|
237
|
-
children.push(
|
237
|
+
children.push(Cucumber::Messages::RuleChild.new(scenario: scenario))
|
238
238
|
end
|
239
239
|
description = get_description(header)
|
240
240
|
|
241
|
-
|
241
|
+
Cucumber::Messages::Rule.new(
|
242
242
|
id: @id_generator.new_id,
|
243
243
|
tags: tags,
|
244
244
|
location: get_location(rule_line, 0),
|
@@ -246,13 +246,13 @@ module Gherkin
|
|
246
246
|
name: rule_line.matched_text,
|
247
247
|
description: description,
|
248
248
|
children: children,
|
249
|
-
|
249
|
+
)
|
250
250
|
when :GherkinDocument
|
251
251
|
feature = node.get_single(:Feature)
|
252
|
-
|
252
|
+
Cucumber::Messages::GherkinDocument.new(
|
253
253
|
comments: @comments,
|
254
254
|
feature: feature
|
255
|
-
|
255
|
+
)
|
256
256
|
else
|
257
257
|
return node
|
258
258
|
end
|
@@ -1013,6 +1013,46 @@
|
|
1013
1013
|
"* ",
|
1014
1014
|
"Blimey! "
|
1015
1015
|
]
|
1016
|
+
},
|
1017
|
+
"en-tx": {
|
1018
|
+
"and": [
|
1019
|
+
"Come hell or high water "
|
1020
|
+
],
|
1021
|
+
"background": [
|
1022
|
+
"Lemme tell y'all a story"
|
1023
|
+
],
|
1024
|
+
"but": [
|
1025
|
+
"Well now hold on, I'll you what "
|
1026
|
+
],
|
1027
|
+
"examples": [
|
1028
|
+
"Now that's a story longer than a cattle drive in July"
|
1029
|
+
],
|
1030
|
+
"feature": [
|
1031
|
+
"This ain’t my first rodeo",
|
1032
|
+
"All gussied up"
|
1033
|
+
],
|
1034
|
+
"given": [
|
1035
|
+
"Fixin' to ",
|
1036
|
+
"All git out "
|
1037
|
+
],
|
1038
|
+
"name": "Texas",
|
1039
|
+
"native": "Texas",
|
1040
|
+
"rule": [
|
1041
|
+
"Rule "
|
1042
|
+
],
|
1043
|
+
"scenario": [
|
1044
|
+
"All hat and no cattle"
|
1045
|
+
],
|
1046
|
+
"scenarioOutline": [
|
1047
|
+
"Serious as a snake bite",
|
1048
|
+
"Busy as a hound in flea season"
|
1049
|
+
],
|
1050
|
+
"then": [
|
1051
|
+
"There’s no tree but bears some fruit "
|
1052
|
+
],
|
1053
|
+
"when": [
|
1054
|
+
"Quick out of the chute "
|
1055
|
+
]
|
1016
1056
|
},
|
1017
1057
|
"eo": {
|
1018
1058
|
"and": [
|
@@ -2566,7 +2606,8 @@
|
|
2566
2606
|
"name": "Polish",
|
2567
2607
|
"native": "polski",
|
2568
2608
|
"rule": [
|
2569
|
-
"
|
2609
|
+
"Zasada",
|
2610
|
+
"Reguła"
|
2570
2611
|
],
|
2571
2612
|
"scenario": [
|
2572
2613
|
"Przykład",
|
@@ -8,10 +8,10 @@ module Gherkin
|
|
8
8
|
def compile(gherkin_document, source)
|
9
9
|
pickles = []
|
10
10
|
|
11
|
-
return pickles unless gherkin_document
|
12
|
-
feature = gherkin_document
|
13
|
-
language = feature
|
14
|
-
tags = feature
|
11
|
+
return pickles unless gherkin_document.feature
|
12
|
+
feature = gherkin_document.feature
|
13
|
+
language = feature.language
|
14
|
+
tags = feature.tags
|
15
15
|
|
16
16
|
compile_feature(pickles, language, tags, feature, source)
|
17
17
|
pickles
|
@@ -21,14 +21,14 @@ module Gherkin
|
|
21
21
|
|
22
22
|
def compile_feature(pickles, language, tags, feature, source)
|
23
23
|
feature_background_steps = []
|
24
|
-
feature
|
25
|
-
if child
|
26
|
-
feature_background_steps.concat(child
|
27
|
-
elsif child
|
28
|
-
compile_rule(pickles, language, tags, feature_background_steps, child
|
24
|
+
feature.children.each do |child|
|
25
|
+
if child.background
|
26
|
+
feature_background_steps.concat(child.background.steps)
|
27
|
+
elsif child.rule
|
28
|
+
compile_rule(pickles, language, tags, feature_background_steps, child.rule, source)
|
29
29
|
else
|
30
|
-
scenario = child
|
31
|
-
if scenario
|
30
|
+
scenario = child.scenario
|
31
|
+
if scenario.examples.empty?
|
32
32
|
compile_scenario(tags, feature_background_steps, scenario, language, pickles, source)
|
33
33
|
else
|
34
34
|
compile_scenario_outline(tags, feature_background_steps, scenario, language, pickles, source)
|
@@ -38,15 +38,15 @@ module Gherkin
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def compile_rule(pickles, language, feature_tags, feature_background_steps, rule, source)
|
41
|
-
tags = [].concat(feature_tags).concat(rule
|
41
|
+
tags = [].concat(feature_tags).concat(rule.tags)
|
42
42
|
|
43
43
|
rule_background_steps = feature_background_steps.dup
|
44
|
-
rule
|
45
|
-
if child
|
46
|
-
rule_background_steps.concat(child
|
44
|
+
rule.children.each do |child|
|
45
|
+
if child.background
|
46
|
+
rule_background_steps.concat(child.background.steps)
|
47
47
|
else
|
48
|
-
scenario = child
|
49
|
-
if scenario
|
48
|
+
scenario = child.scenario
|
49
|
+
if scenario.examples.empty?
|
50
50
|
compile_scenario(tags, rule_background_steps, scenario, language, pickles, source)
|
51
51
|
else
|
52
52
|
compile_scenario_outline(tags, rule_background_steps, scenario, language, pickles, source)
|
@@ -56,51 +56,51 @@ module Gherkin
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def compile_scenario(inherited_tags, background_steps, scenario, language, pickles, source)
|
59
|
-
steps = scenario
|
59
|
+
steps = scenario.steps.empty? ? [] : [].concat(pickle_steps(background_steps))
|
60
60
|
|
61
|
-
tags = [].concat(inherited_tags).concat(scenario
|
61
|
+
tags = [].concat(inherited_tags).concat(scenario.tags)
|
62
62
|
|
63
|
-
scenario
|
63
|
+
scenario.steps.each do |step|
|
64
64
|
steps.push(pickle_step(step))
|
65
65
|
end
|
66
66
|
|
67
|
-
pickle =
|
68
|
-
uri: source
|
67
|
+
pickle = Cucumber::Messages::Pickle.new(
|
68
|
+
uri: source.uri,
|
69
69
|
id: @id_generator.new_id,
|
70
70
|
tags: pickle_tags(tags),
|
71
|
-
name: scenario
|
71
|
+
name: scenario.name,
|
72
72
|
language: language,
|
73
|
-
|
73
|
+
ast_node_ids: [scenario.id],
|
74
74
|
steps: steps
|
75
|
-
|
75
|
+
)
|
76
76
|
pickles.push(pickle)
|
77
77
|
end
|
78
78
|
|
79
79
|
def compile_scenario_outline(inherited_tags, background_steps, scenario, language, pickles, source)
|
80
|
-
scenario
|
81
|
-
variable_cells = examples
|
82
|
-
examples
|
83
|
-
value_cells = values_row
|
84
|
-
steps = scenario
|
85
|
-
tags = [].concat(inherited_tags).concat(scenario
|
86
|
-
|
87
|
-
scenario
|
88
|
-
|
89
|
-
steps.push(
|
80
|
+
scenario.examples.reject { |examples| examples.table_header.nil? }.each do |examples|
|
81
|
+
variable_cells = examples.table_header.cells
|
82
|
+
examples.table_body.each do |values_row|
|
83
|
+
value_cells = values_row.cells
|
84
|
+
steps = scenario.steps.empty? ? [] : [].concat(pickle_steps(background_steps))
|
85
|
+
tags = [].concat(inherited_tags).concat(scenario.tags).concat(examples.tags)
|
86
|
+
|
87
|
+
scenario.steps.each do |scenario_step|
|
88
|
+
step_props = pickle_step_props(scenario_step, variable_cells, values_row)
|
89
|
+
steps.push(Cucumber::Messages::PickleStep.new(**step_props))
|
90
90
|
end
|
91
91
|
|
92
|
-
pickle =
|
93
|
-
uri: source
|
92
|
+
pickle = Cucumber::Messages::Pickle.new(
|
93
|
+
uri: source.uri,
|
94
94
|
id: @id_generator.new_id,
|
95
|
-
name: interpolate(scenario
|
95
|
+
name: interpolate(scenario.name, variable_cells, value_cells),
|
96
96
|
language: language,
|
97
97
|
steps: steps,
|
98
98
|
tags: pickle_tags(tags),
|
99
|
-
|
100
|
-
scenario
|
101
|
-
values_row
|
102
|
-
]
|
103
|
-
|
99
|
+
ast_node_ids: [
|
100
|
+
scenario.id,
|
101
|
+
values_row.id
|
102
|
+
]
|
103
|
+
)
|
104
104
|
pickles.push(pickle)
|
105
105
|
|
106
106
|
end
|
@@ -110,7 +110,7 @@ module Gherkin
|
|
110
110
|
def interpolate(name, variable_cells, value_cells)
|
111
111
|
variable_cells.each_with_index do |variable_cell, n|
|
112
112
|
value_cell = value_cells[n]
|
113
|
-
name = name.gsub('<' + variable_cell
|
113
|
+
name = name.gsub('<' + variable_cell.value + '>', value_cell.value)
|
114
114
|
end
|
115
115
|
name
|
116
116
|
end
|
@@ -122,57 +122,57 @@ module Gherkin
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def pickle_step(step)
|
125
|
-
pickle_step_props(step, [], nil)
|
125
|
+
Cucumber::Messages::PickleStep.new(**pickle_step_props(step, [], nil))
|
126
126
|
end
|
127
127
|
|
128
128
|
def pickle_step_props(step, variable_cells, values_row)
|
129
|
-
value_cells = values_row ? values_row
|
129
|
+
value_cells = values_row ? values_row.cells : []
|
130
130
|
props = {
|
131
131
|
id: @id_generator.new_id,
|
132
|
-
|
133
|
-
text: interpolate(step
|
132
|
+
ast_node_ids: [step.id],
|
133
|
+
text: interpolate(step.text, variable_cells, value_cells),
|
134
134
|
}
|
135
135
|
if values_row
|
136
|
-
props[:
|
136
|
+
props[:ast_node_ids].push(values_row.id)
|
137
137
|
end
|
138
138
|
|
139
|
-
if step
|
140
|
-
data_table =
|
141
|
-
|
142
|
-
|
139
|
+
if step.data_table
|
140
|
+
data_table = Cucumber::Messages::PickleStepArgument.new(
|
141
|
+
data_table: pickle_data_table(step.data_table, variable_cells, value_cells)
|
142
|
+
)
|
143
143
|
props[:argument] = data_table
|
144
144
|
end
|
145
|
-
if step
|
146
|
-
doc_string =
|
147
|
-
|
148
|
-
|
145
|
+
if step.doc_string
|
146
|
+
doc_string = Cucumber::Messages::PickleStepArgument.new(
|
147
|
+
doc_string: pickle_doc_string(step.doc_string, variable_cells, value_cells)
|
148
|
+
)
|
149
149
|
props[:argument] = doc_string
|
150
150
|
end
|
151
151
|
props
|
152
152
|
end
|
153
153
|
|
154
154
|
def pickle_data_table(data_table, variable_cells, value_cells)
|
155
|
-
|
156
|
-
rows: data_table
|
157
|
-
|
158
|
-
cells: row
|
159
|
-
|
160
|
-
value: interpolate(cell
|
161
|
-
|
155
|
+
Cucumber::Messages::PickleTable.new(
|
156
|
+
rows: data_table.rows.map do |row|
|
157
|
+
Cucumber::Messages::PickleTableRow.new(
|
158
|
+
cells: row.cells.map do |cell|
|
159
|
+
Cucumber::Messages::PickleTableCell.new(
|
160
|
+
value: interpolate(cell.value, variable_cells, value_cells)
|
161
|
+
)
|
162
162
|
end
|
163
|
-
|
163
|
+
)
|
164
164
|
end
|
165
|
-
|
165
|
+
)
|
166
166
|
end
|
167
167
|
|
168
168
|
def pickle_doc_string(doc_string, variable_cells, value_cells)
|
169
169
|
props = {
|
170
|
-
content: interpolate(doc_string
|
170
|
+
content: interpolate(doc_string.content, variable_cells, value_cells)
|
171
171
|
}
|
172
|
-
if doc_string
|
173
|
-
props[:
|
172
|
+
if doc_string.media_type
|
173
|
+
props[:media_type] = interpolate(doc_string.media_type, variable_cells, value_cells)
|
174
174
|
end
|
175
|
-
props
|
175
|
+
Cucumber::Messages::PickleDocString.new(**props)
|
176
176
|
end
|
177
177
|
|
178
178
|
def pickle_tags(tags)
|
@@ -180,10 +180,10 @@ module Gherkin
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def pickle_tag(tag)
|
183
|
-
|
184
|
-
name: tag
|
185
|
-
|
186
|
-
|
183
|
+
Cucumber::Messages::PickleTag.new(
|
184
|
+
name: tag.name,
|
185
|
+
ast_node_id: tag.id
|
186
|
+
)
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
data/lib/gherkin/query.rb
CHANGED
@@ -5,7 +5,7 @@ module Gherkin
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def update(message)
|
8
|
-
update_feature(message
|
8
|
+
update_feature(message.gherkin_document.feature) if message.gherkin_document
|
9
9
|
end
|
10
10
|
|
11
11
|
def location(ast_node_id)
|
@@ -17,33 +17,36 @@ module Gherkin
|
|
17
17
|
|
18
18
|
def update_feature(feature)
|
19
19
|
return if feature.nil?
|
20
|
-
store_nodes_location(feature
|
20
|
+
store_nodes_location(feature.tags)
|
21
21
|
|
22
|
-
feature
|
23
|
-
update_rule(child
|
24
|
-
update_background(child
|
25
|
-
update_scenario(child
|
22
|
+
feature.children.each do |child|
|
23
|
+
update_rule(child.rule) if child.rule
|
24
|
+
update_background(child.background) if child.background
|
25
|
+
update_scenario(child.scenario) if child.scenario
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def update_rule(rule)
|
30
|
-
rule
|
31
|
-
|
32
|
-
|
30
|
+
return if rule.nil?
|
31
|
+
store_nodes_location(rule.tags)
|
32
|
+
|
33
|
+
rule.children.each do |child|
|
34
|
+
update_background(child.background) if child.background
|
35
|
+
update_scenario(child.scenario) if child.scenario
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
39
|
def update_background(background)
|
37
|
-
update_steps(background
|
40
|
+
update_steps(background.steps)
|
38
41
|
end
|
39
42
|
|
40
43
|
def update_scenario(scenario)
|
41
44
|
store_node_location(scenario)
|
42
|
-
store_nodes_location(scenario
|
43
|
-
update_steps(scenario
|
44
|
-
scenario
|
45
|
-
store_nodes_location(examples
|
46
|
-
store_nodes_location(examples
|
45
|
+
store_nodes_location(scenario.tags)
|
46
|
+
update_steps(scenario.steps)
|
47
|
+
scenario.examples.each do |examples|
|
48
|
+
store_nodes_location(examples.tags || [])
|
49
|
+
store_nodes_location(examples.table_body || [])
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
@@ -56,7 +59,7 @@ module Gherkin
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def store_node_location(node)
|
59
|
-
@ast_node_locations[node
|
62
|
+
@ast_node_locations[node.id] = node.location
|
60
63
|
end
|
61
64
|
end
|
62
65
|
end
|
@@ -23,25 +23,25 @@ module Gherkin
|
|
23
23
|
enumerated = true
|
24
24
|
|
25
25
|
sources.each do |source|
|
26
|
-
y.yield(
|
26
|
+
y.yield(Cucumber::Messages::Envelope.new(source: source)) if @options[:include_source]
|
27
27
|
begin
|
28
28
|
gherkin_document = nil
|
29
29
|
|
30
30
|
if @options[:include_gherkin_document]
|
31
31
|
gherkin_document = build_gherkin_document(source)
|
32
|
-
y.yield(
|
32
|
+
y.yield(Cucumber::Messages::Envelope.new(gherkin_document: gherkin_document))
|
33
33
|
end
|
34
34
|
if @options[:include_pickles]
|
35
35
|
gherkin_document ||= build_gherkin_document(source)
|
36
36
|
pickles = @compiler.compile(gherkin_document, source)
|
37
37
|
pickles.each do |pickle|
|
38
|
-
y.yield(
|
38
|
+
y.yield(Cucumber::Messages::Envelope.new(pickle: pickle))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
rescue CompositeParserException => err
|
42
|
-
yield_parse_errors(y, err.errors, source
|
42
|
+
yield_parse_errors(y, err.errors, source.uri)
|
43
43
|
rescue ParserException => err
|
44
|
-
yield_parse_errors(y, [err], source
|
44
|
+
yield_parse_errors(y, [err], source.uri)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -51,28 +51,28 @@ module Gherkin
|
|
51
51
|
|
52
52
|
def yield_parse_errors(y, errors, uri)
|
53
53
|
errors.each do |err|
|
54
|
-
parse_error =
|
55
|
-
source:
|
54
|
+
parse_error = Cucumber::Messages::ParseError.new(
|
55
|
+
source: Cucumber::Messages::SourceReference.new(
|
56
56
|
uri: uri,
|
57
|
-
location:
|
57
|
+
location: Cucumber::Messages::Location.new(
|
58
58
|
line: err.location[:line],
|
59
59
|
column: err.location[:column]
|
60
|
-
|
61
|
-
|
60
|
+
)
|
61
|
+
),
|
62
62
|
message: err.message
|
63
|
-
|
64
|
-
y.yield(
|
63
|
+
)
|
64
|
+
y.yield(Cucumber::Messages::Envelope.new(parse_error: parse_error))
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def sources
|
69
69
|
Enumerator.new do |y|
|
70
70
|
@paths.each do |path|
|
71
|
-
source =
|
71
|
+
source = Cucumber::Messages::Source.new(
|
72
72
|
uri: path,
|
73
73
|
data: File.open(path, 'r:UTF-8', &:read),
|
74
|
-
|
75
|
-
|
74
|
+
media_type: 'text/x.cucumber.gherkin+plain'
|
75
|
+
)
|
76
76
|
y.yield(source)
|
77
77
|
end
|
78
78
|
@sources.each do |source|
|
@@ -84,12 +84,15 @@ module Gherkin
|
|
84
84
|
def build_gherkin_document(source)
|
85
85
|
if @options[:default_dialect]
|
86
86
|
token_matcher = TokenMatcher.new(@options[:default_dialect])
|
87
|
-
gd = @parser.parse(source
|
87
|
+
gd = @parser.parse(source.data, token_matcher)
|
88
88
|
else
|
89
|
-
gd = @parser.parse(source
|
89
|
+
gd = @parser.parse(source.data)
|
90
90
|
end
|
91
|
-
|
92
|
-
|
91
|
+
Cucumber::Messages::GherkinDocument.new(
|
92
|
+
uri: source.uri,
|
93
|
+
feature: gd.feature,
|
94
|
+
comments: gd.comments
|
95
|
+
)
|
93
96
|
end
|
94
97
|
end
|
95
98
|
end
|
data/spec/gherkin/query_spec.rb
CHANGED
@@ -6,16 +6,19 @@ describe Gherkin::Query do
|
|
6
6
|
let(:subject) { Gherkin::Query.new }
|
7
7
|
|
8
8
|
def filter_messages_by_attribute(messages, attribute)
|
9
|
-
messages.
|
9
|
+
messages.map do |message|
|
10
|
+
return unless message.respond_to?(attribute)
|
11
|
+
message.send(attribute)
|
12
|
+
end.compact
|
10
13
|
end
|
11
14
|
|
12
15
|
def find_message_by_attribute(messages, attribute)
|
13
16
|
filter_messages_by_attribute(messages, attribute).first
|
14
17
|
end
|
15
18
|
|
16
|
-
let(:gherkin_document) { find_message_by_attribute(messages, :
|
19
|
+
let(:gherkin_document) { find_message_by_attribute(messages, :gherkin_document) }
|
17
20
|
|
18
|
-
let(:messages)
|
21
|
+
let(:messages) do
|
19
22
|
Gherkin.from_source(
|
20
23
|
"some/path",
|
21
24
|
feature_content,
|
@@ -23,9 +26,9 @@ describe Gherkin::Query do
|
|
23
26
|
include_gherkin_document: true
|
24
27
|
}
|
25
28
|
).to_a
|
26
|
-
|
29
|
+
end
|
27
30
|
|
28
|
-
let(:feature_content)
|
31
|
+
let(:feature_content) do
|
29
32
|
"""
|
30
33
|
@feature-tag
|
31
34
|
Feature: my feature
|
@@ -40,12 +43,12 @@ describe Gherkin::Query do
|
|
40
43
|
Scenario Outline: with examples
|
41
44
|
Given a <Status> step
|
42
45
|
|
43
|
-
@
|
46
|
+
@examples-tag
|
44
47
|
Examples:
|
45
48
|
| Status |
|
46
49
|
| passed |
|
47
50
|
|
48
|
-
|
51
|
+
@rule-tag
|
49
52
|
Rule: this is a rule
|
50
53
|
Background:
|
51
54
|
Given the passed step in the rule background
|
@@ -53,32 +56,29 @@ describe Gherkin::Query do
|
|
53
56
|
@ruled-scenario-tag
|
54
57
|
Scenario: a ruled scenario
|
55
58
|
Given a step in the ruled scenario
|
56
|
-
|
57
|
-
|
59
|
+
"""
|
60
|
+
end
|
58
61
|
|
59
|
-
|
62
|
+
describe '#update' do
|
60
63
|
context 'when the feature file is empty' do
|
61
64
|
let(:feature_content) { '' }
|
62
65
|
|
63
66
|
it 'does not fail' do
|
64
|
-
expect
|
65
|
-
messages.each { |message|
|
66
|
-
|
67
|
-
}
|
68
|
-
}.not_to raise_exception
|
67
|
+
expect do
|
68
|
+
messages.each { |message| subject.update(message) }
|
69
|
+
end.not_to raise_exception
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
|
-
|
74
|
+
describe '#location' do
|
74
75
|
before do
|
75
|
-
messages.each { |message|
|
76
|
-
subject.update(message)
|
77
|
-
}
|
76
|
+
messages.each { |message| subject.update(message) }
|
78
77
|
end
|
79
78
|
|
80
|
-
let(:background) { find_message_by_attribute(gherkin_document
|
81
|
-
let(:
|
79
|
+
let(:background) { find_message_by_attribute(gherkin_document.feature.children, :background) }
|
80
|
+
let(:rule) { find_message_by_attribute(gherkin_document.feature.children, :rule) }
|
81
|
+
let(:scenarios) { filter_messages_by_attribute(gherkin_document.feature.children, :scenario) }
|
82
82
|
let(:scenario) { scenarios.first }
|
83
83
|
|
84
84
|
it 'raises an exception when the AST node ID is unknown' do
|
@@ -86,67 +86,71 @@ describe Gherkin::Query do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'provides the location of a scenario' do
|
89
|
-
expect(subject.location(scenario
|
89
|
+
expect(subject.location(scenario.id)).to eq(scenario.location)
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'provides the location of an examples table row' do
|
93
|
-
node = scenarios.last
|
94
|
-
expect(subject.location(node
|
93
|
+
node = scenarios.last.examples.first.table_body.first
|
94
|
+
expect(subject.location(node.id)).to eq(node.location)
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'when querying steps' do
|
98
|
-
let(:background_step) { background
|
99
|
-
let(:scenario_step) { scenario
|
98
|
+
let(:background_step) { background.steps.first }
|
99
|
+
let(:scenario_step) { scenario.steps.first }
|
100
100
|
|
101
101
|
it 'provides the location of a background step' do
|
102
|
-
expect(subject.location(background_step
|
102
|
+
expect(subject.location(background_step.id)).to eq(background_step.location)
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'provides the location of a scenario step' do
|
106
|
-
expect(subject.location(scenario_step
|
106
|
+
expect(subject.location(scenario_step.id)).to eq(scenario_step.location)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
context 'when querying tags' do
|
111
|
-
let(:feature_tag) { gherkin_document
|
112
|
-
let(:
|
113
|
-
let(:
|
111
|
+
let(:feature_tag) { gherkin_document.feature.tags.first }
|
112
|
+
let(:rule_tag) { rule.tags.first }
|
113
|
+
let(:scenario_tag) { scenario.tags.first }
|
114
|
+
let(:examples_tag) { scenarios.last.examples.first.tags.first }
|
114
115
|
|
115
116
|
it 'provides the location of a feature tags' do
|
116
|
-
expect(subject.location(feature_tag
|
117
|
+
expect(subject.location(feature_tag.id)).to eq(feature_tag.location)
|
117
118
|
end
|
118
119
|
|
119
120
|
it 'provides the location of a scenario tags' do
|
120
|
-
expect(subject.location(scenario_tag
|
121
|
+
expect(subject.location(scenario_tag.id)).to eq(scenario_tag.location)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'provides the location of scenario examples tags' do
|
125
|
+
expect(subject.location(examples_tag.id)).to eq(examples_tag.location)
|
121
126
|
end
|
122
127
|
|
123
|
-
it 'provides the location of a
|
124
|
-
expect(subject.location(
|
128
|
+
it 'provides the location of a rule tag' do
|
129
|
+
expect(subject.location(rule_tag.id)).to eq(rule_tag.location)
|
125
130
|
end
|
126
131
|
end
|
127
132
|
|
128
133
|
context 'when children are scoped in a Rule' do
|
129
|
-
let(:
|
130
|
-
let(:
|
131
|
-
let(:
|
132
|
-
let(:
|
133
|
-
let(:
|
134
|
-
let(:rule_scenario_tag) { rule_scenario[:tags].first }
|
134
|
+
let(:rule_background) { find_message_by_attribute(rule.children, :background) }
|
135
|
+
let(:rule_background_step) { rule_background.steps.first }
|
136
|
+
let(:rule_scenario) { find_message_by_attribute(rule.children, :scenario) }
|
137
|
+
let(:rule_scenario_step) { rule_scenario.steps.first }
|
138
|
+
let(:rule_scenario_tag) { rule_scenario.tags.first }
|
135
139
|
|
136
140
|
it 'provides the location of a background step' do
|
137
|
-
expect(subject.location(rule_background_step
|
141
|
+
expect(subject.location(rule_background_step.id)).to eq(rule_background_step.location)
|
138
142
|
end
|
139
143
|
|
140
144
|
it 'provides the location of a scenario' do
|
141
|
-
expect(subject.location(rule_scenario
|
145
|
+
expect(subject.location(rule_scenario.id)).to eq(rule_scenario.location)
|
142
146
|
end
|
143
147
|
|
144
148
|
it 'provides the location of a scenario tag' do
|
145
|
-
expect(subject.location(rule_scenario_tag
|
149
|
+
expect(subject.location(rule_scenario_tag.id)).to eq(rule_scenario_tag.location)
|
146
150
|
end
|
147
151
|
|
148
152
|
it 'provides the location of a scenario step' do
|
149
|
-
expect(subject.location(rule_scenario_step
|
153
|
+
expect(subject.location(rule_scenario_step.id)).to eq(rule_scenario_step.location)
|
150
154
|
end
|
151
155
|
end
|
152
156
|
end
|
@@ -11,11 +11,11 @@ module Gherkin
|
|
11
11
|
}
|
12
12
|
|
13
13
|
let(:source_feature) {
|
14
|
-
|
14
|
+
Cucumber::Messages::Source.new(
|
15
15
|
uri: '//whatever/uri',
|
16
16
|
data: feature_content,
|
17
|
-
|
18
|
-
|
17
|
+
media_type: 'text/x.cucumber.gherkin+plain'
|
18
|
+
)
|
19
19
|
}
|
20
20
|
|
21
21
|
let(:options) {
|
@@ -25,10 +25,10 @@ module Gherkin
|
|
25
25
|
}
|
26
26
|
|
27
27
|
let(:gherkin_document) {
|
28
|
-
ParserMessageStream.new([], [source_feature], options).messages.first
|
28
|
+
ParserMessageStream.new([], [source_feature], options).messages.first.gherkin_document
|
29
29
|
}
|
30
30
|
|
31
|
-
let(:scenario_id) { gherkin_document
|
31
|
+
let(:scenario_id) { gherkin_document.feature.children.first.scenario.id }
|
32
32
|
|
33
33
|
context '#messages' do
|
34
34
|
it "raises an exception on second iteration" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-gherkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 20.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gáspár Nagy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cucumber-messages
|
@@ -18,20 +18,20 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '17.0'
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 17.0.0
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - "~>"
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
31
|
+
version: '17.0'
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 17.0.0
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rake
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
version: '13.0'
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 13.0.
|
44
|
+
version: 13.0.5
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
version: '13.0'
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 13.0.
|
54
|
+
version: 13.0.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,12 +134,12 @@ requirements: []
|
|
134
134
|
rubygems_version: 3.1.2
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
|
-
summary: cucumber-gherkin-
|
137
|
+
summary: cucumber-gherkin-20.0.0
|
138
138
|
test_files:
|
139
139
|
- spec/capture_warnings.rb
|
140
|
-
- spec/gherkin/dialect_spec.rb
|
141
140
|
- spec/gherkin/gherkin_line_spec.rb
|
142
|
-
- spec/gherkin/
|
141
|
+
- spec/gherkin/dialect_spec.rb
|
143
142
|
- spec/gherkin/parser_spec.rb
|
144
|
-
- spec/gherkin/query_spec.rb
|
145
143
|
- spec/gherkin/stream/parser_message_stream_spec.rb
|
144
|
+
- spec/gherkin/query_spec.rb
|
145
|
+
- spec/gherkin/gherkin_spec.rb
|