cuke_modeler 3.27.0 → 3.28.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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +579 -572
  3. data/LICENSE.txt +22 -22
  4. data/README.md +135 -135
  5. data/cuke_modeler.gemspec +59 -59
  6. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +13 -13
  7. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +13 -13
  8. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +13 -13
  9. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +13 -13
  10. data/lib/cuke_modeler/adapters/gherkin_14_adapter.rb +13 -13
  11. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +13 -13
  12. data/lib/cuke_modeler/adapters/gherkin_16_adapter.rb +13 -13
  13. data/lib/cuke_modeler/adapters/gherkin_17_adapter.rb +13 -13
  14. data/lib/cuke_modeler/adapters/gherkin_18_adapter.rb +27 -27
  15. data/lib/cuke_modeler/adapters/gherkin_19_adapter.rb +64 -64
  16. data/lib/cuke_modeler/adapters/gherkin_20_adapter.rb +359 -359
  17. data/lib/cuke_modeler/adapters/gherkin_21_adapter.rb +13 -13
  18. data/lib/cuke_modeler/adapters/gherkin_22_adapter.rb +13 -13
  19. data/lib/cuke_modeler/adapters/gherkin_23_adapter.rb +13 -13
  20. data/lib/cuke_modeler/adapters/gherkin_24_adapter.rb +13 -13
  21. data/lib/cuke_modeler/adapters/gherkin_25_adapter.rb +13 -13
  22. data/lib/cuke_modeler/adapters/gherkin_26_adapter.rb +13 -13
  23. data/lib/cuke_modeler/adapters/gherkin_27_adapter.rb +13 -13
  24. data/lib/cuke_modeler/adapters/gherkin_28_adapter.rb +13 -13
  25. data/lib/cuke_modeler/adapters/gherkin_29_adapter.rb +13 -13
  26. data/lib/cuke_modeler/adapters/gherkin_30_adapter.rb +13 -13
  27. data/lib/cuke_modeler/adapters/gherkin_31_adapter.rb +13 -13
  28. data/lib/cuke_modeler/adapters/gherkin_32_adapter.rb +13 -13
  29. data/lib/cuke_modeler/adapters/gherkin_33_adapter.rb +13 -13
  30. data/lib/cuke_modeler/adapters/gherkin_34_adapter.rb +13 -13
  31. data/lib/cuke_modeler/adapters/gherkin_35_adapter.rb +13 -13
  32. data/lib/cuke_modeler/adapters/gherkin_36_adapter.rb +13 -13
  33. data/lib/cuke_modeler/adapters/gherkin_37_adapter.rb +13 -13
  34. data/lib/cuke_modeler/adapters/gherkin_38_adapter.rb +13 -0
  35. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +375 -375
  36. data/lib/cuke_modeler/adapters/gherkin_base_adapter.rb +17 -17
  37. data/lib/cuke_modeler/containing.rb +105 -105
  38. data/lib/cuke_modeler/described.rb +71 -71
  39. data/lib/cuke_modeler/models/background.rb +122 -122
  40. data/lib/cuke_modeler/models/cell.rb +88 -88
  41. data/lib/cuke_modeler/models/comment.rb +82 -82
  42. data/lib/cuke_modeler/models/directory.rb +143 -143
  43. data/lib/cuke_modeler/models/doc_string.rb +104 -104
  44. data/lib/cuke_modeler/models/example.rb +274 -274
  45. data/lib/cuke_modeler/models/feature.rb +200 -200
  46. data/lib/cuke_modeler/models/feature_file.rb +116 -116
  47. data/lib/cuke_modeler/models/model.rb +87 -87
  48. data/lib/cuke_modeler/models/outline.rb +145 -145
  49. data/lib/cuke_modeler/models/row.rb +104 -104
  50. data/lib/cuke_modeler/models/rule.rb +162 -162
  51. data/lib/cuke_modeler/models/scenario.rb +128 -128
  52. data/lib/cuke_modeler/models/step.rb +178 -178
  53. data/lib/cuke_modeler/models/table.rb +117 -117
  54. data/lib/cuke_modeler/models/tag.rb +75 -75
  55. data/lib/cuke_modeler/named.rb +26 -26
  56. data/lib/cuke_modeler/nested.rb +61 -61
  57. data/lib/cuke_modeler/parsed.rb +24 -24
  58. data/lib/cuke_modeler/parsing.rb +208 -208
  59. data/lib/cuke_modeler/sourceable.rb +29 -29
  60. data/lib/cuke_modeler/stepped.rb +34 -34
  61. data/lib/cuke_modeler/taggable.rb +57 -57
  62. data/lib/cuke_modeler/version.rb +4 -4
  63. data/lib/cuke_modeler.rb +32 -32
  64. data/testing/cucumber/features/analysis/step_comparison.feature +25 -25
  65. data/testing/cucumber/features/analysis/test_comparison.feature +35 -35
  66. data/testing/cucumber/features/modeling/background_modeling.feature +105 -105
  67. data/testing/cucumber/features/modeling/background_output.feature +60 -60
  68. data/testing/cucumber/features/modeling/cell_modeling.feature +68 -68
  69. data/testing/cucumber/features/modeling/cell_output.feature +36 -36
  70. data/testing/cucumber/features/modeling/comment_modeling.feature +62 -62
  71. data/testing/cucumber/features/modeling/comment_output.feature +40 -40
  72. data/testing/cucumber/features/modeling/directory_modeling.feature +62 -62
  73. data/testing/cucumber/features/modeling/directory_output.feature +33 -33
  74. data/testing/cucumber/features/modeling/doc_string_modeling.feature +85 -85
  75. data/testing/cucumber/features/modeling/doc_string_output.feature +50 -50
  76. data/testing/cucumber/features/modeling/example_modeling.feature +155 -155
  77. data/testing/cucumber/features/modeling/example_output.feature +57 -57
  78. data/testing/cucumber/features/modeling/feature_file_modeling.feature +49 -49
  79. data/testing/cucumber/features/modeling/feature_file_output.feature +33 -33
  80. data/testing/cucumber/features/modeling/feature_modeling.feature +149 -149
  81. data/testing/cucumber/features/modeling/feature_output.feature +144 -144
  82. data/testing/cucumber/features/modeling/model_output.feature +61 -61
  83. data/testing/cucumber/features/modeling/model_structure.feature +42 -42
  84. data/testing/cucumber/features/modeling/outline_modeling.feature +175 -175
  85. data/testing/cucumber/features/modeling/outline_output.feature +87 -87
  86. data/testing/cucumber/features/modeling/row_modeling.feature +70 -70
  87. data/testing/cucumber/features/modeling/row_output.feature +40 -40
  88. data/testing/cucumber/features/modeling/rule_modeling.feature +171 -171
  89. data/testing/cucumber/features/modeling/rule_output.feature +136 -136
  90. data/testing/cucumber/features/modeling/scenario_modeling.feature +146 -146
  91. data/testing/cucumber/features/modeling/scenario_output.feature +63 -63
  92. data/testing/cucumber/features/modeling/step_modeling.feature +105 -105
  93. data/testing/cucumber/features/modeling/step_output.feature +47 -47
  94. data/testing/cucumber/features/modeling/table_modeling.feature +73 -73
  95. data/testing/cucumber/features/modeling/table_output.feature +42 -42
  96. data/testing/cucumber/features/modeling/tag_modeling.feature +62 -62
  97. data/testing/cucumber/features/modeling/tag_output.feature +40 -40
  98. metadata +6 -8
