cuke_modeler 3.10.0 → 3.14.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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/README.md +1 -2
  4. data/cuke_modeler.gemspec +3 -4
  5. data/lib/cuke_modeler/adapters/gherkin_20_adapter.rb +350 -0
  6. data/lib/cuke_modeler/adapters/gherkin_21_adapter.rb +13 -0
  7. data/lib/cuke_modeler/adapters/gherkin_22_adapter.rb +13 -0
  8. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +16 -5
  9. data/lib/cuke_modeler/adapters/gherkin_base_adapter.rb +14 -0
  10. data/lib/cuke_modeler/containing.rb +13 -13
  11. data/lib/cuke_modeler/nested.rb +1 -0
  12. data/lib/cuke_modeler/parsing.rb +23 -2
  13. data/lib/cuke_modeler/sourceable.rb +4 -1
  14. data/lib/cuke_modeler/version.rb +1 -1
  15. data/testing/cucumber/features/modeling/background_modeling.feature +28 -5
  16. data/testing/cucumber/features/modeling/cell_modeling.feature +46 -0
  17. data/testing/cucumber/features/modeling/comment_modeling.feature +20 -0
  18. data/testing/cucumber/features/modeling/doc_string_modeling.feature +26 -0
  19. data/testing/cucumber/features/modeling/example_modeling.feature +25 -0
  20. data/testing/cucumber/features/modeling/feature_modeling.feature +7 -0
  21. data/testing/cucumber/features/modeling/outline_modeling.feature +26 -1
  22. data/testing/cucumber/features/modeling/row_modeling.feature +23 -0
  23. data/testing/cucumber/features/modeling/rule_modeling.feature +21 -0
  24. data/testing/cucumber/features/modeling/scenario_modeling.feature +22 -0
  25. data/testing/cucumber/features/modeling/step_modeling.feature +22 -0
  26. data/testing/cucumber/features/modeling/table_modeling.feature +24 -0
  27. data/testing/cucumber/features/modeling/tag_modeling.feature +20 -0
  28. metadata +26 -22
@@ -55,7 +55,7 @@ module CukeModeler
55
55
 
56
56
  def populate_scenario(scenario_object, parsed_scenario_data)
57
57
  populate_parsing_data(scenario_object, parsed_scenario_data)
58
- populate_source_line(scenario_object, parsed_scenario_data)
58
+ populate_source_location(scenario_object, parsed_scenario_data)
59
59
  populate_keyword(scenario_object, parsed_scenario_data)
60
60
  populate_name(scenario_object, parsed_scenario_data)
61
61
  populate_description(scenario_object, parsed_scenario_data)
@@ -65,7 +65,7 @@ module CukeModeler
65
65
 
66
66
  def populate_outline(outline_object, parsed_outline_data)
67
67
  populate_parsing_data(outline_object, parsed_outline_data)
68
- populate_source_line(outline_object, parsed_outline_data)
68
+ populate_source_location(outline_object, parsed_outline_data)
69
69
  populate_keyword(outline_object, parsed_outline_data)
70
70
  populate_name(outline_object, parsed_outline_data)
71
71
  populate_description(outline_object, parsed_outline_data)
@@ -79,7 +79,7 @@ module CukeModeler
79
79
  populate_keyword(background_object, parsed_background_data)
80
80
  populate_name(background_object, parsed_background_data)
81
81
  populate_description(background_object, parsed_background_data)
82
- populate_source_line(background_object, parsed_background_data)
82
+ populate_source_location(background_object, parsed_background_data)
83
83
  populate_steps(background_object, parsed_background_data)
84
84
  end
85
85
 
@@ -87,7 +87,7 @@ module CukeModeler
87
87
  populate_text(step_object, parsed_step_data)
88
88
  populate_block(step_object, parsed_step_data)
89
89
  populate_keyword(step_object, parsed_step_data)
90
- populate_source_line(step_object, parsed_step_data)
90
+ populate_source_location(step_object, parsed_step_data)
91
91
  populate_parsing_data(step_object, parsed_step_data)
