cuke_modeler 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -1
  3. data/README.md +11 -14
  4. data/cuke_modeler.gemspec +12 -9
  5. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +12 -0
  6. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +12 -0
  7. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +12 -0
  8. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +12 -0
  9. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +313 -5
  10. data/lib/cuke_modeler/models/background.rb +1 -1
  11. data/lib/cuke_modeler/models/cell.rb +1 -1
  12. data/lib/cuke_modeler/models/comment.rb +1 -1
  13. data/lib/cuke_modeler/models/directory.rb +2 -2
  14. data/lib/cuke_modeler/models/doc_string.rb +1 -1
  15. data/lib/cuke_modeler/models/example.rb +1 -1
  16. data/lib/cuke_modeler/models/feature.rb +1 -1
  17. data/lib/cuke_modeler/models/feature_file.rb +2 -2
  18. data/lib/cuke_modeler/models/outline.rb +1 -1
  19. data/lib/cuke_modeler/models/row.rb +1 -1
  20. data/lib/cuke_modeler/models/scenario.rb +1 -1
  21. data/lib/cuke_modeler/models/step.rb +1 -1
  22. data/lib/cuke_modeler/models/table.rb +1 -1
  23. data/lib/cuke_modeler/models/tag.rb +1 -1
  24. data/lib/cuke_modeler/parsing.rb +29 -58
  25. data/lib/cuke_modeler/version.rb +1 -1
  26. metadata +33 -151
  27. data/.gitignore +0 -18
  28. data/.simplecov +0 -7
  29. data/.travis.yml +0 -81
  30. data/Gemfile +0 -44
  31. data/Rakefile +0 -73
  32. data/appveyor.yml +0 -88
  33. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +0 -274
  34. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +0 -297
  35. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +0 -309
  36. data/lib/cuke_modeler/adapters/gherkin_5_adapter.rb +0 -12
  37. data/lib/cuke_modeler/adapters/gherkin_6_adapter.rb +0 -310
  38. data/lib/cuke_modeler/adapters/gherkin_7_adapter.rb +0 -307
  39. data/lib/cuke_modeler/adapters/gherkin_8_adapter.rb +0 -12
  40. data/testing/cucumber/step_definitions/action_steps.rb +0 -13
  41. data/testing/cucumber/step_definitions/background_steps.rb +0 -1
  42. data/testing/cucumber/step_definitions/directory_steps.rb +0 -6
  43. data/testing/cucumber/step_definitions/doc_string_steps.rb +0 -1
  44. data/testing/cucumber/step_definitions/feature_file_steps.rb +0 -16
  45. data/testing/cucumber/step_definitions/feature_steps.rb +0 -7
  46. data/testing/cucumber/step_definitions/modeling_steps.rb +0 -49
  47. data/testing/cucumber/step_definitions/setup_steps.rb +0 -32
  48. data/testing/cucumber/step_definitions/step_steps.rb +0 -3
  49. data/testing/cucumber/step_definitions/table_steps.rb +0 -1
  50. data/testing/cucumber/step_definitions/tag_steps.rb +0 -3
  51. data/testing/cucumber/step_definitions/verification_steps.rb +0 -181
  52. data/testing/cucumber/support/env.rb +0 -30
  53. data/testing/dialect_helper.rb +0 -48
  54. data/testing/file_helper.rb +0 -47
  55. data/testing/gemfiles/gherkin2.gemfile +0 -33
  56. data/testing/gemfiles/gherkin3.gemfile +0 -26
  57. data/testing/gemfiles/gherkin4.gemfile +0 -27
  58. data/testing/gemfiles/gherkin5.gemfile +0 -27
  59. data/testing/gemfiles/gherkin6.gemfile +0 -10
  60. data/testing/gemfiles/gherkin7.gemfile +0 -9
  61. data/testing/gemfiles/gherkin8.gemfile +0 -9
  62. data/testing/gemfiles/gherkin9.gemfile +0 -9
  63. data/testing/helper_methods.rb +0 -23
  64. data/testing/rspec/spec/integration/adapters/gherkin_2_adapter_spec.rb +0 -166
  65. data/testing/rspec/spec/integration/adapters/gherkin_3_adapter_spec.rb +0 -166
  66. data/testing/rspec/spec/integration/adapters/gherkin_4_adapter_spec.rb +0 -165
  67. data/testing/rspec/spec/integration/adapters/gherkin_5_adapter_spec.rb +0 -165
  68. data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +0 -159
  69. data/testing/rspec/spec/integration/adapters/gherkin_7_adapter_spec.rb +0 -162
  70. data/testing/rspec/spec/integration/adapters/gherkin_8_adapter_spec.rb +0 -162
  71. data/testing/rspec/spec/integration/adapters/gherkin_9_adapter_spec.rb +0 -162
  72. data/testing/rspec/spec/integration/models/background_integration_spec.rb +0 -438
  73. data/testing/rspec/spec/integration/models/cell_integration_spec.rb +0 -338
  74. data/testing/rspec/spec/integration/models/comment_integration_spec.rb +0 -180
  75. data/testing/rspec/spec/integration/models/directory_integration_spec.rb +0 -218
  76. data/testing/rspec/spec/integration/models/doc_string_integration_spec.rb +0 -398
  77. data/testing/rspec/spec/integration/models/example_integration_spec.rb +0 -753
  78. data/testing/rspec/spec/integration/models/feature_file_integration_spec.rb +0 -276
  79. data/testing/rspec/spec/integration/models/feature_integration_spec.rb +0 -655
  80. data/testing/rspec/spec/integration/models/model_integration_spec.rb +0 -15
  81. data/testing/rspec/spec/integration/models/outline_integration_spec.rb +0 -619
  82. data/testing/rspec/spec/integration/models/row_integration_spec.rb +0 -303
  83. data/testing/rspec/spec/integration/models/scenario_integration_spec.rb +0 -475
  84. data/testing/rspec/spec/integration/models/step_integration_spec.rb +0 -573
  85. data/testing/rspec/spec/integration/models/table_integration_spec.rb +0 -333
  86. data/testing/rspec/spec/integration/models/tag_integration_spec.rb +0 -271
  87. data/testing/rspec/spec/integration/nested_integration_spec.rb +0 -91
  88. data/testing/rspec/spec/integration/parsing_integration_spec.rb +0 -143
  89. data/testing/rspec/spec/integration/shared/models_integration_specs.rb +0 -18
  90. data/testing/rspec/spec/spec_helper.rb +0 -129
  91. data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +0 -25
  92. data/testing/rspec/spec/unit/described_unit_spec.rb +0 -23
  93. data/testing/rspec/spec/unit/models/background_unit_spec.rb +0 -83
  94. data/testing/rspec/spec/unit/models/cell_unit_spec.rb +0 -68
  95. data/testing/rspec/spec/unit/models/comment_unit_spec.rb +0 -68
  96. data/testing/rspec/spec/unit/models/directory_unit_spec.rb +0 -127
  97. data/testing/rspec/spec/unit/models/doc_string_unit_spec.rb +0 -100
  98. data/testing/rspec/spec/unit/models/example_unit_spec.rb +0 -133
  99. data/testing/rspec/spec/unit/models/feature_file_unit_spec.rb +0 -125
  100. data/testing/rspec/spec/unit/models/feature_unit_spec.rb +0 -157
  101. data/testing/rspec/spec/unit/models/model_unit_spec.rb +0 -15
  102. data/testing/rspec/spec/unit/models/outline_unit_spec.rb +0 -117
  103. data/testing/rspec/spec/unit/models/row_unit_spec.rb +0 -68
  104. data/testing/rspec/spec/unit/models/scenario_unit_spec.rb +0 -86
  105. data/testing/rspec/spec/unit/models/step_unit_spec.rb +0 -109
  106. data/testing/rspec/spec/unit/models/table_unit_spec.rb +0 -77
  107. data/testing/rspec/spec/unit/models/tag_unit_spec.rb +0 -68
  108. data/testing/rspec/spec/unit/named_unit_spec.rb +0 -23
  109. data/testing/rspec/spec/unit/nested_unit_spec.rb +0 -43
  110. data/testing/rspec/spec/unit/parsed_unit_spec.rb +0 -27
  111. data/testing/rspec/spec/unit/parsing_unit_spec.rb +0 -54
  112. data/testing/rspec/spec/unit/shared/bare_bones_models_unit_specs.rb +0 -14
  113. data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +0 -127
  114. data/testing/rspec/spec/unit/shared/described_models_unit_specs.rb +0 -38
  115. data/testing/rspec/spec/unit/shared/keyworded_models_unit_specs.rb +0 -58
  116. data/testing/rspec/spec/unit/shared/models_unit_specs.rb +0 -15
  117. data/testing/rspec/spec/unit/shared/named_models_unit_specs.rb +0 -39
  118. data/testing/rspec/spec/unit/shared/nested_models_unit_specs.rb +0 -51
  119. data/testing/rspec/spec/unit/shared/parsed_models_unit_specs.rb +0 -39
  120. data/testing/rspec/spec/unit/shared/prepopulated_models_unit_specs.rb +0 -18
  121. data/testing/rspec/spec/unit/shared/sourced_models_unit_specs.rb +0 -39
  122. data/testing/rspec/spec/unit/shared/stepped_models_unit_specs.rb +0 -46
  123. data/testing/rspec/spec/unit/shared/stringifiable_models_unit_specs.rb +0 -18
  124. data/testing/rspec/spec/unit/shared/tagged_models_unit_specs.rb +0 -72
  125. data/testing/rspec/spec/unit/sourceable_unit_spec.rb +0 -27
  126. data/testing/rspec/spec/unit/stepped_unit_spec.rb +0 -23
  127. data/testing/rspec/spec/unit/taggable_unit_spec.rb +0 -69
  128. data/testing/test_languages.json +0 -45
  129. data/todo.txt +0 -25
