cuke_modeler 3.20.0 → 3.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/README.md +5 -6
  4. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +5 -5
  5. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +5 -5
  6. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +5 -5
  7. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +5 -5
  8. data/lib/cuke_modeler/adapters/gherkin_14_adapter.rb +5 -5
  9. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +5 -5
  10. data/lib/cuke_modeler/adapters/gherkin_16_adapter.rb +5 -5
  11. data/lib/cuke_modeler/adapters/gherkin_17_adapter.rb +5 -5
  12. data/lib/cuke_modeler/adapters/gherkin_18_adapter.rb +5 -2
  13. data/lib/cuke_modeler/adapters/gherkin_19_adapter.rb +5 -2
  14. data/lib/cuke_modeler/adapters/gherkin_20_adapter.rb +5 -2
  15. data/lib/cuke_modeler/adapters/gherkin_21_adapter.rb +5 -5
  16. data/lib/cuke_modeler/adapters/gherkin_22_adapter.rb +5 -5
  17. data/lib/cuke_modeler/adapters/gherkin_23_adapter.rb +5 -5
  18. data/lib/cuke_modeler/adapters/gherkin_24_adapter.rb +5 -5
  19. data/lib/cuke_modeler/adapters/gherkin_25_adapter.rb +5 -5
  20. data/lib/cuke_modeler/adapters/gherkin_26_adapter.rb +5 -5
  21. data/lib/cuke_modeler/adapters/gherkin_27_adapter.rb +5 -5
  22. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +5 -2
  23. data/lib/cuke_modeler/adapters/gherkin_base_adapter.rb +5 -2
  24. data/lib/cuke_modeler/containing.rb +43 -210
  25. data/lib/cuke_modeler/described.rb +8 -4
  26. data/lib/cuke_modeler/models/background.rb +53 -11
  27. data/lib/cuke_modeler/models/cell.rb +36 -8
  28. data/lib/cuke_modeler/models/comment.rb +35 -8
  29. data/lib/cuke_modeler/models/directory.rb +58 -10
  30. data/lib/cuke_modeler/models/doc_string.rb +41 -9
  31. data/lib/cuke_modeler/models/example.rb +94 -17
  32. data/lib/cuke_modeler/models/feature.rb +73 -11
  33. data/lib/cuke_modeler/models/feature_file.rb +56 -12
  34. data/lib/cuke_modeler/models/model.rb +50 -7
  35. data/lib/cuke_modeler/models/outline.rb +59 -10
  36. data/lib/cuke_modeler/models/row.rb +45 -9
  37. data/lib/cuke_modeler/models/rule.rb +59 -9
  38. data/lib/cuke_modeler/models/scenario.rb +51 -10
  39. data/lib/cuke_modeler/models/step.rb +61 -11
  40. data/lib/cuke_modeler/models/table.rb +45 -9
  41. data/lib/cuke_modeler/models/tag.rb +30 -14
  42. data/lib/cuke_modeler/named.rb +7 -4
  43. data/lib/cuke_modeler/nested.rb +19 -4
  44. data/lib/cuke_modeler/parsed.rb +10 -5
  45. data/lib/cuke_modeler/parsing.rb +25 -13
  46. data/lib/cuke_modeler/sourceable.rb +11 -5
  47. data/lib/cuke_modeler/stepped.rb +7 -5
  48. data/lib/cuke_modeler/taggable.rb +22 -4
  49. data/lib/cuke_modeler/version.rb +1 -1
  50. data/testing/cucumber/features/modeling/base_model.feature +3 -0
  51. metadata +3 -2
@@ -1,6 +1,6 @@
1
1
  module CukeModeler
2
2
 
3
- # A class modeling an element of a Cucumber suite.
3
+ # A class modeling an element of a Cucumber suite. All model classes should descend from this class.
4
4
  class Model
5
5
 
6
6
  include Nested
@@ -8,37 +8,80 @@ module CukeModeler
8
8
 
9
9
 
10
10
  # Creates a new Model object and, if *source_text* is provided,
11
- # populates the object.
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
12
21
  def initialize(source_text = nil)
13
22
  error_message = "Can only create models from Strings but was given a #{source_text.class}."
14
23
  raise(ArgumentError, error_message) if source_text && !source_text.is_a?(String)
15
24
 
16
- # This should be overridden by a child class
25
+ return unless source_text
26
+
27
+ source_data = process_source(source_text)
28
+ populate_model(source_data)
17
29
  end
18
30
 