92
92
  end
93
93
 
@@ -102,12 +102,12 @@ module CukeModeler
102
102
  def populate_table(table_object, parsed_table_data)
103
103
  populate_row_models(table_object, parsed_table_data)
104
104
  populate_parsing_data(table_object, parsed_table_data)
105
- populate_source_line(table_object, parsed_table_data)
105
+ populate_source_location(table_object, parsed_table_data)
106
106
  end
107
107
 
108
108
  def populate_cell(cell_object, parsed_cell_data)
109
109
  populate_cell_value(cell_object, parsed_cell_data)
110
- populate_source_line(cell_object, parsed_cell_data)
110
+ populate_source_location(cell_object, parsed_cell_data)
111
111
  populate_parsing_data(cell_object, parsed_cell_data)
112
112
  end
113
113
 
@@ -115,13 +115,13 @@ module CukeModeler
115
115
  populate_content_type(doc_string_object, parsed_doc_string_data)
116
116
  populate_content(doc_string_object, parsed_doc_string_data)
117
117
  populate_parsing_data(doc_string_object, parsed_doc_string_data)
118
- populate_source_line(doc_string_object, parsed_doc_string_data)
118
+ populate_source_location(doc_string_object, parsed_doc_string_data)
119
119
  end
120
120
 
121
121
  def populate_example(example_object, parsed_example_data)
122
122
  populate_parsing_data(example_object, parsed_example_data)
123
123
  populate_keyword(example_object, parsed_example_data)
124
- populate_source_line(example_object, parsed_example_data)
124
+ populate_source_location(example_object, parsed_example_data)
125
125
  populate_name(example_object, parsed_example_data)
126
126
  populate_description(example_object, parsed_example_data)
127
127
  populate_tags(example_object, parsed_example_data)
@@ -129,14 +129,14 @@ module CukeModeler
129
129
  end
130
130
 
131
131
  def populate_row(row_object, parsed_row_data)
132
- populate_source_line(row_object, parsed_row_data)
132
+ populate_source_location(row_object, parsed_row_data)
133
133
  populate_row_cells(row_object, parsed_row_data)
134
134
  populate_parsing_data(row_object, parsed_row_data)
135
135
  end
136
136
 
137
137
  def populate_feature(feature_object, parsed_feature_data)
138
138
  populate_parsing_data(feature_object, parsed_feature_data)
139
- populate_source_line(feature_object, parsed_feature_data)
139
+ populate_source_location(feature_object, parsed_feature_data)
140
140
  populate_keyword(feature_object, parsed_feature_data)
141
141
  populate_name(feature_object, parsed_feature_data)
142
142
  populate_description(feature_object, parsed_feature_data)
@@ -146,7 +146,7 @@ module CukeModeler
146
146
 
147
147
  def populate_rule(rule_object, parsed_rule_data)
148
148
  populate_parsing_data(rule_object, parsed_rule_data)
149
- populate_source_line(rule_object, parsed_rule_data)
149
+ populate_source_location(rule_object, parsed_rule_data)
150
150
  populate_keyword(rule_object, parsed_rule_data)
151
151
  populate_name(rule_object, parsed_rule_data)
152
152
  populate_description(rule_object, parsed_rule_data)
@@ -182,13 +182,13 @@ module CukeModeler
182
182
  def populate_tag(tag_object, processed_tag_data)
183
183
  populate_name(tag_object, processed_tag_data)
184
184
  populate_parsing_data(tag_object, processed_tag_data)
185
- populate_source_line(tag_object, processed_tag_data)
185
+ populate_source_location(tag_object, processed_tag_data)
186
186
  end
187
187
 
188
188
  def populate_comment(comment_object, processed_comment_data)
189
189
  populate_comment_text(comment_object, processed_comment_data)
190
190
  populate_parsing_data(comment_object, processed_comment_data)
191
- populate_source_line(comment_object, processed_comment_data)
191
+ populate_source_location(comment_object, processed_comment_data)
192
192
  end
