Class: CukeModeler::Rule
- Includes:
- Described, Named, Parsed, Parsing, Sourceable
- Defined in:
- lib/cuke_modeler/models/rule.rb
Overview
A class modeling a rule in a Cucumber suite.
Instance Attribute Summary collapse
-
#background ⇒ Object
The Background object contained by the Rule.
-
#keyword ⇒ Object
The keyword for the rule.
-
#tests ⇒ Object
The Scenario and Outline objects contained by the Rule.
Attributes included from Sourceable
Attributes included from Described
Attributes included from Named
Attributes included from Parsed
Attributes included from Nested
Instance Method Summary collapse
-
#background? ⇒ Boolean
(also: #has_background?)
Returns true if the rule contains a background, false otherwise.
-
#children ⇒ Object
Returns the model objects that belong to this model.
-
#initialize(source_text = nil) ⇒ Rule
constructor
Creates a new Rule object and, if source_text is provided, populates the object.
-
#outlines ⇒ Object
Returns the outline models contained in the rule.
-
#scenarios ⇒ Object
Returns the scenario models contained in the rule.
-
#to_s ⇒ Object
Returns a string representation of this model.
Methods included from Parsing
Methods included from Containing
Methods included from Nested
Constructor Details
#initialize(source_text = nil) ⇒ Rule
Creates a new Rule object and, if source_text is provided, populates the object.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cuke_modeler/models/rule.rb', line 26 def initialize(source_text = nil) @tests = [] super(source_text) return unless source_text parsed_rule_data = parse_source(source_text) populate_rule(self, parsed_rule_data) end |
Instance Attribute Details
#background ⇒ Object
The Background object contained by the Rule
18 19 20 |
# File 'lib/cuke_modeler/models/rule.rb', line 18 def background @background end |
#keyword ⇒ Object
The keyword for the rule
15 16 17 |
# File 'lib/cuke_modeler/models/rule.rb', line 15 def keyword @keyword end |
#tests ⇒ Object
The Scenario and Outline objects contained by the Rule
21 22 23 |
# File 'lib/cuke_modeler/models/rule.rb', line 21 def tests @tests end |
Instance Method Details
#background? ⇒ Boolean Also known as: has_background?
Returns true if the rule contains a background, false otherwise.
38 39 40 |
# File 'lib/cuke_modeler/models/rule.rb', line 38 def background? !@background.nil? end |
#children ⇒ Object
Returns the model objects that belong to this model.
55 56 57 58 59 60 |
# File 'lib/cuke_modeler/models/rule.rb', line 55 def children models = tests models << background if background models end |
#outlines ⇒ Object
Returns the outline models contained in the rule.
50 51 52 |
# File 'lib/cuke_modeler/models/rule.rb', line 50 def outlines @tests.select { |test| test.is_a? Outline } end |
#scenarios ⇒ Object
Returns the scenario models contained in the rule.
45 46 47 |
# File 'lib/cuke_modeler/models/rule.rb', line 45 def scenarios @tests.select { |test| test.is_a? Scenario } end |
#to_s ⇒ Object
Returns a string representation of this model. For a rule model, this will be Gherkin text that is equivalent to the rule being modeled.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cuke_modeler/models/rule.rb', line 64 def to_s text = '' text << "#{@keyword}:#{name_output_string}" text << "\n#{description_output_string}" unless no_description_to_output? text << "\n\n#{background_output_string}" if background text << "\n\n#{tests_output_string}" unless tests.empty? text end |