19
31
  # It's a lazy implementation but it's mandatory for the class to define this method
20
32
  # rubocop:disable Lint/UselessMethodDefinition
21
33
 
22
- # Returns a string representation of this model.
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
23
41
  def to_s
24
- # This should be overridden by a child class
25
42
  super
26
43
  end
27
44
 
28
45
  # rubocop:enable Lint/UselessMethodDefinition
29
46
 
30
- # Returns the model objects that belong to this model.
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
31
53
  def children
32
54
  []
33
55
  end
34
56
 
35
57
  # See `Object#inspect`. Returns some basic information about the
36
- # object, including its class and object ID.
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
37
68
  def inspect(verbose: false)
38
69
  return super() if verbose
39
70
 
40
71
  "#<#{self.class.name}:#{object_id}>"
41
72
  end
42
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
+
43
86
  end
44
87
  end
@@ -21,27 +21,44 @@ module CukeModeler
21
21
 
22
22
  # Creates a new Outline object and, if *source_text* is provided, populates the
23
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
24
32
  def initialize(source_text = nil)
25
33
  @steps = []
26
34
  @tags = []
27
35
  @examples = []
28
36
 
29
37
  super(source_text)
30
-
31
- return unless source_text
32
-
33
- parsed_outline_data = parse_source(source_text)
34
- populate_outline(self, parsed_outline_data)
35
38
  end
36
39
 
37
- # Returns *true* if the two models have equivalent steps and *false* otherwise.
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
38
48
  def ==(other)
39
49
  return false unless other.respond_to?(:steps)
40
50
 
41
51
  steps == other.steps
42
52
  end
43
53
 
44
- # Returns the model objects that belong to this model.
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
45
62
  def children
46
63
  examples + steps + tags
47
64
  end
@@ -49,8 +66,13 @@ module CukeModeler
49
66
  # Building strings just isn't pretty
50
67
  # rubocop:disable Metrics/AbcSize
51
68
 
52
- # Returns a string representation of this model. For an outline model,
69
+ # Returns a string representation of this model. For an Outline model,
53
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
54
76
  def to_s
55
77
  text = ''
56
78
 
@@ -68,7 +90,17 @@ module CukeModeler
68
90
 
69
91
  # See `Object#inspect`. Returns some basic information about the
70
92
  # object, including its class, object ID, and its most meaningful
71
- # attribute. For an outline model, this will be the name of the outline.
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
72
104
  def inspect(verbose: false)
73
105
  return super(verbose: verbose) if verbose
74
106
 
@@ -79,7 +111,7 @@ module CukeModeler
79
111
  private
80
112
 
81
113
 
82
- def parse_source(source_text)
114
+ def process_source(source_text)
83
115
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
84
116
  source_text = base_file_string + source_text
85
117
 
@@ -88,6 +120,23 @@ module CukeModeler
88
120
  parsed_file['feature']['elements'].first
89
121
  end
90
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
+
91
140
  def examples_output_string
92
141
  examples.empty? ? '' : examples.join("\n\n")
93
142
  end
@@ -13,24 +13,38 @@ module CukeModeler
13
13
 
14
14
  # Creates a new Row object and, if *source_text* is provided, populates
15
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
16
24
  def initialize(source_text = nil)
17
25
  @cells = []
18
26
 
19
27
  super(source_text)
20
-
21
- return unless source_text
22
-
23
- parsed_row_data = parse_source(source_text)
24
- populate_row(self, parsed_row_data)
25
28
  end
26
29
 
27
- # Returns the model objects that belong to this model.
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
28
37
  def children
29
38
  @cells
30
39
  end
31
40
 
32
- # Returns a string representation of this model. For a row model,
41
+ # Returns a string representation of this model. For a Row model,
33
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
34
48
  def to_s
35
49
  text_cells = cells.map(&:to_s)
36
50
 
@@ -39,7 +53,17 @@ module CukeModeler
39
53
 
40
54
  # See `Object#inspect`. Returns some basic information about the
41
55
  # object, including its class, object ID, and its most meaningful
42
- # attribute. For a row model, this will be the cells of the row.
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
43
67
  def inspect(verbose: false)
44
68
  return super(verbose: verbose) if verbose
45
69
 
@@ -52,7 +76,7 @@ module CukeModeler
52
76
  private
53
77
 
54
78
 
55
- def parse_source(source_text)
79
+ def process_source(source_text)
56
80
  base_file_string = "# language: #{Parsing.dialect}
57
81
  #{dialect_feature_keyword}: Fake feature to parse