193
193
 
194
194
  def populate_comment_text(comment_model, parsed_comment_data)
@@ -30,6 +30,7 @@ module CukeModeler
30
30
  directory: [Directory],
31
31
  feature_file: [FeatureFile],
32
32
  feature: [Feature],
33
+ rule: [Rule],
33
34
  test: [Scenario, Outline, Background],
34
35
  background: [Background],
35
36
  scenario: [Scenario],
@@ -1,3 +1,5 @@
1
+ # rubocop:disable Metrics/ModuleLength - Just not going to worry about this
2
+
1
3
  # Have to at least load some version of the gem before which version of the gem has been loaded can
2
4
  # be determined and the rest of the needed files can be loaded.
3
5
  require 'gherkin'
@@ -7,7 +9,7 @@ require 'gherkin'
7
9
  # an 'adapter' appropriate to the version of the *cucumber-gherkin* gem that has been activated.
8
10
  gherkin_version = Gem.loaded_specs['cucumber-gherkin'].version.version
9
11
  gherkin_major_version = gherkin_version.match(/^(\d+)\./)[1].to_i
10
- supported_gherkin_versions = (9..19)
12
+ supported_gherkin_versions = (9..22)
11
13
 
12
14
  raise("Unknown Gherkin version: '#{gherkin_version}'") unless supported_gherkin_versions.include?(gherkin_major_version)
13
15
 
@@ -32,7 +34,7 @@ module CukeModeler
32
34
 
33
35
  # The dialects currently known by the gherkin gem
34
36
  def dialects
35
- @dialects ||= Gherkin::DIALECTS
37
+ Gherkin::DIALECTS
36
38
  end
37
39
 
38
40
  # Parses the Cucumber feature given in *source_text* and returns a hash representation of
@@ -61,6 +63,23 @@ module CukeModeler
61
63
  # inside of it, so I'm leaving this here in case it changes again
62
64
  # rubocop:disable Lint/DuplicateMethods
63
65
  case gherkin_major_version
66
+ when 20, 21, 22
67
+ # TODO: make these methods private?
68
+ # NOT A PART OF THE PUBLIC API
69
+ # The method to use for parsing Gherkin text
70
+ def parsing_method(source_text, filename)
71
+ messages = Gherkin.from_source(filename,
72
+ source_text,
73
+ { include_gherkin_document: true })
74
+ .to_a
75
+
76
+ error_message = messages.find(&:parse_error)
77
+ gherkin_ast_message = messages.find(&:gherkin_document)
78
+
79
+ raise error_message.parse_error.message if error_message
80
+
81
+ gherkin_ast_message.gherkin_document
82
+ end
64
83
  when 19
65
84
  # TODO: make these methods private?
66
85
  # NOT A PART OF THE PUBLIC API
@@ -175,3 +194,5 @@ module CukeModeler
175
194
 
176
195
  end
177
196
  end
197
+
198
+ # rubocop:enable Metrics/ModuleLength
@@ -8,12 +8,15 @@ module CukeModeler
8
8
  # The line number where the element began in the source code
9
9
  attr_accessor :source_line
10
10
 
11
+ # The column number where the element began in the source code
12
+ attr_accessor :source_column
11
13
 
12
14
  private
13
15
 
14
16
 
15
- def populate_source_line(model, parsed_model_data)
17
+ def populate_source_location(model, parsed_model_data)
16
18
  model.source_line = parsed_model_data['line']
19
+ model.source_column = parsed_model_data['column']
17
20
  end
18
21
 
19
22
  end
@@ -1,4 +1,4 @@
1
1
  module CukeModeler
2
2
  # The gem version
3
- VERSION = '3.10.0'.freeze
3
+ VERSION = '3.14.0'.freeze
4
4
  end
@@ -23,21 +23,21 @@ Feature: Background modeling
23
23
  """
24
24
 
25
25
 
26
- Scenario: Modeling a backgrounds's keyword
26
+ Scenario: Modeling a background's keyword
27
27
  When the backgrounds's keyword is requested
28
28
  """
