cuke_modeler 3.19.0 → 3.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -1
  3. data/README.md +5 -6
  4. data/cuke_modeler.gemspec +5 -3
  5. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +5 -5
  6. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +5 -5
  7. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +5 -5
  8. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +5 -5
  9. data/lib/cuke_modeler/adapters/gherkin_14_adapter.rb +5 -5
  10. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +5 -5
  11. data/lib/cuke_modeler/adapters/gherkin_16_adapter.rb +5 -5
  12. data/lib/cuke_modeler/adapters/gherkin_17_adapter.rb +5 -5
  13. data/lib/cuke_modeler/adapters/gherkin_18_adapter.rb +5 -2
  14. data/lib/cuke_modeler/adapters/gherkin_19_adapter.rb +5 -2
  15. data/lib/cuke_modeler/adapters/gherkin_20_adapter.rb +5 -2
  16. data/lib/cuke_modeler/adapters/gherkin_21_adapter.rb +5 -5
  17. data/lib/cuke_modeler/adapters/gherkin_22_adapter.rb +5 -5
  18. data/lib/cuke_modeler/adapters/gherkin_23_adapter.rb +5 -5
  19. data/lib/cuke_modeler/adapters/gherkin_24_adapter.rb +5 -5
  20. data/lib/cuke_modeler/adapters/gherkin_25_adapter.rb +5 -5
  21. data/lib/cuke_modeler/adapters/gherkin_26_adapter.rb +5 -5
  22. data/lib/cuke_modeler/adapters/gherkin_27_adapter.rb +13 -0
  23. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +5 -2
  24. data/lib/cuke_modeler/adapters/gherkin_base_adapter.rb +5 -2
  25. data/lib/cuke_modeler/containing.rb +43 -210
  26. data/lib/cuke_modeler/described.rb +8 -4
  27. data/lib/cuke_modeler/models/background.rb +61 -9
  28. data/lib/cuke_modeler/models/cell.rb +44 -7
  29. data/lib/cuke_modeler/models/comment.rb +43 -7
  30. data/lib/cuke_modeler/models/directory.rb +66 -8
  31. data/lib/cuke_modeler/models/doc_string.rb +49 -7
  32. data/lib/cuke_modeler/models/example.rb +103 -17
  33. data/lib/cuke_modeler/models/feature.rb +81 -10
  34. data/lib/cuke_modeler/models/feature_file.rb +64 -10
  35. data/lib/cuke_modeler/models/model.rb +57 -6
  36. data/lib/cuke_modeler/models/outline.rb +67 -9
  37. data/lib/cuke_modeler/models/row.rb +55 -8
  38. data/lib/cuke_modeler/models/rule.rb +67 -8
  39. data/lib/cuke_modeler/models/scenario.rb +59 -9
  40. data/lib/cuke_modeler/models/step.rb +69 -10
  41. data/lib/cuke_modeler/models/table.rb +55 -8
  42. data/lib/cuke_modeler/models/tag.rb +38 -13
  43. data/lib/cuke_modeler/named.rb +7 -4
  44. data/lib/cuke_modeler/nested.rb +19 -4
  45. data/lib/cuke_modeler/parsed.rb +10 -5
  46. data/lib/cuke_modeler/parsing.rb +28 -16
  47. data/lib/cuke_modeler/sourceable.rb +11 -5
  48. data/lib/cuke_modeler/stepped.rb +7 -5
  49. data/lib/cuke_modeler/taggable.rb +22 -4
  50. data/lib/cuke_modeler/version.rb +1 -1
  51. data/testing/cucumber/features/modeling/background_output.feature +19 -5
  52. data/testing/cucumber/features/modeling/base_model.feature +3 -0
  53. data/testing/cucumber/features/modeling/cell_output.feature +18 -4
  54. data/testing/cucumber/features/modeling/comment_output.feature +19 -5
  55. data/testing/cucumber/features/modeling/directory_output.feature +21 -4
  56. data/testing/cucumber/features/modeling/doc_string_output.feature +19 -5
  57. data/testing/cucumber/features/modeling/example_output.feature +21 -7
  58. data/testing/cucumber/features/modeling/feature_file_output.feature +21 -4
  59. data/testing/cucumber/features/modeling/feature_output.feature +20 -6
  60. data/testing/cucumber/features/modeling/model_output.feature +53 -5
  61. data/testing/cucumber/features/modeling/outline_output.feature +19 -5
  62. data/testing/cucumber/features/modeling/row_output.feature +19 -5
  63. data/testing/cucumber/features/modeling/rule_output.feature +27 -6
  64. data/testing/cucumber/features/modeling/scenario_output.feature +19 -5
  65. data/testing/cucumber/features/modeling/step_output.feature +19 -5
  66. data/testing/cucumber/features/modeling/table_output.feature +18 -4
  67. data/testing/cucumber/features/modeling/tag_output.feature +19 -5
  68. metadata +8 -6