58
82
  #{dialect_scenario_keyword}:
@@ -64,5 +88,17 @@ module CukeModeler
64
88
  parsed_file['feature']['elements'].first['steps'].first['table']['rows'].first
65
89
  end
66
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
+
67
103
  end
68
104
  end
@@ -23,19 +23,27 @@ module CukeModeler
23
23
 
24
24
  # Creates a new Rule object and, if *source_text* is provided, populates the
25
25
  # object.
26
+ #
27
+ # @example
28
+ # Rule.new
29
+ # Rule.new("Rule:\nThis is a rule")
30
+ #
31
+ # @param source_text [String] The Gherkin text that will be used to populate the model
32
+ # @raise [ArgumentError] If *source_text* is not a String
33
+ # @return [Rule] A new Rule instance
26
34
  def initialize(source_text = nil)
27
35
  @tags = []
28
36
  @tests = []
29
37
 
30
38
  super(source_text)
31
-
32
- return unless source_text
33
-
34
- parsed_rule_data = parse_source(source_text)
35
- populate_rule(self, parsed_rule_data)
36
39
  end
37
40
 
38
41
  # Returns *true* if the rule contains a background, *false* otherwise.
42
+ #
43
+ # @example
44
+ # rule.background?
45
+ #
46
+ # @return [Boolean] Whether the rule contains a background
39
47
  def background?
40
48
  !@background.nil?
41
49
  end
@@ -43,16 +51,33 @@ module CukeModeler
43
51
  alias has_background? background?
44
52
 
45
53
  # Returns the scenario models contained in the rule.
54
+ #
55
+ # @example
56
+ # rule.scenarios
57
+ #
58
+ # @return [Array<Scenario>] Child Scenario models
46
59
  def scenarios
47
60
  @tests.select { |test| test.is_a? Scenario }
48
61
  end
49
62
 
50
63
  # Returns the outline models contained in the rule.
64
+ #
65
+ # @example
66
+ # rule.outlines
67
+ #
68
+ # @return [Array<Outline>] Child Outline models
51
69
  def outlines
52
70
  @tests.select { |test| test.is_a? Outline }
53
71
  end
54
72
 
55
- # Returns the model objects that belong to this model.
73
+ # Returns the model objects that are children of this model. For a
74
+ # Rule model, these would be any associated Background, Scenario,
75
+ # Outline, or Tag models.
76
+ #
77
+ # @example
78
+ # rule.children
79
+ #
80
+ # @return [Array<Background, Scenario, Outline, Tag>] A collection of child models
56
81
  def children
57
82
  models = tests + tags
58
83
  models << background if background
@@ -60,8 +85,13 @@ module CukeModeler
60
85
  models
61
86
  end
62
87
 
63
- # Returns a string representation of this model. For a rule model,
88
+ # Returns a string representation of this model. For a Rule model,
64
89
  # this will be Gherkin text that is equivalent to the rule being modeled.
90
+ #
91
+ # @example
92
+ # rule.to_s
93
+ #
94
+ # @return [String] A string representation of this model
65
95
  def to_s
66
96
  text = ''
67
97
 
@@ -76,7 +106,17 @@ module CukeModeler
76
106
 
77
107
  # See `Object#inspect`. Returns some basic information about the
78
108
  # object, including its class, object ID, and its most meaningful
79
- # attribute. For a rule model, this will be the name of the rule.
109
+ # attribute. For a Rule model, this will be the name of the rule.
110
+ # If *verbose* is true, provides default Ruby inspection behavior
111
+ # instead.
112
+ #
113
+ # @example
114
+ # rule.inspect
115
+ # rule.inspect(verbose: true)
116
+ #
117
+ # @param verbose [Boolean] Whether or not to return the full details of
118
+ # the object. Defaults to false.
119
+ # @return [String] A string representation of this model
80
120
  def inspect(verbose: false)
81
121
  return super(verbose: verbose) if verbose
82
122
 
@@ -87,7 +127,7 @@ module CukeModeler
87
127
  private
88
128
 
89
129
 
90
- def parse_source(source_text)
130
+ def process_source(source_text)
91
131
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
92
132
  source_text = base_file_string + source_text
93
133
 
@@ -96,6 +136,16 @@ module CukeModeler
96
136
  parsed_file['feature']['elements'].first
97
137
  end
98
138
 