29
29
  @model.keyword
30
30
  """
31
31
  Then the model returns "Background"
32
32
 
33
- Scenario: Modeling a backgrounds's name
33
+ Scenario: Modeling a background's name
34
34
  When the background's name is requested
35
35
  """
36
36
  @model.name
37
37
  """
38
38
  Then the model returns "Some general test setup stuff."
39
39
 
40
- Scenario: Modeling a backgrounds's description
40
+ Scenario: Modeling a background's description
41
41
  When the background's description is requested
42
42
  """
43
43
  @model.description
@@ -50,7 +50,7 @@ Feature: Background modeling
50
50
  Even more.
51
51
  """
52
52
 
53
- Scenario: Modeling a backgrounds's steps
53
+ Scenario: Modeling a background's steps
54
54
  When the background's steps are requested
55
55
  """
56
56
  @model.steps
@@ -60,7 +60,7 @@ Feature: Background modeling
60
60
  | another setup step |
61
61
  | an action step |
62
62
 
63
- Scenario: Modeling a backgrounds's source line
63
+ Scenario: Modeling a background's source line
64
64
  Given the following gherkin:
65
65
  """
66
66
  Feature:
@@ -81,3 +81,26 @@ Feature: Background modeling
81
81
  @model.source_line
82
82
  """
83
83
  Then the model returns "3"
84
+
85
+ Scenario: Modeling a background's source column
86
+ Given the following gherkin:
87
+ """
88
+ Feature:
89
+
90
+
91
+ Background:
92
+ * a step
93
+ """
94
+ And a feature model based on that gherkin
95
+ """
96
+ @model = CukeModeler::Feature.new(<source_text>)
97
+ """
98
+ And the background model of that feature model
99
+ """
100
+ @model = @model.background
101
+ """
102
+ When the background's source column is requested
103
+ """
104
+ @model.source_column
105
+ """
106
+ Then the model returns "3"
@@ -20,3 +20,49 @@ Feature: Cell modeling
20
20
  @model.value
21
21
  """
22
22
  Then the model returns "foo"
23
+
24
+ Scenario: Modeling a cell's source line
25
+ Given the following gherkin:
26
+ """
27
+ Feature:
28
+
29
+ Scenario:
30
+ * a step
31
+ | foo |
32
+ """
33
+ And a feature model based on that gherkin
34
+ """
35
+ @model = CukeModeler::Feature.new(<source_text>)
36
+ """
37
+ And the cell model inside of that feature model
38
+ """
39
+ @model = @model.tests.first.steps.first.block.rows.first.cells.first
40
+ """
41
+ When the cell's source line is requested
42
+ """
43
+ @model.source_line
44
+ """
45
+ Then the model returns "5"
46
+
47
+ Scenario: Modeling a cell's source column
48
+ Given the following gherkin:
49
+ """
50
+ Feature:
51
+
52
+ Scenario:
53
+ * a step
54
+ | foo |
55
+ """
56
+ And a feature model based on that gherkin
57
+ """
58
+ @model = CukeModeler::Feature.new(<source_text>)
59
+ """
60
+ And the cell model inside of that feature model
61
+ """
62
+ @model = @model.tests.first.steps.first.block.rows.first.cells.first
63
+ """
64
+ When the cell's source column is requested
65
+ """
66
+ @model.source_column
67
+ """
68
+ Then the model returns "9"
@@ -40,3 +40,23 @@ Feature: Comment modeling
40
40
  @model.source_line
41
41
  """
42
42
  Then the model returns "1"
43
+
44
+ Scenario: Modeling a comment's source column
45
+ Given a feature file with the following gherkin:
46
+ """
47
+ # a comment
48
+ Feature:
49
+ """
50
+ And a feature file model based on that file
51
+ """
52
+ @model = CukeModeler::FeatureFile.new(<file_path>)
53
+ """
54
+ And the comment model of that feature file model
55
+ """
56
+ @model = @model.comments.first
57
+ """
58
+ When the comment's source column is requested
59
+ """
60
+ @model.source_column
61
+ """
62
+ Then the model returns "1"
@@ -57,3 +57,29 @@ Feature: Doc string modeling
57
57
  @model.source_line
