Class: CukeModeler::Rule
- 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 Taggable
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 ⇒ Array<Background, Scenario, Outline, Tag>
Returns the model objects that are children of this model.
-
#initialize(source_text = nil) ⇒ Rule
constructor
Creates a new Rule object and, if source_text is provided, populates the object.
-
#inspect(verbose: false) ⇒ String
See ‘Object#inspect`.
-
#outlines ⇒ Array<Outline>
Returns the outline models contained in the rule.
-
#scenarios ⇒ Array<Scenario>
Returns the scenario models contained in the rule.
-
#to_s ⇒ String
Returns a string representation of this model.
Methods included from Taggable
Methods included from Parsing
Methods included from Containing
#each, #each_descendant, #each_model
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.
34 35 36 37 38 39 |
# File 'lib/cuke_modeler/models/rule.rb', line 34 def initialize(source_text = nil) @tags = [] @tests = [] super 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.
47 48 49 |
# File 'lib/cuke_modeler/models/rule.rb', line 47 def background? !@background.nil? end |
#children ⇒ Array<Background, Scenario, Outline, Tag>
Returns the model objects that are children of this model. For a Rule model, these would be any associated Background, Scenario, Outline, or Tag models.
81 82 83 84 85 86 |
# File 'lib/cuke_modeler/models/rule.rb', line 81 def children models = tests + models << background if background models end |
#inspect(verbose: false) ⇒ String
See ‘Object#inspect`. Returns some basic information about the object, including its class, object ID, and its most meaningful attribute. For a Rule model, this will be the name of the rule. If verbose is true, provides default Ruby inspection behavior instead.
120 121 122 123 124 |
# File 'lib/cuke_modeler/models/rule.rb', line 120 def inspect(verbose: false) return super if verbose "#{super.chop} @name: #{@name.inspect}>" end |
#outlines ⇒ Array<Outline>
Returns the outline models contained in the rule.
69 70 71 |
# File 'lib/cuke_modeler/models/rule.rb', line 69 def outlines @tests.select { |test| test.is_a? Outline } end |
#scenarios ⇒ Array<Scenario>
Returns the scenario models contained in the rule.
59 60 61 |
# File 'lib/cuke_modeler/models/rule.rb', line 59 def scenarios @tests.select { |test| test.is_a? Scenario } end |
#to_s ⇒ String
Returns a string representation of this model. For a Rule model, this will be Gherkin text that is equivalent to the rule being modeled.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/cuke_modeler/models/rule.rb', line 95 def to_s text = '' text << "#{tag_output_string}\n" unless .empty? 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 |