@@ -1,12 +0,0 @@
1
- require_relative 'gherkin_4_adapter'
2
-
3
- module CukeModeler
4
-
5
- # NOT A PART OF THE PUBLIC API
6
- # An adapter that can convert the output of version 5.x of the *gherkin* gem into input that is consumable by this gem.
7
-
8
- class Gherkin5Adapter < Gherkin4Adapter
9
-
10
- end
11
-
12
- end
@@ -1,310 +0,0 @@
1
- module CukeModeler
2
-
3
- # NOT A PART OF THE PUBLIC API
4
- # An adapter that can convert the output of version 6.x of the *gherkin* gem into input that is consumable by this gem.
5
-
6
- class Gherkin6Adapter
7
-
8
- # Adapts the given AST into the shape that this gem expects
9
- def adapt(parsed_ast)
10
- # Saving off the original data
11
- parsed_ast['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_ast))
12
-
13
- # Removing parsed data for child elements in order to avoid duplicating data
14
- parsed_ast['cuke_modeler_parsing_data'][:feature] = nil
15
- parsed_ast['cuke_modeler_parsing_data'][:comments] = nil
16
-
17
- # Comments are stored on the feature file in gherkin 4.x
18
- parsed_ast['comments'] = []
19
- parsed_ast[:comments].each do |comment|
20
- adapt_comment!(comment)
21
- end
22
- parsed_ast['comments'].concat(parsed_ast.delete(:comments))
23
-
24
- adapt_feature!(parsed_ast[:feature]) if parsed_ast[:feature]
25
- parsed_ast['feature'] = parsed_ast.delete(:feature)
26
-
27
- [parsed_ast]
28
- end
29
-
30
- # Adapts the AST sub-tree that is rooted at the given feature node.
31
- def adapt_feature!(parsed_feature)
32
- # Saving off the original data
33
- parsed_feature['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_feature))
34
-
35
- # Removing parsed data for child elements in order to avoid duplicating data
36
- parsed_feature['cuke_modeler_parsing_data'][:tags] = nil
37
- parsed_feature['cuke_modeler_parsing_data'][:children] = nil
38
-
39
- parsed_feature['keyword'] = parsed_feature.delete(:keyword)
40
- parsed_feature['name'] = parsed_feature.delete(:name)
41
- parsed_feature['description'] = parsed_feature.delete(:description)
42
- parsed_feature['line'] = parsed_feature.delete(:location)[:line]
43
-
44
- parsed_feature['elements'] = []
45
- adapt_child_elements!(parsed_feature[:children])
46
- parsed_feature['elements'].concat(parsed_feature.delete(:children))
47
-
48
- parsed_feature['tags'] = []
49
- parsed_feature[:tags].each do |tag|
50
- adapt_tag!(tag)
51
- end
52
- parsed_feature['tags'].concat(parsed_feature.delete(:tags))
53
- end
54
-
55
- # Adapts the AST sub-tree that is rooted at the given background node.
56
- def adapt_background!(parsed_background)
57
- # Saving off the original data
58
- parsed_background['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_background))
59
-
60
- # Removing parsed data for child elements in order to avoid duplicating data
61
- parsed_background['cuke_modeler_parsing_data'][:background][:steps] = nil
62
-
63
- parsed_background['type'] = 'Background'
64
- parsed_background['keyword'] = parsed_background[:background].delete(:keyword)
65
- parsed_background['name'] = parsed_background[:background].delete(:name)
66
- parsed_background['description'] = parsed_background[:background].delete(:description)
67
- parsed_background['line'] = parsed_background[:background].delete(:location)[:line]
68
-
69
- parsed_background['steps'] = []
70
- parsed_background[:background][:steps].each do |step|
71
- adapt_step!(step)
72
- end
73
- parsed_background['steps'].concat(parsed_background[:background].delete(:steps))
74
- end
75
-
76
- # Adapts the AST sub-tree that is rooted at the given scenario node.
77
- def adapt_scenario!(parsed_test)
78
- # Removing parsed data for child elements in order to avoid duplicating data
79
- parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] = nil
80
- parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] = nil
81
-
82
- parsed_test['type'] = 'Scenario'
83
- parsed_test['keyword'] = parsed_test[:scenario].delete(:keyword)
84
- parsed_test['name'] = parsed_test[:scenario].delete(:name)
85
- parsed_test['description'] = parsed_test[:scenario].delete(:description)
86
- parsed_test['line'] = parsed_test[:scenario].delete(:location)[:line]
87
-
88
- parsed_test['tags'] = []
89
- parsed_test[:scenario][:tags].each do |tag|
90
- adapt_tag!(tag)
91
- end
92
- parsed_test['tags'].concat(parsed_test[:scenario].delete(:tags))
93
-
94
- parsed_test['steps'] = []
95
- parsed_test[:scenario][:steps].each do |step|
96
- adapt_step!(step)
97
- end
98
- parsed_test['steps'].concat(parsed_test[:scenario].delete(:steps))
99
- end
100
-
101
- # Adapts the AST sub-tree that is rooted at the given outline node.
102
- def adapt_outline!(parsed_test)
103
- # Removing parsed data for child elements in order to avoid duplicating data
104
- parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] = nil
105
- parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] = nil
106
- parsed_test['cuke_modeler_parsing_data'][:scenario][:examples] = nil
107
-
108
- parsed_test['type'] = 'ScenarioOutline'
109
- parsed_test['keyword'] = parsed_test[:scenario].delete(:keyword)
110
- parsed_test['name'] = parsed_test[:scenario].delete(:name)
111
- parsed_test['description'] = parsed_test[:scenario].delete(:description)
112
- parsed_test['line'] = parsed_test[:scenario].delete(:location)[:line]
113
-
114
- parsed_test['tags'] = []
115
- parsed_test[:scenario][:tags].each do |tag|
116
- adapt_tag!(tag)
117
- end
118
- parsed_test['tags'].concat(parsed_test[:scenario].delete(:tags))
119
-
120
- parsed_test['steps'] = []
121
- parsed_test[:scenario][:steps].each do |step|
122
- adapt_step!(step)
123
- end
124
- parsed_test['steps'].concat(parsed_test[:scenario].delete(:steps))
125
-
126
- parsed_test['examples'] = []
127
- parsed_test[:scenario][:examples].each do |step|
128
- adapt_example!(step)
129
- end
130
- parsed_test['examples'].concat(parsed_test[:scenario].delete(:examples))
131
- end
132
-
133
- # Adapts the AST sub-tree that is rooted at the given example node.
134
- def adapt_example!(parsed_example)
135
- # Saving off the original data
136
- parsed_example['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_example))
137
-
138
- # Removing parsed data for child elements in order to avoid duplicating data
139
- parsed_example['cuke_modeler_parsing_data'][:tags] = nil
140
- parsed_example['cuke_modeler_parsing_data'][:table_header] = nil
141
- parsed_example['cuke_modeler_parsing_data'][:table_body] = nil
142
-
143
- parsed_example['keyword'] = parsed_example.delete(:keyword)
144
- parsed_example['name'] = parsed_example.delete(:name)
145
- parsed_example['line'] = parsed_example.delete(:location)[:line]
146
- parsed_example['description'] = parsed_example.delete(:description)
147
-
148
- parsed_example['rows'] = []
149
-
150
- if parsed_example[:table_header]
151
- adapt_table_row!(parsed_example[:table_header])
152
- parsed_example['rows'] << parsed_example.delete(:table_header)
153
- end
154
-
155
- if parsed_example[:table_body]
156
-
157
- parsed_example[:table_body].each do |row|
158
- adapt_table_row!(row)
159
- end
160
- parsed_example['rows'].concat(parsed_example.delete(:table_body))
161
- end
162
-
163
-
164
- parsed_example['tags'] = []
165
- parsed_example[:tags].each do |tag|
166
- adapt_tag!(tag)
167
- end
168
- parsed_example['tags'].concat(parsed_example.delete(:tags))
169
- end
170
-
171
- # Adapts the AST sub-tree that is rooted at the given tag node.
172
- def adapt_tag!(parsed_tag)
173
- # Saving off the original data
174
- parsed_tag['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_tag))
175
-
176
- parsed_tag['name'] = parsed_tag.delete(:name)
177
- parsed_tag['line'] = parsed_tag.delete(:location)[:line]
178
- end
179
-
180
- # Adapts the AST sub-tree that is rooted at the given comment node.
181
- def adapt_comment!(parsed_comment)
182
- # Saving off the original data
183
- parsed_comment['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_comment))
184
-
185
- parsed_comment['text'] = parsed_comment.delete(:text)
186
- parsed_comment['line'] = parsed_comment.delete(:location)[:line]
187
- end
188
-
189
- # Adapts the AST sub-tree that is rooted at the given step node.
190
- def adapt_step!(parsed_step)
191
- # Saving off the original data
192
- parsed_step['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step))
193
-
194
- # Removing parsed data for child elements in order to avoid duplicating data
195
- parsed_step['cuke_modeler_parsing_data'][:data_table] = nil
196
- parsed_step['cuke_modeler_parsing_data'][:doc_string] = nil
197
-
198
- parsed_step['keyword'] = parsed_step.delete(:keyword)
199
- parsed_step['name'] = parsed_step.delete(:text)
200
- parsed_step['line'] = parsed_step.delete(:location)[:line]
201
-
202
-
203
- case
204
- when parsed_step[:doc_string]
205
- adapt_doc_string!(parsed_step[:doc_string])
206
- parsed_step['doc_string'] = parsed_step.delete(:doc_string)
207
- when parsed_step[:data_table]
208
- adapt_step_table!(parsed_step[:data_table])
209
- parsed_step['table'] = parsed_step.delete(:data_table)
210
- else
211
- # Step has no extra argument
212
- end
213
- end
214
-
215
- # Adapts the AST sub-tree that is rooted at the given doc string node.
216
- def adapt_doc_string!(parsed_doc_string)
217
- # Saving off the original data
218
- parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string))
219
-
220
- parsed_doc_string['value'] = parsed_doc_string.delete(:content)
221
- parsed_doc_string['content_type'] = parsed_doc_string.delete(:content_type).strip # TODO: fix bug in Gherkin so that this whitespace is already trimmed off
222
- parsed_doc_string['line'] = parsed_doc_string.delete(:location)[:line]
223
- end
224
-
225
- # Adapts the AST sub-tree that is rooted at the given table node.
226
- def adapt_step_table!(parsed_step_table)
227
- # Saving off the original data
228
- parsed_step_table['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step_table))
229
-
230
- # Removing parsed data for child elements in order to avoid duplicating data
231
- parsed_step_table['cuke_modeler_parsing_data'][:rows] = nil
232
-
233
- parsed_step_table['rows'] = []
234
- parsed_step_table[:rows].each do |row|
235
- adapt_table_row!(row)
236
- end
237
- parsed_step_table['rows'].concat(parsed_step_table.delete(:rows))
238
- parsed_step_table['line'] = parsed_step_table.delete(:location)[:line]
239
- end
240
-
241
- # Adapts the AST sub-tree that is rooted at the given row node.
242
- def adapt_table_row!(parsed_table_row)
243
- # Saving off the original data
244
- parsed_table_row['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_table_row))
245
-
246
- # Removing parsed data for child elements in order to avoid duplicating data which the child elements will themselves include
247
- parsed_table_row['cuke_modeler_parsing_data'][:cells] = nil
248
-
249
-
250
- parsed_table_row['line'] = parsed_table_row.delete(:location)[:line]
251
-
252
- parsed_table_row['cells'] = []
253
- parsed_table_row[:cells].each do |row|
254
- adapt_table_cell!(row)
255
- end
256
- parsed_table_row['cells'].concat(parsed_table_row.delete(:cells))
257
- end
258
-
259
- # Adapts the AST sub-tree that is rooted at the given cell node.
260
- def adapt_table_cell!(parsed_cell)
261
- # Saving off the original data
262
- parsed_cell['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_cell))
263
-
264
- parsed_cell['value'] = parsed_cell.delete(:value)
265
- parsed_cell['line'] = parsed_cell.delete(:location)[:line]
266
- end
267
-
268
-
269
- private
270
-
271
-
272
- def adapt_child_elements!(parsed_children)
273
- return if parsed_children.empty?
274
-
275
- background_child = parsed_children.find { |child| child[:background] }
276
-
277
- if background_child
278
- adapt_background!(background_child)
279
-
280
- remaining_children = parsed_children.reject { |child| child[:background] }
281
- end
282
-
283
- adapt_tests!(remaining_children || parsed_children)
284
- end
285
-
286
- def adapt_tests!(parsed_tests)
287
- return unless parsed_tests
288
-
289
- parsed_tests.each do |test|
290
- adapt_test!(test)
291
- end
292
- end
293
-
294
- def adapt_test!(parsed_test)
295
- # Saving off the original data
296
- parsed_test['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_test))
297
-
298
-
299
- case
300
- when parsed_test[:scenario] && parsed_test[:scenario][:examples].any?
301
- adapt_outline!(parsed_test)
302
- when parsed_test[:scenario]
303
- adapt_scenario!(parsed_test)
304
- else
305
- raise(ArgumentError, "Unknown test type with keys: #{parsed_test.keys}")
306
- end
307
- end
308
-
309
- end
310
- end
@@ -1,307 +0,0 @@
1
- module CukeModeler
2
-
3
- # NOT A PART OF THE PUBLIC API
4
- # An adapter that can convert the output of version 7.x of the *gherkin* gem into input that is consumable by this gem.
5
-
6
- class Gherkin7Adapter
7
-
8
- # Adapts the given AST into the shape that this gem expects
9
- def adapt(parsed_ast)
10
- # Saving off the original data
11
- parsed_ast['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_ast))
12
-
13
- # Removing parsed data for child elements in order to avoid duplicating data
14
- parsed_ast['cuke_modeler_parsing_data'][:feature] = nil
15
- parsed_ast['cuke_modeler_parsing_data'][:comments] = nil
16
-
17
- parsed_ast['comments'] = []
18
- parsed_ast[:comments].each do |comment|
19
- adapt_comment!(comment)
20
- end
21
- parsed_ast['comments'].concat(parsed_ast.delete(:comments))
22
-
23
- adapt_feature!(parsed_ast[:feature]) if parsed_ast[:feature]
24
- parsed_ast['feature'] = parsed_ast.delete(:feature)
25
-
26
- [parsed_ast]
27
- end
28
-
29
- # Adapts the AST sub-tree that is rooted at the given feature node.
30
- def adapt_feature!(parsed_feature)
31
- # Saving off the original data
32
- parsed_feature['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_feature))
33
-
34
- # Removing parsed data for child elements in order to avoid duplicating data
35
- parsed_feature['cuke_modeler_parsing_data'][:tags] = nil
36
- parsed_feature['cuke_modeler_parsing_data'][:children] = nil
37
-
38
- parsed_feature['keyword'] = parsed_feature.delete(:keyword)
39
- parsed_feature['name'] = parsed_feature.delete(:name)
40
- parsed_feature['description'] = parsed_feature.delete(:description)
41
- parsed_feature['line'] = parsed_feature.delete(:location)[:line]
42
-
43
- parsed_feature['elements'] = []
44
- adapt_child_elements!(parsed_feature[:children])
45
- parsed_feature['elements'].concat(parsed_feature.delete(:children))
46
-
47
- parsed_feature['tags'] = []
48
- parsed_feature[:tags].each do |tag|
49
- adapt_tag!(tag)
50
- end
51
- parsed_feature['tags'].concat(parsed_feature.delete(:tags))
52
- end
53
-
54
- # Adapts the AST sub-tree that is rooted at the given background node.
55
- def adapt_background!(parsed_background)
56
- # Saving off the original data
57
- parsed_background['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_background))
58
-
59
- # Removing parsed data for child elements in order to avoid duplicating data
60
- parsed_background['cuke_modeler_parsing_data'][:background][:steps] = nil
61
-
62
- parsed_background['type'] = 'Background'
63
- parsed_background['keyword'] = parsed_background[:background].delete(:keyword)
64
- parsed_background['name'] = parsed_background[:background].delete(:name)
65
- parsed_background['description'] = parsed_background[:background].delete(:description)
66
- parsed_background['line'] = parsed_background[:background].delete(:location)[:line]
67
-
68
- parsed_background['steps'] = []
69
- parsed_background[:background][:steps].each do |step|
70
- adapt_step!(step)
71
- end
72
- parsed_background['steps'].concat(parsed_background[:background].delete(:steps))
73
- end
74
-
75
- # Adapts the AST sub-tree that is rooted at the given scenario node.
76
- def adapt_scenario!(parsed_test)
77
- # Removing parsed data for child elements in order to avoid duplicating data
78
- parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] = nil
79
- parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] = nil
80
-
81
- parsed_test['type'] = 'Scenario'
82
- parsed_test['keyword'] = parsed_test[:scenario].delete(:keyword)
83
- parsed_test['name'] = parsed_test[:scenario].delete(:name)
84
- parsed_test['description'] = parsed_test[:scenario].delete(:description)
85
- parsed_test['line'] = parsed_test[:scenario].delete(:location)[:line]
86
-
87
- parsed_test['tags'] = []
88
- parsed_test[:scenario][:tags].each do |tag|
89
- adapt_tag!(tag)
90
- end
91
- parsed_test['tags'].concat(parsed_test[:scenario].delete(:tags))
92
-
93
- parsed_test['steps'] = []
94
- parsed_test[:scenario][:steps].each do |step|
95
- adapt_step!(step)
96
- end
97
- parsed_test['steps'].concat(parsed_test[:scenario].delete(:steps))
98
- end
99
-
100
- # Adapts the AST sub-tree that is rooted at the given outline node.
101
- def adapt_outline!(parsed_test)
102
- # Removing parsed data for child elements in order to avoid duplicating data
103
- parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] = nil
104
- parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] = nil
105
- parsed_test['cuke_modeler_parsing_data'][:scenario][:examples] = nil
106
-
107
- parsed_test['type'] = 'ScenarioOutline'
108
- parsed_test['keyword'] = parsed_test[:scenario].delete(:keyword)
109
- parsed_test['name'] = parsed_test[:scenario].delete(:name)
110
- parsed_test['description'] = parsed_test[:scenario].delete(:description)
111
- parsed_test['line'] = parsed_test[:scenario].delete(:location)[:line]
112
-
113
- parsed_test['tags'] = []
114
- parsed_test[:scenario][:tags].each do |tag|
115
- adapt_tag!(tag)
116
- end
117
- parsed_test['tags'].concat(parsed_test[:scenario].delete(:tags))
118
-
119
- parsed_test['steps'] = []
120
- parsed_test[:scenario][:steps].each do |step|
121
- adapt_step!(step)
122
- end
123
- parsed_test['steps'].concat(parsed_test[:scenario].delete(:steps))
124
-
125
- parsed_test['examples'] = []
126
- parsed_test[:scenario][:examples].each do |step|
127
- adapt_example!(step)
128
- end
129
- parsed_test['examples'].concat(parsed_test[:scenario].delete(:examples))
130
- end
131
-
132
- # Adapts the AST sub-tree that is rooted at the given example node.
133
- def adapt_example!(parsed_example)
134
- # Saving off the original data
135
- parsed_example['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_example))
136
-
137
- # Removing parsed data for child elements in order to avoid duplicating data
138
- parsed_example['cuke_modeler_parsing_data'][:tags] = nil
139
- parsed_example['cuke_modeler_parsing_data'][:table_header] = nil
140
- parsed_example['cuke_modeler_parsing_data'][:table_body] = nil
141
-
142
- parsed_example['keyword'] = parsed_example.delete(:keyword)
143
- parsed_example['name'] = parsed_example.delete(:name)
144
- parsed_example['line'] = parsed_example.delete(:location)[:line]
145
- parsed_example['description'] = parsed_example.delete(:description)
146
-
147
- parsed_example['rows'] = []
148
-
149
- if parsed_example[:table_header]
150
- adapt_table_row!(parsed_example[:table_header])
151
- parsed_example['rows'] << parsed_example.delete(:table_header)
152
- end
153
-
154
- if parsed_example[:table_body]
155
- parsed_example[:table_body].each do |row|
156
- adapt_table_row!(row)
157
- end
158
- parsed_example['rows'].concat(parsed_example.delete(:table_body))
159
- end
160
-
161
- parsed_example['tags'] = []
162
- parsed_example[:tags].each do |tag|
163
- adapt_tag!(tag)
164
- end
165
- parsed_example['tags'].concat(parsed_example.delete(:tags))
166
- end
167
-
168
- # Adapts the AST sub-tree that is rooted at the given tag node.
169
- def adapt_tag!(parsed_tag)
170
- # Saving off the original data
171
- parsed_tag['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_tag))
172
-
173
- parsed_tag['name'] = parsed_tag.delete(:name)
174
- parsed_tag['line'] = parsed_tag.delete(:location)[:line]
175
- end
176
-
177
- # Adapts the AST sub-tree that is rooted at the given comment node.
178
- def adapt_comment!(parsed_comment)
179
- # Saving off the original data
180
- parsed_comment['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_comment))
181
-
182
- parsed_comment['text'] = parsed_comment.delete(:text)
183
- parsed_comment['line'] = parsed_comment.delete(:location)[:line]
184
- end
185
-
186
- # Adapts the AST sub-tree that is rooted at the given step node.
187
- def adapt_step!(parsed_step)
188
- # Saving off the original data
189
- parsed_step['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step))
190
-
191
- # Removing parsed data for child elements in order to avoid duplicating data
192
- parsed_step['cuke_modeler_parsing_data'][:data_table] = nil
193
- parsed_step['cuke_modeler_parsing_data'][:doc_string] = nil
194
-
195
- parsed_step['keyword'] = parsed_step.delete(:keyword)
196
- parsed_step['name'] = parsed_step.delete(:text)
197
- parsed_step['line'] = parsed_step.delete(:location)[:line]
198
-
199
-
200
- case
201
- when parsed_step[:doc_string]
202
- adapt_doc_string!(parsed_step[:doc_string])
203
- parsed_step['doc_string'] = parsed_step.delete(:doc_string)
204
- when parsed_step[:data_table]
205
- adapt_step_table!(parsed_step[:data_table])
206
- parsed_step['table'] = parsed_step.delete(:data_table)
207
- else
208
- # Step has no extra argument
209
- end
210
- end
211
-
212
- # Adapts the AST sub-tree that is rooted at the given doc string node.
213
- def adapt_doc_string!(parsed_doc_string)
214
- # Saving off the original data
215
- parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string))
216
-
217
- parsed_doc_string['value'] = parsed_doc_string.delete(:content)
218
- parsed_doc_string['content_type'] = parsed_doc_string.delete(:content_type).strip # TODO: fix bug in Gherkin so that this whitespace is already trimmed off
219
- parsed_doc_string['line'] = parsed_doc_string.delete(:location)[:line]
220
- end
221
-
222
- # Adapts the AST sub-tree that is rooted at the given table node.
223
- def adapt_step_table!(parsed_step_table)
224
- # Saving off the original data
225
- parsed_step_table['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step_table))
226
-
227
- # Removing parsed data for child elements in order to avoid duplicating data
228
- parsed_step_table['cuke_modeler_parsing_data'][:rows] = nil
229
-
230
- parsed_step_table['rows'] = []
231
- parsed_step_table[:rows].each do |row|
232
- adapt_table_row!(row)
233
- end
234
- parsed_step_table['rows'].concat(parsed_step_table.delete(:rows))
235
- parsed_step_table['line'] = parsed_step_table.delete(:location)[:line]
236
- end
237
-
238
- # Adapts the AST sub-tree that is rooted at the given row node.
239
- def adapt_table_row!(parsed_table_row)
240
- # Saving off the original data
241
- parsed_table_row['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_table_row))
242
-
243
- # Removing parsed data for child elements in order to avoid duplicating data which the child elements will themselves include
244
- parsed_table_row['cuke_modeler_parsing_data'][:cells] = nil
245
-
246
-
247
- parsed_table_row['line'] = parsed_table_row.delete(:location)[:line]
248
-
249
- parsed_table_row['cells'] = []
250
- parsed_table_row[:cells].each do |row|
251
- adapt_table_cell!(row)
252
- end
253
- parsed_table_row['cells'].concat(parsed_table_row.delete(:cells))
254
- end
255
-
256
- # Adapts the AST sub-tree that is rooted at the given cell node.
257
- def adapt_table_cell!(parsed_cell)
258
- # Saving off the original data
259
- parsed_cell['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_cell))
260
-
261
- parsed_cell['value'] = parsed_cell.delete(:value)
262
- parsed_cell['line'] = parsed_cell.delete(:location)[:line]
263
- end
264
-
265
-
266
- private
267
-
268
-
269
- def adapt_child_elements!(parsed_children)
270
- return if parsed_children.empty?
271
-
272
- background_child = parsed_children.find { |child| child[:background] }
273
-
274
- if background_child
275
- adapt_background!(background_child)
276
-
277
- remaining_children = parsed_children.reject { |child| child[:background] }
278
- end
279
-
280
- adapt_tests!(remaining_children || parsed_children)
281
- end
282
-
283
- def adapt_tests!(parsed_tests)
284
- return unless parsed_tests
285
-
286
- parsed_tests.each do |test|
287
- adapt_test!(test)
288
- end
289
- end
290
-
291
- def adapt_test!(parsed_test)
292
- # Saving off the original data
293
- parsed_test['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_test))
294
-
295
-
296
- case
297
- when parsed_test[:scenario] && parsed_test[:scenario][:examples].any?
298
- adapt_outline!(parsed_test)
299
- when parsed_test[:scenario]
300
- adapt_scenario!(parsed_test)
301
- else
302
- raise(ArgumentError, "Unknown test type with keys: #{parsed_test.keys}")
303
- end
304
- end
305
-
306
- end
307
- end