@@ -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,29 +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
 
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
+
35
86
  end
36
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
 
@@ -66,11 +88,30 @@ module CukeModeler
66
88
 
67
89
  # rubocop:enable Metrics/AbcSize
68
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(verbose: verbose) if verbose
106
+
107
+ "#{super.chop} @name: #{name.inspect}>"
108
+ end
109
+
69
110
 
70
111
  private
71
112
 
72
113
 
73
- def parse_source(source_text)
114
+ def process_source(source_text)
74
115
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
75
116
  source_text = base_file_string + source_text
76
117
 
@@ -79,6 +120,23 @@ module CukeModeler
79
120
  parsed_file['feature']['elements'].first
80
121
  end
81
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
+
82
140
  def examples_output_string
83
141
  examples.empty? ? '' : examples.join("\n\n")
84
142
  end
@@ -13,35 +13,70 @@ 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
 
37
51
  "| #{text_cells.join(' | ')} |"
38
52
  end
39
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(verbose: verbose) if verbose
69
+
70
+ cell_output = @cells&.collect(&:value)
71
+
72
+ "#{super.chop} @cells: #{cell_output.inspect}>"
73
+ end
74
+
40
75
 
41
76
  private
42
77
 
43
78
 
44
- def parse_source(source_text)
79
+ def process_source(source_text)
45
80
  base_file_string = "# language: #{Parsing.dialect}
46
81
  #{dialect_feature_keyword}: Fake feature to parse
47
82
  #{dialect_scenario_keyword}:
@@ -53,5 +88,17 @@ module CukeModeler
53
88
  parsed_file['feature']['elements'].first['steps'].first['table']['rows'].first
54
89
  end
55
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
+
56
103
  end
57
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
 
@@ -74,11 +104,30 @@ module CukeModeler
74
104
  text
75
105
  end
76
106
 
107
+ # See `Object#inspect`. Returns some basic information about the
108
+ # object, including its class, object ID, and its most meaningful
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
120
+ def inspect(verbose: false)
121
+ return super(verbose: verbose) if verbose
122
+
123
+ "#{super.chop} @name: #{@name.inspect}>"
124
+ end
125
+
77
126
 
78
127
  private
79
128
 
80
129
 
81
- def parse_source(source_text)
130
+ def process_source(source_text)
82
131
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
83
132
  source_text = base_file_string + source_text
84
133
 
@@ -87,6 +136,16 @@ module CukeModeler
87
136
  parsed_file['feature']['elements'].first
88
137
  end
89
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
+
90
149
  def background_output_string
91
150
  test_output_string(background)
92
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
 
@@ -61,11 +82,30 @@ module CukeModeler
61
82
 
62
83
  # rubocop:enable Metrics/AbcSize
63
84
 
85
+ # See `Object#inspect`. Returns some basic information about the
86
+ # object, including its class, object ID, and its most meaningful
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
98
+ def inspect(verbose: false)
99
+ return super(verbose: verbose) if verbose
100
+
101
+ "#{super.chop} @name: #{name.inspect}>"
102
+ end
103
+
64
104
 
65
105
  private
66
106
 
67
107
 
68
- def parse_source(source_text)
108
+ def process_source(source_text)
69
109
  base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
70
110
  source_text = base_file_string + source_text
71
111
 
@@ -74,5 +114,15 @@ module CukeModeler
74
114
  parsed_file['feature']['elements'].first
75
115
  end
76
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
+
77
127
  end
78
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
@@ -53,11 +73,30 @@ module CukeModeler
53
73
  text
54
74
  end
55
75
 
76
+ # See `Object#inspect`. Returns some basic information about the
77
+ # object, including its class, object ID, and its most meaningful
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
89
+ def inspect(verbose: false)
90
+ return super(verbose: verbose) if verbose
91
+
92
+ "#{super.chop} @text: #{@text.inspect}>"
93
+ end
94
+
56
95
 
57
96
  private
58
97
 
59
98
 
60
- def parse_source(source_text)
99
+ def process_source(source_text)
61
100
  base_file_string = "# language: #{Parsing.dialect}
62
101
  #{dialect_feature_keyword}: Fake feature to parse
63
102
  #{dialect_scenario_keyword}:\n"
@@ -68,6 +107,26 @@ module CukeModeler
68
107
  parsed_file['feature']['elements'].first['steps'].first
69
108
  end
70
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
+
71
130
  def text_matches?(other_step)
72
131
  text == other_step.text
73
132
  end