58
58
  """
59
59
  Then the model returns "5"
60
+
61
+
62
+ Scenario: Modeling a doc string's source column
63
+ Given the following gherkin:
64
+ """
65
+ Feature:
66
+
67
+ Scenario:
68
+ * a step
69
+ \"\"\"
70
+ foo
71
+ \"\"\"
72
+ """
73
+ And a feature model based on that gherkin
74
+ """
75
+ @model = CukeModeler::Feature.new(<source_text>)
76
+ """
77
+ And the doc string model inside of that feature model
78
+ """
79
+ @model = @model.tests.first.steps.first.block
80
+ """
81
+ When the doc string's source column is requested
82
+ """
83
+ @model.source_column
84
+ """
85
+ Then the model returns "7"
@@ -128,3 +128,28 @@ Feature: Example modeling
128
128
  @model.source_line
129
129
  """
130
130
  Then the model returns "5"
131
+
132
+ Scenario: Modeling an example's source column
133
+ Given the following gherkin:
134
+ """
135
+ Feature:
136
+
137
+ Scenario Outline:
138
+ * a step
139
+ Examples:
140
+ | param |
141
+ | value |
142
+ """
143
+ And a feature model based on that gherkin
144
+ """
145
+ @model = CukeModeler::Feature.new(<source_text>)
146
+ """
147
+ And the example model inside of that feature model
148
+ """
149
+ @model = @model.tests.first.examples.first
150
+ """
151
+ When the example's source column is requested
152
+ """
153
+ @model.source_column
154
+ """
155
+ Then the model returns "3"
@@ -132,3 +132,10 @@ that feature.
132
132
  @model.source_line
133
133
  """
134
134
  Then the model returns "2"
135
+
136
+ Scenario: Modeling a feature's source column
137
+ When the feature's source column is requested
138
+ """
139
+ @model.source_column
140
+ """
141
+ Then the model returns "1"
@@ -124,7 +124,7 @@ Feature: Outline modeling
124
124
  | @outline_tag_1 |
125
125
  | @outline_tag_2 |
126
126
 
127
- Scenario: Modeling a outline's source line
127
+ Scenario: Modeling an outline's source line
128
128
  Given the following gherkin:
129
129
  """
130
130
  Feature:
@@ -148,3 +148,28 @@ Feature: Outline modeling
148
148
  @model.source_line
149
149
  """
150
150
  Then the model returns "3"
151
+
152
+ Scenario: Modeling an outline's source column
153
+ Given the following gherkin:
154
+ """
155
+ Feature:
156
+
157
+ Scenario Outline:
158
+ * a step
159
+ Examples:
160
+ | param |
161
+ | value |
162
+ """
163
+ And a feature model based on that gherkin
164
+ """
165
+ @model = CukeModeler::Feature.new(<source_text>)
166
+ """
167
+ And the outline model of that feature model
168
+ """
169
+ @model = @model.outlines.first
170
+ """
171
+ When the outline's source column is requested
172
+ """
173
+ @model.source_column
174
+ """
175
+ Then the model returns "3"
@@ -45,3 +45,26 @@ Feature: Row modeling
45
45
  @model.source_line
46
46
  """
47
47
  Then the model returns "5"
48
+
49
+ Scenario: Modeling a row's source column
50
+ Given the following gherkin:
51
+ """
52
+ Feature:
53
+
54
+ Scenario:
55
+ * a step
56
+ | foo |
57
+ """
58
+ And a feature model based on that gherkin
59
+ """
60
+ @model = CukeModeler::Feature.new(<source_text>)
61
+ """
62
+ And the row model inside of that feature model
63
+ """
64
+ @model = @model.tests.first.steps.first.block.rows.first
65
+ """
66
+ When the rows's source column is requested
67
+ """
68
+ @model.source_column
69
+ """
70
+ Then the model returns "7"
@@ -148,3 +148,24 @@ in that rule.
148
148
  @model.source_line
