Class: CukeModeler::Gherkin9Adapter
- Inherits:
-
Object
- Object
- CukeModeler::Gherkin9Adapter
- Defined in:
- lib/cuke_modeler/adapters/gherkin_9_adapter.rb
Overview
NOT A PART OF THE PUBLIC API An adapter that can convert the output of version 9.x of the cucumber-gherkin gem into input that is consumable by this gem.
Direct Known Subclasses
Gherkin10Adapter, Gherkin11Adapter, Gherkin12Adapter, Gherkin13Adapter, Gherkin14Adapter, Gherkin15Adapter
Instance Method Summary collapse
-
#adapt(parsed_ast) ⇒ Object
Adapts the given AST into the shape that this gem expects.
-
#adapt_background!(parsed_background) ⇒ Object
Adapts the AST sub-tree that is rooted at the given background node.
-
#adapt_comment!(parsed_comment) ⇒ Object
Adapts the AST sub-tree that is rooted at the given comment node.
-
#adapt_doc_string!(parsed_doc_string) ⇒ Object
Adapts the AST sub-tree that is rooted at the given doc string node.
-
#adapt_example!(parsed_example) ⇒ Object
Adapts the AST sub-tree that is rooted at the given example node.
-
#adapt_feature!(parsed_feature) ⇒ Object
Adapts the AST sub-tree that is rooted at the given feature node.
-
#adapt_outline!(parsed_test) ⇒ Object
Adapts the AST sub-tree that is rooted at the given outline node.
-
#adapt_rule!(parsed_rule) ⇒ Object
Adapts the AST sub-tree that is rooted at the given rule node.
-
#adapt_scenario!(parsed_test) ⇒ Object
Adapts the AST sub-tree that is rooted at the given scenario node.
-
#adapt_step!(parsed_step) ⇒ Object
Adapts the AST sub-tree that is rooted at the given step node.
-
#adapt_step_table!(parsed_step_table) ⇒ Object
Adapts the AST sub-tree that is rooted at the given table node.
-
#adapt_table_cell!(parsed_cell) ⇒ Object
Adapts the AST sub-tree that is rooted at the given cell node.
-
#adapt_table_row!(parsed_table_row) ⇒ Object
Adapts the AST sub-tree that is rooted at the given row node.
-
#adapt_tag!(parsed_tag) ⇒ Object
Adapts the AST sub-tree that is rooted at the given tag node.
Instance Method Details
#adapt(parsed_ast) ⇒ Object
Adapts the given AST into the shape that this gem expects
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 9 def adapt(parsed_ast) # Saving off the original data parsed_ast['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_ast)) # Removing parsed data for child elements in order to avoid duplicating data parsed_ast['cuke_modeler_parsing_data'][:feature] = nil if parsed_ast['cuke_modeler_parsing_data'][:feature] parsed_ast['cuke_modeler_parsing_data'][:comments] = nil if parsed_ast['cuke_modeler_parsing_data'][:comments] parsed_ast['comments'] = [] if parsed_ast[:comments] parsed_ast[:comments].each do |comment| adapt_comment!(comment) end parsed_ast['comments'].concat(parsed_ast.delete(:comments)) end adapt_feature!(parsed_ast[:feature]) if parsed_ast[:feature] parsed_ast['feature'] = parsed_ast.delete(:feature) parsed_ast end |
#adapt_background!(parsed_background) ⇒ Object
Adapts the AST sub-tree that is rooted at the given background node.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 61 def adapt_background!(parsed_background) # Saving off the original data parsed_background['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_background)) # Removing parsed data for child elements in order to avoid duplicating data parsed_background['cuke_modeler_parsing_data'][:background][:steps] = nil if parsed_background['cuke_modeler_parsing_data'][:background][:steps] parsed_background['type'] = 'Background' parsed_background['keyword'] = parsed_background[:background].delete(:keyword) parsed_background['name'] = parsed_background[:background].delete(:name) parsed_background['description'] = parsed_background[:background].delete(:description) || '' parsed_background['line'] = parsed_background[:background].delete(:location)[:line] parsed_background['steps'] = [] if parsed_background[:background][:steps] parsed_background[:background][:steps].each do |step| adapt_step!(step) end parsed_background['steps'].concat(parsed_background[:background].delete(:steps)) end end |
#adapt_comment!(parsed_comment) ⇒ Object
Adapts the AST sub-tree that is rooted at the given comment node.
219 220 221 222 223 224 225 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 219 def adapt_comment!(parsed_comment) # Saving off the original data parsed_comment['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_comment)) parsed_comment['text'] = parsed_comment.delete(:text) parsed_comment['line'] = parsed_comment.delete(:location)[:line] end |
#adapt_doc_string!(parsed_doc_string) ⇒ Object
Adapts the AST sub-tree that is rooted at the given doc string node.
253 254 255 256 257 258 259 260 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 253 def adapt_doc_string!(parsed_doc_string) # Saving off the original data parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string)) parsed_doc_string['value'] = parsed_doc_string.delete(:content) parsed_doc_string['content_type'] = parsed_doc_string.delete(:media_type) parsed_doc_string['line'] = parsed_doc_string.delete(:location)[:line] end |
#adapt_example!(parsed_example) ⇒ Object
Adapts the AST sub-tree that is rooted at the given example node.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 172 def adapt_example!(parsed_example) # Saving off the original data parsed_example['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_example)) # Removing parsed data for child elements in order to avoid duplicating data parsed_example['cuke_modeler_parsing_data'][:tags] = nil if parsed_example['cuke_modeler_parsing_data'][:tags] parsed_example['cuke_modeler_parsing_data'][:table_header] = nil if parsed_example['cuke_modeler_parsing_data'][:table_header] parsed_example['cuke_modeler_parsing_data'][:table_body] = nil if parsed_example['cuke_modeler_parsing_data'][:table_body] parsed_example['keyword'] = parsed_example.delete(:keyword) parsed_example['name'] = parsed_example.delete(:name) parsed_example['line'] = parsed_example.delete(:location)[:line] parsed_example['description'] = parsed_example.delete(:description) || '' parsed_example['rows'] = [] if parsed_example[:table_header] adapt_table_row!(parsed_example[:table_header]) parsed_example['rows'] << parsed_example.delete(:table_header) end if parsed_example[:table_body] parsed_example[:table_body].each do |row| adapt_table_row!(row) end parsed_example['rows'].concat(parsed_example.delete(:table_body)) end parsed_example['tags'] = [] if parsed_example[:tags] parsed_example[:tags].each do |tag| adapt_tag!(tag) end parsed_example['tags'].concat(parsed_example.delete(:tags)) end end |
#adapt_feature!(parsed_feature) ⇒ Object
Adapts the AST sub-tree that is rooted at the given feature node.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 32 def adapt_feature!(parsed_feature) # Saving off the original data parsed_feature['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_feature)) # Removing parsed data for child elements in order to avoid duplicating data parsed_feature['cuke_modeler_parsing_data'][:tags] = nil if parsed_feature['cuke_modeler_parsing_data'][:tags] parsed_feature['cuke_modeler_parsing_data'][:children] = nil if parsed_feature['cuke_modeler_parsing_data'][:children] parsed_feature['keyword'] = parsed_feature.delete(:keyword) parsed_feature['name'] = parsed_feature.delete(:name) parsed_feature['description'] = parsed_feature.delete(:description) || '' parsed_feature['line'] = parsed_feature.delete(:location)[:line] parsed_feature['elements'] = [] if parsed_feature[:children] adapt_child_elements!(parsed_feature[:children]) parsed_feature['elements'].concat(parsed_feature.delete(:children)) end parsed_feature['tags'] = [] if parsed_feature[:tags] parsed_feature[:tags].each do |tag| adapt_tag!(tag) end parsed_feature['tags'].concat(parsed_feature.delete(:tags)) end end |
#adapt_outline!(parsed_test) ⇒ Object
Adapts the AST sub-tree that is rooted at the given outline node.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 134 def adapt_outline!(parsed_test) # Removing parsed data for child elements in order to avoid duplicating data parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] = nil if parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] = nil if parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] parsed_test['cuke_modeler_parsing_data'][:scenario][:examples] = nil if parsed_test['cuke_modeler_parsing_data'][:scenario][:examples] parsed_test['type'] = 'ScenarioOutline' parsed_test['keyword'] = parsed_test[:scenario].delete(:keyword) parsed_test['name'] = parsed_test[:scenario].delete(:name) parsed_test['description'] = parsed_test[:scenario].delete(:description) || '' parsed_test['line'] = parsed_test[:scenario].delete(:location)[:line] parsed_test['tags'] = [] if parsed_test[:scenario][:tags] parsed_test[:scenario][:tags].each do |tag| adapt_tag!(tag) end parsed_test['tags'].concat(parsed_test[:scenario].delete(:tags)) end parsed_test['steps'] = [] if parsed_test[:scenario][:steps] parsed_test[:scenario][:steps].each do |step| adapt_step!(step) end parsed_test['steps'].concat(parsed_test[:scenario].delete(:steps)) end parsed_test['examples'] = [] if parsed_test[:scenario][:examples] parsed_test[:scenario][:examples].each do |step| adapt_example!(step) end parsed_test['examples'].concat(parsed_test[:scenario].delete(:examples)) end end |
#adapt_rule!(parsed_rule) ⇒ Object
Adapts the AST sub-tree that is rooted at the given rule node.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 84 def adapt_rule!(parsed_rule) # Saving off the original data parsed_rule['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_rule)) # Removing parsed data for child elements in order to avoid duplicating data parsed_rule['cuke_modeler_parsing_data'][:rule][:children] = nil if parsed_rule['cuke_modeler_parsing_data'][:rule][:children] parsed_rule['type'] = 'Rule' parsed_rule['keyword'] = parsed_rule[:rule].delete(:keyword) parsed_rule['name'] = parsed_rule[:rule].delete(:name) parsed_rule['description'] = parsed_rule[:rule].delete(:description) || '' parsed_rule['line'] = parsed_rule[:rule].delete(:location)[:line] parsed_rule['elements'] = [] if parsed_rule[:rule][:children] adapt_child_elements!(parsed_rule[:rule][:children]) parsed_rule['elements'].concat(parsed_rule[:rule].delete(:children)) end end |
#adapt_scenario!(parsed_test) ⇒ Object
Adapts the AST sub-tree that is rooted at the given scenario node.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 105 def adapt_scenario!(parsed_test) # Removing parsed data for child elements in order to avoid duplicating data parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] = nil if parsed_test['cuke_modeler_parsing_data'][:scenario][:tags] parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] = nil if parsed_test['cuke_modeler_parsing_data'][:scenario][:steps] parsed_test['type'] = 'Scenario' parsed_test['keyword'] = parsed_test[:scenario].delete(:keyword) parsed_test['name'] = parsed_test[:scenario].delete(:name) parsed_test['description'] = parsed_test[:scenario].delete(:description) || '' parsed_test['line'] = parsed_test[:scenario].delete(:location)[:line] parsed_test['tags'] = [] if parsed_test[:scenario][:tags] parsed_test[:scenario][:tags].each do |tag| adapt_tag!(tag) end parsed_test['tags'].concat(parsed_test[:scenario].delete(:tags)) end parsed_test['steps'] = [] if parsed_test[:scenario][:steps] parsed_test[:scenario][:steps].each do |step| adapt_step!(step) end parsed_test['steps'].concat(parsed_test[:scenario].delete(:steps)) end end |
#adapt_step!(parsed_step) ⇒ Object
Adapts the AST sub-tree that is rooted at the given step node.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 228 def adapt_step!(parsed_step) # Saving off the original data parsed_step['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step)) # Removing parsed data for child elements in order to avoid duplicating data parsed_step['cuke_modeler_parsing_data'][:data_table] = nil if parsed_step['cuke_modeler_parsing_data'][:data_table] parsed_step['cuke_modeler_parsing_data'][:doc_string] = nil if parsed_step['cuke_modeler_parsing_data'][:doc_string] parsed_step['keyword'] = parsed_step.delete(:keyword) parsed_step['name'] = parsed_step.delete(:text) parsed_step['line'] = parsed_step.delete(:location)[:line] case when parsed_step[:doc_string] adapt_doc_string!(parsed_step[:doc_string]) parsed_step['doc_string'] = parsed_step.delete(:doc_string) when parsed_step[:data_table] adapt_step_table!(parsed_step[:data_table]) parsed_step['table'] = parsed_step.delete(:data_table) else # Step has no extra argument end end |
#adapt_step_table!(parsed_step_table) ⇒ Object
Adapts the AST sub-tree that is rooted at the given table node.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 263 def adapt_step_table!(parsed_step_table) # Saving off the original data parsed_step_table['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step_table)) # Removing parsed data for child elements in order to avoid duplicating data parsed_step_table['cuke_modeler_parsing_data'][:rows] = nil parsed_step_table['rows'] = [] parsed_step_table[:rows].each do |row| adapt_table_row!(row) end parsed_step_table['rows'].concat(parsed_step_table.delete(:rows)) parsed_step_table['line'] = parsed_step_table.delete(:location)[:line] end |
#adapt_table_cell!(parsed_cell) ⇒ Object
Adapts the AST sub-tree that is rooted at the given cell node.
296 297 298 299 300 301 302 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 296 def adapt_table_cell!(parsed_cell) # Saving off the original data parsed_cell['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_cell)) parsed_cell['value'] = parsed_cell.delete(:value) parsed_cell['line'] = parsed_cell.delete(:location)[:line] end |
#adapt_table_row!(parsed_table_row) ⇒ Object
Adapts the AST sub-tree that is rooted at the given row node.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 279 def adapt_table_row!(parsed_table_row) # Saving off the original data parsed_table_row['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_table_row)) # Removing parsed data for child elements in order to avoid duplicating data which the child elements will themselves include parsed_table_row['cuke_modeler_parsing_data'][:cells] = nil parsed_table_row['line'] = parsed_table_row.delete(:location)[:line] parsed_table_row['cells'] = [] parsed_table_row[:cells].each do |row| adapt_table_cell!(row) end parsed_table_row['cells'].concat(parsed_table_row.delete(:cells)) end |
#adapt_tag!(parsed_tag) ⇒ Object
Adapts the AST sub-tree that is rooted at the given tag node.
210 211 212 213 214 215 216 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 210 def adapt_tag!(parsed_tag) # Saving off the original data parsed_tag['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_tag)) parsed_tag['name'] = parsed_tag.delete(:name) parsed_tag['line'] = parsed_tag.delete(:location)[:line] end |