@@ -1,87 +1,87 @@
1
- module CukeModeler
2
-
3
- # A class modeling an element of a Cucumber suite. All model classes should descend from this class.
4
- class Model
5
-
6
- include Nested
7
- include Containing
8
-
9
-
10
- # Creates a new Model object and, if *source_text* is provided,
11
- # populates the object. For the base model class, there is nothing
12
- # to populate.
13
- #
14
- # @example
15
- # Model.new
16
- # Model.new('some source text')
17
- #
18
- # @param source_text [String] The string that will be used to populate the model. Defaults to nil.
19
- # @raise [ArgumentError] If *source_text* is not a String
20
- # @return [Model] A new Model instance
21
- def initialize(source_text = nil)
22
- error_message = "Can only create models from Strings but was given a #{source_text.class}."
23
- raise(ArgumentError, error_message) if source_text && !source_text.is_a?(String)
24
-
25
- return unless source_text
26
-
27
- source_data = process_source(source_text)
28
- populate_model(source_data)
29
- end
30
-
31
- # It's a lazy implementation but it's mandatory for the class to define this method
32
- # rubocop:disable Lint/UselessMethodDefinition
33
-
34
- # Returns a string representation of this model. Because the base model class
35
- # doesn't represent anything specific, its string output is undefined.
36
- #
37
- # @example
38
- # model.to_s
39
- #
40
- # @return [String] A string representation of this model
41
- def to_s
42
- super
43
- end
44
-
45
- # rubocop:enable Lint/UselessMethodDefinition
46
-
47
- # Returns the model objects that are children of this model.
48
- #
49
- # @example
50
- # model.children
51
- #
52
- # @return [Array<Model>] A collection of child models
53
- def children
54
- []
55
- end
56
-
57
- # See `Object#inspect`. Returns some basic information about the
58
- # object, including its class and object ID. If *verbose* is true,
59
- # provides default Ruby inspection behavior instead.
60
- #
61
- # @example
62
- # model.inspect
63
- # model.inspect(verbose: true)
64
- #
65
- # @param verbose [Boolean] Whether or not to return the full details of
66
- # the object. Defaults to false.
67
- # @return [String] A string representation of this model
68
- def inspect(verbose: false)
69
- return super() if verbose
70
-
71
- "#<#{self.class.name}:#{object_id}>"
72
- end
73
-
74
-
75
- private
76
-
77
-
78
- def process_source(source_text)
79
- # No-op. Overridden by child classes.
80
- end
81
-
82
- def populate_model(model_data)
83
- # No-op. Overridden by child classes.
84
- end
85
-
86
- end
87
- end
1
+ module CukeModeler
2
+
3
+ # A class modeling an element of a Cucumber suite. All model classes should descend from this class.
4
+ class Model
5
+
6
+ include Nested
7
+ include Containing
8
+
9
+
10
+ # Creates a new Model object and, if *source_text* is provided,
11
+ # populates the object. For the base model class, there is nothing
12
+ # to populate.
13
+ #
14
+ # @example
15
+ # Model.new
16
+ # Model.new('some source text')
17
+ #
18
+ # @param source_text [String] The string that will be used to populate the model. Defaults to nil.
19
+ # @raise [ArgumentError] If *source_text* is not a String
20
+ # @return [Model] A new Model instance
21
+ def initialize(source_text = nil)
22
+ error_message = "Can only create models from Strings but was given a #{source_text.class}."
23
+ raise(ArgumentError, error_message) if source_text && !source_text.is_a?(String)
24
+
25
+ return unless source_text
26
+
27
+ source_data = process_source(source_text)
28
+ populate_model(source_data)
29
+ end
30
+
31
+ # It's a lazy implementation but it's mandatory for the class to define this method
32
+ # rubocop:disable Lint/UselessMethodDefinition
33
+
34
+ # Returns a string representation of this model. Because the base model class
35
+ # doesn't represent anything specific, its string output is undefined.
36
+ #
37
+ # @example
38
+ # model.to_s
39
+ #
40
+ # @return [String] A string representation of this model
41
+ def to_s
42
+ super
43
+ end
44
+
45
+ # rubocop:enable Lint/UselessMethodDefinition
46
+
47
+ # Returns the model objects that are children of this model.
48
+ #
49
+ # @example
50
+ # model.children
51
+ #
52
+ # @return [Array<Model>] A collection of child models
53
+ def children
54
+ []
55
+ end
56
+
57
+ # See `Object#inspect`. Returns some basic information about the
58
+ # object, including its class and object ID. If *verbose* is true,
59
+ # provides default Ruby inspection behavior instead.
60
+ #
61
+ # @example
62
+ # model.inspect
63
+ # model.inspect(verbose: true)
64
+ #
65
+ # @param verbose [Boolean] Whether or not to return the full details of
66
+ # the object. Defaults to false.
67
+ # @return [String] A string representation of this model
68
+ def inspect(verbose: false)
69
+ return super() if verbose
70
+
71
+ "#<#{self.class.name}:#{object_id}>"
72
+ end
73
+
74
+
75
+ private
76
+
77
+
78
+ def process_source(source_text)
79
+ # No-op. Overridden by child classes.
80
+ end
81
+
82
+ def populate_model(model_data)
83
+ # No-op. Overridden by child classes.
84
+ end
85
+
86
+ end
87
+ end
@@ -1,145 +1,145 @@
1
- module CukeModeler
2
-
3
- # A class modeling an individual outline in a Cucumber suite.
4
- class Outline < Model
5
-
6
- include Parsing
7
- include Parsed
8
- include Named
9
- include Described
10
- include Stepped
11
- include Sourceable
12
- include Taggable
13
-
14
-
15
- # The outline's keyword
16
- attr_accessor :keyword
17
-
18
- # The Example objects contained by the Outline
19
- attr_accessor :examples
20
-
21
-
22
- # Creates a new Outline object and, if *source_text* is provided, populates the
23
- # object.
24
- #
25
- # @example
26
- # Outline.new
27
- # Outline.new("Scenario Outline:\n * a step")
28
- #
29
- # @param source_text [String] The Gherkin text that will be used to populate the model
30
- # @raise [ArgumentError] If *source_text* is not a String
31
- # @return [Outline] A new Outline instance
32
- def initialize(source_text = nil)
33
- @steps = []
34
- @tags = []
35
- @examples = []
36
-
37
- super
38
- end
39
-
40
- # Compares this model with another object. Returns *true* if the two objects
41
- # have equivalent steps and *false* otherwise.
42
- #
43
- # @example
44
- # outline_1 == outline_2
45
- #
46
- # @param other [Object] The object to compare this model with
47
- # @return [Boolean] Whether the two objects are equivalent
48
- def ==(other)
49
- return false unless other.respond_to?(:steps)
50
-
51
- steps == other.steps
52
- end
53
-
54
- # Returns the model objects that are children of this model. For
55
- # an Outline model, these would be any associated Step, Tag, or
56
- # Example models.
57
- #
58
- # @example
59
- # outline.children
60
- #
61
- # @return [Array<Step, Tag, Example>] A collection of child models
62
- def children
63
- examples + steps + tags
64
- end
65
-
66
- # Building strings just isn't pretty
67
- # rubocop:disable Metrics/AbcSize
68
-
69
- # Returns a string representation of this model. For an Outline model,
70
- # this will be Gherkin text that is equivalent to the outline being modeled.
71
- #
72
- # @example
73
- # outline.to_s
74
- #
75
- # @return [String] A string representation of this model
76
- def to_s
77
- text = ''
78
-
79
- text << "#{tag_output_string}\n" unless tags.empty?
80
- text << "#{@keyword}:#{name_output_string}"
81
- text << "\n#{description_output_string}" unless no_description_to_output?
82
- text << "\n" unless steps.empty? || no_description_to_output?
83
- text << "\n#{steps_output_string}" unless steps.empty?
84
- text << "\n\n#{examples_output_string}" unless examples.empty?
85
-
86
- text
87
- end
88
-
89
- # rubocop:enable Metrics/AbcSize
90
-
91
- # See `Object#inspect`. Returns some basic information about the
92
- # object, including its class, object ID, and its most meaningful
93
- # attribute. For an Outline model, this will be the name of the
94
- # outline. If *verbose* is true, provides default Ruby inspection
95
- # behavior instead.
96
- #
97
- # @example
98
- # outline.inspect
99
- # outline.inspect(verbose: true)
100
- #
101
- # @param verbose [Boolean] Whether or not to return the full details of
102
- # the object. Defaults to false.
103
- # @return [String] A string representation of this model
104
- def inspect(verbose: false)
105
- return super if verbose
106
-
107
- "#{super.chop} @name: #{name.inspect}>"
108
- end
109
-
110
-
111
- private
112
-
113
-
114
- def process_source(source_text)
115
- base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
116
- source_text = base_file_string + source_text
117
-
118
- parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_outline.feature')
119
-
120
- parsed_file['feature']['elements'].first
121
- end
122
-
123
- def populate_model(parsed_outline_data)
124
- populate_parsing_data(parsed_outline_data)
125
- populate_source_location(parsed_outline_data)
126
- populate_keyword(parsed_outline_data)
127
- populate_name(parsed_outline_data)
128
- populate_description(parsed_outline_data)
129
- populate_steps(parsed_outline_data)
130
- populate_tags(parsed_outline_data)
131
- populate_outline_examples(parsed_outline_data['examples']) if parsed_outline_data['examples']
132
- end
133
-
134
- def populate_outline_examples(parsed_examples)
135
- parsed_examples.each do |example_data|
136
- @examples << build_child_model(Example, example_data)
137
- end
138
- end
139
-
140
- def examples_output_string
141
- examples.empty? ? '' : examples.join("\n\n")
142
- end
143
-
144
- end
145
- end
1
+ module CukeModeler
2
+
3
+ # A class modeling an individual outline in a Cucumber suite.
4
+ class Outline < Model
5
+
6
+ include Parsing
7
+ include Parsed
8
+ include Named
9
+ include Described
10
+ include Stepped
11
+ include Sourceable
12
+ include Taggable
13
+
14
+
15
+ # The outline's keyword
16
+ attr_accessor :keyword
17
+
18
+ # The Example objects contained by the Outline
19
+ attr_accessor :examples
20
+
21
+
22
+ # Creates a new Outline object and, if *source_text* is provided, populates the
23
+ # object.
24
+ #
25
+ # @example
26
+ # Outline.new
27
+ # Outline.new("Scenario Outline:\n * a step")
28
+ #
29
+ # @param source_text [String] The Gherkin text that will be used to populate the model
30
+ # @raise [ArgumentError] If *source_text* is not a String
31
+ # @return [Outline] A new Outline instance
32
+ def initialize(source_text = nil)
33
+ @steps = []
34
+ @tags = []
35
+ @examples = []
36
+
37
+ super
38
+ end
39
+
40
+ # Compares this model with another object. Returns *true* if the two objects
41
+ # have equivalent steps and *false* otherwise.
42
+ #
43
+ # @example
44
+ # outline_1 == outline_2
45
+ #
46
+ # @param other [Object] The object to compare this model with
47
+ # @return [Boolean] Whether the two objects are equivalent
48
+ def ==(other)
49
+ return false unless other.respond_to?(:steps)
50
+
51
+ steps == other.steps
52
+ end
53
+
54
+ # Returns the model objects that are children of this model. For
55
+ # an Outline model, these would be any associated Step, Tag, or
56
+ # Example models.
57
+ #
58
+ # @example
59
+ # outline.children
60
+ #
61
+ # @return [Array<Step, Tag, Example>] A collection of child models
62
+ def children
63
+ examples + steps + tags
64
+ end
65
+
66
+ # Building strings just isn't pretty
67
+ # rubocop:disable Metrics/AbcSize
68
+
69
+ # Returns a string representation of this model. For an Outline model,
70
+ # this will be Gherkin text that is equivalent to the outline being modeled.
71
+ #
72
+ # @example
73
+ # outline.to_s
74
+ #
75
+ # @return [String] A string representation of this model
76
+ def to_s
77
+ text = ''
78
+
79
+ text << "#{tag_output_string}\n" unless tags.empty?
80
+ text << "#{@keyword}:#{name_output_string}"
81
+ text << "\n#{description_output_string}" unless no_description_to_output?
82
+ text << "\n" unless steps.empty? || no_description_to_output?
83
+ text << "\n#{steps_output_string}" unless steps.empty?
84
+ text << "\n\n#{examples_output_string}" unless examples.empty?
85
+
86
+ text
87
+ end
88
+
89
+ # rubocop:enable Metrics/AbcSize
90
+
91
+ # See `Object#inspect`. Returns some basic information about the
92
+ # object, including its class, object ID, and its most meaningful
93
+ # attribute. For an Outline model, this will be the name of the
94
+ # outline. If *verbose* is true, provides default Ruby inspection
95
+ # behavior instead.
96
+ #
97
+ # @example
98
+ # outline.inspect
99
+ # outline.inspect(verbose: true)
100
+ #
101
+ # @param verbose [Boolean] Whether or not to return the full details of
102
+ # the object. Defaults to false.
103
+ # @return [String] A string representation of this model
104
+ def inspect(verbose: false)
105
+ return super if verbose
106
+
107
+ "#{super.chop} @name: #{name.inspect}>"
108
+ end
109
+
110
+
111
+ private
112
+
113
+
114
+ def process_source(source_text)
115
+ base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
116
+ source_text = base_file_string + source_text
117
+
118
+ parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_outline.feature')
119
+
120
+ parsed_file['feature']['elements'].first
121
+ end
122
+
123
+ def populate_model(parsed_outline_data)
124
+ populate_parsing_data(parsed_outline_data)
125
+ populate_source_location(parsed_outline_data)
126
+ populate_keyword(parsed_outline_data)
127
+ populate_name(parsed_outline_data)
128
+ populate_description(parsed_outline_data)
129
+ populate_steps(parsed_outline_data)
130
+ populate_tags(parsed_outline_data)
131
+ populate_outline_examples(parsed_outline_data['examples']) if parsed_outline_data['examples']
132
+ end
133
+
134
+ def populate_outline_examples(parsed_examples)
135
+ parsed_examples.each do |example_data|
136
+ @examples << build_child_model(Example, example_data)
137
+ end
138
+ end
139
+
140
+ def examples_output_string
141
+ examples.empty? ? '' : examples.join("\n\n")
142
+ end
143
+
144
+ end
145
+ end
@@ -1,104 +1,104 @@
1
- module CukeModeler
2
-
3
- # A class modeling a single row of a step table or example table.
4
- class Row < Model
5
-
6
- include Sourceable
7
- include Parsing
8
- include Parsed
9
-
10
- # The cell models that make up the row
11
- attr_accessor :cells
12
-
13
-
14
- # Creates a new Row object and, if *source_text* is provided, populates
15
- # the object.
16
- #
17
- # @example
18
- # Row.new
19
- # Row.new('|value_1|value_2|')
20
- #
21
- # @param source_text [String] The Gherkin text that will be used to populate the model
22
- # @raise [ArgumentError] If *source_text* is not a String
23
- # @return [Row] A new Row instance
24
- def initialize(source_text = nil)
25
- @cells = []
26
-
27
- super
28
- end
29
-
30
- # Returns the model objects that are children of this model. For a
31
- # Row model, these would be any associated Cell models.
32
- #
33
- # @example
34
- # row.children
35
- #
36
- # @return [Array<Cell>] A collection of child models
37
- def children
38
- @cells
39
- end
40
-
41
- # Returns a string representation of this model. For a Row model,
42
- # this will be Gherkin text that is equivalent to the row being modeled.
43
- #
44
- # @example
45
- # row.to_s
46
- #
47
- # @return [String] A string representation of this model
48
- def to_s
49
- text_cells = cells.map(&:to_s)
50
-
51
- "| #{text_cells.join(' | ')} |"
52
- end
53
-
54
- # See `Object#inspect`. Returns some basic information about the
55
- # object, including its class, object ID, and its most meaningful
56
- # attribute. For a Row model, this will be the cells of the row.
57
- # If *verbose* is true, provides default Ruby inspection behavior
58
- # instead.
59
- #
60
- # @example
61
- # row.inspect
62
- # row.inspect(verbose: true)
63
- #
64
- # @param verbose [Boolean] Whether or not to return the full details of
65
- # the object. Defaults to false.
66
- # @return [String] A string representation of this model
67
- def inspect(verbose: false)
68
- return super if verbose
69
-
70
- cell_output = @cells&.collect(&:value)
71
-
72
- "#{super.chop} @cells: #{cell_output.inspect}>"
73
- end
74
-
75
-
76
- private
77
-
78
-
79
- def process_source(source_text)
80
- base_file_string = "# language: #{Parsing.dialect}
81
- #{dialect_feature_keyword}: Fake feature to parse
82
- #{dialect_scenario_keyword}:
83
- #{dialect_step_keyword} fake step\n"
84
- source_text = base_file_string + source_text
85
-
86
- parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_row.feature')
87
-
88
- parsed_file['feature']['elements'].first['steps'].first['table']['rows'].first
89
- end
90
-
91
- def populate_model(parsed_row_data)
92
- populate_source_location(parsed_row_data)
93
- populate_row_cells(parsed_row_data)
94
- populate_parsing_data(parsed_row_data)
95
- end
96
-
97
- def populate_row_cells(parsed_row_data)
98
- parsed_row_data['cells'].each do |cell_data|
99
- @cells << build_child_model(Cell, cell_data)
100
- end
101
- end
102
-
103
- end
104
- end
1
+ module CukeModeler
2
+
3
+ # A class modeling a single row of a step table or example table.
4
+ class Row < Model
5
+
6
+ include Sourceable
7
+ include Parsing
8
+ include Parsed
9
+
10
+ # The cell models that make up the row
11
+ attr_accessor :cells
12
+
13
+
14
+ # Creates a new Row object and, if *source_text* is provided, populates
15
+ # the object.
16
+ #
17
+ # @example
18
+ # Row.new
19
+ # Row.new('|value_1|value_2|')
20
+ #
21
+ # @param source_text [String] The Gherkin text that will be used to populate the model
22
+ # @raise [ArgumentError] If *source_text* is not a String
23
+ # @return [Row] A new Row instance
24
+ def initialize(source_text = nil)
25
+ @cells = []
26
+
27
+ super
28
+ end
29
+
30
+ # Returns the model objects that are children of this model. For a
31
+ # Row model, these would be any associated Cell models.
32
+ #
33
+ # @example
34
+ # row.children
35
+ #
36
+ # @return [Array<Cell>] A collection of child models
37
+ def children
38
+ @cells
39
+ end
40
+
41
+ # Returns a string representation of this model. For a Row model,
42
+ # this will be Gherkin text that is equivalent to the row being modeled.
43
+ #
44
+ # @example
45
+ # row.to_s
46
+ #
47
+ # @return [String] A string representation of this model
48
+ def to_s
49
+ text_cells = cells.map(&:to_s)
50
+
51
+ "| #{text_cells.join(' | ')} |"
52
+ end
53
+
54
+ # See `Object#inspect`. Returns some basic information about the
55
+ # object, including its class, object ID, and its most meaningful
56
+ # attribute. For a Row model, this will be the cells of the row.
57
+ # If *verbose* is true, provides default Ruby inspection behavior
58
+ # instead.
59
+ #
60
+ # @example
61
+ # row.inspect
62
+ # row.inspect(verbose: true)
63
+ #
64
+ # @param verbose [Boolean] Whether or not to return the full details of
65
+ # the object. Defaults to false.
66
+ # @return [String] A string representation of this model
67
+ def inspect(verbose: false)
68
+ return super if verbose
69
+
70
+ cell_output = @cells&.collect(&:value)
71
+
72
+ "#{super.chop} @cells: #{cell_output.inspect}>"
73
+ end
74
+
75
+
76
+ private
77
+
78
+
79
+ def process_source(source_text)
80
+ base_file_string = "# language: #{Parsing.dialect}
81
+ #{dialect_feature_keyword}: Fake feature to parse
82
+ #{dialect_scenario_keyword}:
83
+ #{dialect_step_keyword} fake step\n"
84
+ source_text = base_file_string + source_text
85
+
86
+ parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_row.feature')
87
+
88
+ parsed_file['feature']['elements'].first['steps'].first['table']['rows'].first
89
+ end
90
+
91
+ def populate_model(parsed_row_data)
92
+ populate_source_location(parsed_row_data)
93
+ populate_row_cells(parsed_row_data)
94
+ populate_parsing_data(parsed_row_data)
95
+ end
96
+
97
+ def populate_row_cells(parsed_row_data)
98
+ parsed_row_data['cells'].each do |cell_data|
99
+ @cells << build_child_model(Cell, cell_data)
100
+ end
101
+ end
102
+
103
+ end
104
+ end