139
+ def populate_model(parsed_rule_data)
140
+ populate_parsing_data(parsed_rule_data)
141
+ populate_source_location(parsed_rule_data)
142
+ populate_keyword(parsed_rule_data)
143
+ populate_name(parsed_rule_data)
144
+ populate_description(parsed_rule_data)
145
+ populate_tags(parsed_rule_data)
146
+ populate_children(parsed_rule_data)
147
+ end
148
+
99
149
  def background_output_string
100
150
  test_output_string(background)
101
151
  end
@@ -18,26 +18,42 @@ module CukeModeler
18
18
 
19
19
  # Creates a new Scenario object and, if *source_text* is provided, populates the
20
20
  # object.
21
+ #
22
+ # @example
23
+ # Scenario.new
24
+ # Scenario.new("Scenario:\n * a step")
25
+ #
26
+ # @param source_text [String] The Gherkin text that will be used to populate the model
27
+ # @raise [ArgumentError] If *source_text* is not a String
28
+ # @return [Scenario] A new Scenario instance
21
29
  def initialize(source_text = nil)
22
30
  @steps = []
23
31
  @tags = []
24
32
 
25
33
  super(source_text)
26
-
27
- return unless source_text
28
-
29
- parsed_scenario_data = parse_source(source_text)
30
- populate_scenario(self, parsed_scenario_data)
31
34
  end
32
35
 
33
- # Returns *true* if the two models have equivalent steps and *false* otherwise.
36
+ # Compares this model with another object. Returns *true* if the two objects
37
+ # have equivalent steps and *false* otherwise.
38
+ #
39
+ # @example
40
+ # scenario_1 == scenario_2
41
+ #
42
+ # @param other [Object] The object to compare this model with
43
+ # @return [Boolean] Whether the two objects are equivalent
34
44
  def ==(other)
35
45
  return false unless other.respond_to?(:steps)
36
46
 
37
47
  steps == other.steps
38
48
  end
39
49
 
40
- # Returns the model objects that belong to this model.
50
+ # Returns the model objects that are children of this model. For a
51
+ # Scenario model, these would be any associated Step or Tag models.
52
+ #
53
+ # @example
54
+ # scenario.children
55
+ #
56
+ # @return [Array<Step, Tag>] A collection of child models
41
57
  def children
42
58
  steps + tags
43
59
  end
@@ -45,8 +61,13 @@ module CukeModeler
45
61
  # Building strings just isn't pretty
46
62
  # rubocop:disable Metrics/AbcSize
47
63
 
48
- # Returns a string representation of this model. For a scenario model,
64
+ # Returns a string representation of this model. For a Scenario model,
49
65
  # this will be Gherkin text that is equivalent to the scenario being modeled.
66
+ #
67
+ # @example
68
+ # scenario.to_s
69
+ #
70
+ # @return [String] A string representation of this model
50
71
  def to_s
51
72
  text = ''
52
73
 
@@ -63,7 +84,17 @@ module CukeModeler
63
84
 
64
85
  # See `Object#inspect`. Returns some basic information about the
65
86
  # object, including its class, object ID, and its most meaningful
66
- # attribute. For a scenario model, this will be the name of the scenario.
87
+ # attribute. For a Scenario model, this will be the name of the
88
+ # scenario. If *verbose* is true, provides default Ruby inspection
89
+ # behavior instead.
90
+ #
91
+ # @example
92
+ # scenario.inspect
93
+ # scenario.inspect(verbose: true)
94
+ #
95
+ # @param verbose [Boolean] Whether or not to return the full details of
96
+ # the object. Defaults to false.
97
+ # @return [String] A string representation of this model
67
98
  def inspect(verbose: false)
68
99
  return super(verbose: verbose) if verbose
69
100
 
@@ -74,7 +105,7 @@ module CukeModeler
74
105
  private
75
106
 
76
107
 
77
- def parse_source(source_text)
108
+ def process_source(source_text)
78
109
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
79
110
  source_text = base_file_string + source_text
80
111
 
@@ -83,5 +114,15 @@ module CukeModeler
83
114
  parsed_file['feature']['elements'].first
84
115
  end
85
116
 
117
+ def populate_model(parsed_scenario_data)
118
+ populate_parsing_data(parsed_scenario_data)
119
+ populate_source_location(parsed_scenario_data)
120
+ populate_keyword(parsed_scenario_data)
121
+ populate_name(parsed_scenario_data)
122
+ populate_description(parsed_scenario_data)
123
+ populate_steps(parsed_scenario_data)
124
+ populate_tags(parsed_scenario_data)
125
+ end
126
+
86
127
  end
87
128
  end
@@ -20,17 +20,26 @@ module CukeModeler
20
20
 