149
149
  """
150
150
  Then the model returns "3"
151
+
152
+ Scenario: Modeling a rule's source column
153
+ Given the following gherkin:
154
+ """
155
+ Feature:
156
+
157
+ Rule:
158
+ """
159
+ And a feature model based on that gherkin
160
+ """
161
+ @model = CukeModeler::Feature.new(<source_text>)
162
+ """
163
+ And the rule model of that feature model
164
+ """
165
+ @model = @model.rules.first
166
+ """
167
+ When the rule's source column is requested
168
+ """
169
+ @model.source_column
170
+ """
171
+ Then the model returns "3"
@@ -122,3 +122,25 @@ Feature: Scenario modeling
122
122
  @model.source_line
123
123
  """
124
124
  Then the model returns "3"
125
+
126
+ Scenario: Modeling a scenario's source column
127
+ Given the following gherkin:
128
+ """
129
+ Feature:
130
+
131
+ Scenario:
132
+ * a step
133
+ """
134
+ And a feature model based on that gherkin
135
+ """
136
+ @model = CukeModeler::Feature.new(<source_text>)
137
+ """
138
+ And the scenario model of that feature model
139
+ """
140
+ @model = @model.scenarios.first
141
+ """
142
+ When the scenario's source column is requested
143
+ """
144
+ @model.source_column
145
+ """
146
+ Then the model returns "3"
@@ -50,6 +50,28 @@ Feature: Step modeling
50
50
  """
51
51
  Then the model returns "4"
52
52
 
53
+ Scenario: Modeling a step's source column
54
+ Given the following gherkin:
55
+ """
56
+ Feature:
57
+
58
+ Scenario:
59
+ * a step
60
+ """
61
+ And a feature model based on that gherkin
62
+ """
63
+ @model = CukeModeler::Feature.new(<source_text>)
64
+ """
65
+ And the step model inside of that feature model
66
+ """
67
+ @model = @model.tests.first.steps.first
68
+ """
69
+ When the step's source column is requested
70
+ """
71
+ @model.source_column
72
+ """
73
+ Then the model returns "5"
74
+
53
75
  Scenario: Modeling a step's table
54
76
  Given a step model based on the following gherkin:
55
77
  """
@@ -47,3 +47,27 @@ Feature: Table modeling
47
47
  @model.source_line
48
48
  """
49
49
  Then the model returns "5"
50
+
51
+ Scenario: Modeling a table's source column
52
+ Given the following gherkin:
53
+ """
54
+ Feature:
55
+
56
+ Scenario:
57
+ * a step
58
+ | value 1 |
59
+ | value 2 |
60
+ """
61
+ And a feature model based on that gherkin
62
+ """
63
+ @model = CukeModeler::Feature.new(<source_text>)
64
+ """
65
+ And the table model inside of that feature model
66
+ """
67
+ @model = @model.tests.first.steps.first.block
68
+ """
69
+ When the table's source column is requested
70
+ """
71
+ @model.source_column
72
+ """
73
+ Then the model returns "7"
@@ -40,3 +40,23 @@ Feature: Tag modeling
40
40
  @model.source_line
41
41
  """
42
42
  Then the model returns "1"
43
+
44
+ Scenario: Modeling a tag's source column
45
+ Given the following gherkin:
46
+ """
47
+ @a_tag
48
+ Feature:
49
+ """
50
+ And a feature model based on that gherkin
51
+ """
52
+ @model = CukeModeler::Feature.new(<source_text>)
53
+ """
54
+ And the tag model of that feature model
55
+ """
56
+ @model = @model.tags.first
57
+ """
58
+ When the tag's source column is requested
59
+ """
60
+ @model.source_column
61
+ """
62
+ Then the model returns "1"