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(ast) ⇒ Object
Adapts the given AST into the shape that this gem expects.
-
#adapt_background(background_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given background node.
-
#adapt_comment(comment_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given comment node.
-
#adapt_doc_string(doc_string_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given doc string node.
-
#adapt_example(example_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given example node.
-
#adapt_feature(feature_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given feature node.
-
#adapt_outline(test_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given outline node.
-
#adapt_rule(rule_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given rule node.
-
#adapt_scenario(test_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given scenario node.
-
#adapt_step(step_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given step node.
-
#adapt_step_table(step_table_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given table node.
-
#adapt_table_cell(cell_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given cell node.
-
#adapt_table_row(table_row_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given row node.
-
#adapt_tag(tag_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given tag node.
Instance Method Details
#adapt(ast) ⇒ Object
Adapts the given AST into the shape that this gem expects
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 13 def adapt(ast) adapted_ast = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_ast, ast) clear_child_elements(adapted_ast, [[:feature], [:comments]]) adapted_ast['comments'] = adapt_comments(ast) adapted_ast['feature'] = adapt_feature(ast[:feature]) adapted_ast end |
#adapt_background(background_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given background node.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 50 def adapt_background(background_ast) adapted_background = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_background, background_ast) clear_child_elements(adapted_background, [[:background, :steps]]) adapted_background['type'] = 'Background' adapted_background['keyword'] = background_ast[:background][:keyword] adapted_background['name'] = background_ast[:background][:name] adapted_background['description'] = background_ast[:background][:description] || '' adapted_background['line'] = background_ast[:background][:location][:line] adapted_background['steps'] = adapt_steps(background_ast[:background]) adapted_background end |
#adapt_comment(comment_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given comment node.
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 172 def adapt_comment(comment_ast) adapted_comment = {} # Saving off the original data save_original_data(adapted_comment, comment_ast) adapted_comment['text'] = comment_ast[:text] adapted_comment['line'] = comment_ast[:location][:line] adapted_comment end |
#adapt_doc_string(doc_string_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given doc string node.
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 207 def adapt_doc_string(doc_string_ast) adapted_doc_string = {} # Saving off the original data save_original_data(adapted_doc_string, doc_string_ast) adapted_doc_string['value'] = doc_string_ast[:content] adapted_doc_string['content_type'] = doc_string_ast[:media_type] adapted_doc_string['line'] = doc_string_ast[:location][:line] adapted_doc_string end |
#adapt_example(example_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given example node.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 132 def adapt_example(example_ast) adapted_example = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_example, example_ast) clear_child_elements(adapted_example, [[:tags], [:table_header], [:table_body]]) adapted_example['keyword'] = example_ast[:keyword] adapted_example['name'] = example_ast[:name] adapted_example['line'] = example_ast[:location][:line] adapted_example['description'] = example_ast[:description] || '' adapted_example['rows'] = [] adapted_example['rows'] << adapt_table_row(example_ast[:table_header]) if example_ast[:table_header] example_ast[:table_body]&.each do |row| adapted_example['rows'] << adapt_table_row(row) end adapted_example['tags'] = (example_ast) adapted_example end |
#adapt_feature(feature_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given feature node.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 28 def adapt_feature(feature_ast) return nil unless feature_ast adapted_feature = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_feature, feature_ast) clear_child_elements(adapted_feature, [[:tags], [:children]]) adapted_feature['keyword'] = feature_ast[:keyword] adapted_feature['name'] = feature_ast[:name] adapted_feature['description'] = feature_ast[:description] || '' adapted_feature['line'] = feature_ast[:location][:line] adapted_feature['elements'] = adapt_child_elements(feature_ast) adapted_feature['tags'] = (feature_ast) adapted_feature end |
#adapt_outline(test_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given outline node.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 109 def adapt_outline(test_ast) adapted_outline = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_outline, test_ast) clear_child_elements(adapted_outline, [[:scenario, :tags], [:scenario, :steps], [:scenario, :examples]]) adapted_outline['type'] = 'ScenarioOutline' adapted_outline['keyword'] = test_ast[:scenario][:keyword] adapted_outline['name'] = test_ast[:scenario][:name] adapted_outline['description'] = test_ast[:scenario][:description] || '' adapted_outline['line'] = test_ast[:scenario][:location][:line] adapted_outline['tags'] = (test_ast[:scenario]) adapted_outline['steps'] = adapt_steps(test_ast[:scenario]) adapted_outline['examples'] = adapt_examples(test_ast[:scenario]) adapted_outline end |
#adapt_rule(rule_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given rule node.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 69 def adapt_rule(rule_ast) adapted_rule = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_rule, rule_ast) clear_child_elements(adapted_rule, [[:rule, :children]]) adapted_rule['type'] = 'Rule' adapted_rule['keyword'] = rule_ast[:rule][:keyword] adapted_rule['name'] = rule_ast[:rule][:name] adapted_rule['description'] = rule_ast[:rule][:description] || '' adapted_rule['line'] = rule_ast[:rule][:location][:line] adapted_rule['elements'] = adapt_child_elements(rule_ast[:rule]) adapted_rule end |
#adapt_scenario(test_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given scenario node.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 88 def adapt_scenario(test_ast) adapted_scenario = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_scenario, test_ast) clear_child_elements(adapted_scenario, [[:scenario, :tags], [:scenario, :steps]]) adapted_scenario['type'] = 'Scenario' adapted_scenario['keyword'] = test_ast[:scenario][:keyword] adapted_scenario['name'] = test_ast[:scenario][:name] adapted_scenario['description'] = test_ast[:scenario][:description] || '' adapted_scenario['line'] = test_ast[:scenario][:location][:line] adapted_scenario['tags'] = (test_ast[:scenario]) adapted_scenario['steps'] = adapt_steps(test_ast[:scenario]) adapted_scenario end |
#adapt_step(step_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given step node.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 185 def adapt_step(step_ast) adapted_step = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_step, step_ast) clear_child_elements(adapted_step, [[:data_table], [:doc_string]]) adapted_step['keyword'] = step_ast[:keyword] adapted_step['name'] = step_ast[:text] adapted_step['line'] = step_ast[:location][:line] if step_ast[:doc_string] adapted_step['doc_string'] = adapt_doc_string(step_ast[:doc_string]) elsif step_ast[:data_table] adapted_step['table'] = adapt_step_table(step_ast[:data_table]) end adapted_step end |
#adapt_step_table(step_table_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given table node.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 221 def adapt_step_table(step_table_ast) adapted_step_table = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_step_table, step_table_ast) clear_child_elements(adapted_step_table, [[:rows]]) adapted_step_table['rows'] = [] step_table_ast[:rows].each do |row| adapted_step_table['rows'] << adapt_table_row(row) end adapted_step_table['line'] = step_table_ast[:location][:line] adapted_step_table end |
#adapt_table_cell(cell_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given cell node.
256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 256 def adapt_table_cell(cell_ast) adapted_cell = {} # Saving off the original data save_original_data(adapted_cell, cell_ast) adapted_cell['value'] = cell_ast[:value] adapted_cell['line'] = cell_ast[:location][:line] adapted_cell end |
#adapt_table_row(table_row_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given row node.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 238 def adapt_table_row(table_row_ast) adapted_table_row = {} # Saving off the original data and removing parsed data for child elements in order to avoid duplicating data save_original_data(adapted_table_row, table_row_ast) clear_child_elements(adapted_table_row, [[:cells]]) adapted_table_row['line'] = table_row_ast[:location][:line] adapted_table_row['cells'] = [] table_row_ast[:cells].each do |row| adapted_table_row['cells'] << adapt_table_cell(row) end adapted_table_row end |
#adapt_tag(tag_ast) ⇒ Object
Adapts the AST sub-tree that is rooted at the given tag node.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/cuke_modeler/adapters/gherkin_9_adapter.rb', line 159 def adapt_tag(tag_ast) adapted_tag = {} # Saving off the original data save_original_data(adapted_tag, tag_ast) adapted_tag['name'] = tag_ast[:name] adapted_tag['line'] = tag_ast[:location][:line] adapted_tag end |