21
21
  # Creates a new Step object and, if *source_text* is provided, populates the
22
22
  # object.
23
+ #
24
+ # @example
25
+ # Step.new
26
+ # Step.new("Given a step")
27
+ #
28
+ # @param source_text [String] The Gherkin text that will be used to populate the model
29
+ # @raise [ArgumentError] If *source_text* is not a String
30
+ # @return [Step] A new Step instance
23
31
  def initialize(source_text = nil)
24
32
  super(source_text)
25
-
26
- return unless source_text
27
-
28
- parsed_step_data = parse_source(source_text)
29
- populate_step(self, parsed_step_data)
30
33
  end
31
34
 
32
- # Returns *true* if the two steps have the same base text (i.e. minus any keyword,
33
- # table, or doc string and *false* otherwise.
35
+ # Compares this model with another object. Returns *true* if the two objects
36
+ # have the same base text, table, and doc string and *false* otherwise.
37
+ #
38
+ # @example
39
+ # step_1 == step_2
40
+ #
41
+ # @param other [Object] The object to compare this model with
42
+ # @return [Boolean] Whether the two objects are equivalent
34
43
  def ==(other)
35
44
  return false unless other.is_a?(CukeModeler::Step)
36
45
 
@@ -39,13 +48,24 @@ module CukeModeler
39
48
  doc_string_matches?(other)
40
49
  end
41
50
 
42
- # Returns the model objects that belong to this model.
51
+ # Returns the model objects that are children of this model. For a
52
+ # Step model, these would be any associated Table or DocString models.
53
+ #
54
+ # @example
55
+ # step.children
56
+ #
57
+ # @return [Array<Table, DocString>] A collection of child models
43
58
  def children
44
59
  block ? [block] : []
45
60
  end
46
61
 
47
- # Returns a string representation of this model. For a step model,
62
+ # Returns a string representation of this model. For a Step model,
48
63
  # this will be Gherkin text that is equivalent to the step being modeled.
64
+ #
65
+ # @example
66
+ # step.to_s
67
+ #
68
+ # @return [String] A string representation of this model
49
69
  def to_s
50
70
  text = "#{keyword} #{self.text}"
51
71
  text << "\n#{block.to_s.split("\n").collect { |line| " #{line}" }.join("\n")}" if block
@@ -55,7 +75,17 @@ module CukeModeler
55
75
 
56
76
  # See `Object#inspect`. Returns some basic information about the
57
77
  # object, including its class, object ID, and its most meaningful
58
- # attribute. For a step model, this will be the text of the step.
78
+ # attribute. For a Step model, this will be the text of the step.
79
+ # If *verbose* is true, provides default Ruby inspection behavior
80
+ # instead.
81
+ #
82
+ # @example
83
+ # step.inspect
84
+ # step.inspect(verbose: true)
85
+ #
86
+ # @param verbose [Boolean] Whether or not to return the full details of
87
+ # the object. Defaults to false.
88
+ # @return [String] A string representation of this model
59
89
  def inspect(verbose: false)
60
90
  return super(verbose: verbose) if verbose
61
91
 
@@ -66,7 +96,7 @@ module CukeModeler
66
96
  private
67
97
 
68
98
 
69
- def parse_source(source_text)
99
+ def process_source(source_text)
70
100
  base_file_string = "# language: #{Parsing.dialect}
71
101
  #{dialect_feature_keyword}: Fake feature to parse
72
102
  #{dialect_scenario_keyword}:\n"
@@ -77,6 +107,26 @@ module CukeModeler
77
107
  parsed_file['feature']['elements'].first['steps'].first
78
108
  end
79
109
 
110
+ def populate_model(parsed_step_data)
111
+ populate_text(parsed_step_data)
112
+ populate_block(parsed_step_data)
113
+ populate_keyword(parsed_step_data)
114
+ populate_source_location(parsed_step_data)
115
+ populate_parsing_data(parsed_step_data)
116
+ end
117
+
118
+ def populate_text(parsed_step_data)
119
+ @text = parsed_step_data['name']
120
+ end
121
+
122
+ def populate_block(parsed_step_data)
123
+ @block = if parsed_step_data['table']
124
+ build_child_model(Table, parsed_step_data['table'])
125
+ elsif parsed_step_data['doc_string']
126
+ build_child_model(DocString, parsed_step_data['doc_string'])
127
+ end
128
+ end
129
+
80
130
  def text_matches?(other_step)
81
131
  text == other_step.text
82
132
  end