Class: CukeModeler::Feature
- Includes:
- Described, Named, Parsed, Sourceable, Taggable
- Defined in:
- lib/cuke_modeler/models/feature.rb
Overview
A class modeling a feature in a Cucumber suite.
Instance Attribute Summary collapse
-
#background ⇒ Object
The Background object contained by the Feature.
-
#keyword ⇒ Object
The keyword for the feature.
-
#language ⇒ Object
The language for the feature.
-
#rules ⇒ Object
The Rule objects contained by the Feature.
-
#tests ⇒ Object
The Scenario and Outline objects contained by the Feature.
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 feature contains a background, false otherwise.
-
#children ⇒ Array<Rule, Background, Scenario, Outline, Tag>
Returns the model objects that are children of this model.
-
#initialize(source_text = nil) ⇒ Feature
constructor
Creates a new Feature 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 feature.
-
#scenarios ⇒ Array<Scenario>
Returns the scenario models contained in the feature.
-
#test_case_count ⇒ Integer
deprecated
Deprecated.
See CHANGELOG
-
#to_s ⇒ String
Returns a string representation of this model.
Methods included from Taggable
Methods included from Containing
#each, #each_descendant, #each_model
Methods included from Nested
Constructor Details
#initialize(source_text = nil) ⇒ Feature
Creates a new Feature object and, if source_text is provided, populates the object.
39 40 41 42 43 44 45 |
# File 'lib/cuke_modeler/models/feature.rb', line 39 def initialize(source_text = nil) = [] @rules = [] @tests = [] super end |
Instance Attribute Details
#background ⇒ Object
The Background object contained by the Feature
20 21 22 |
# File 'lib/cuke_modeler/models/feature.rb', line 20 def background @background end |
#keyword ⇒ Object
The keyword for the feature
17 18 19 |
# File 'lib/cuke_modeler/models/feature.rb', line 17 def keyword @keyword end |
#language ⇒ Object
The language for the feature
14 15 16 |
# File 'lib/cuke_modeler/models/feature.rb', line 14 def language @language end |
#rules ⇒ Object
The Rule objects contained by the Feature
23 24 25 |
# File 'lib/cuke_modeler/models/feature.rb', line 23 def rules @rules end |
#tests ⇒ Object
The Scenario and Outline objects contained by the Feature
26 27 28 |
# File 'lib/cuke_modeler/models/feature.rb', line 26 def tests @tests end |
Instance Method Details
#background? ⇒ Boolean Also known as: has_background?
Returns true if the feature contains a background, false otherwise.
53 54 55 |
# File 'lib/cuke_modeler/models/feature.rb', line 53 def background? !@background.nil? end |
#children ⇒ Array<Rule, Background, Scenario, Outline, Tag>
Returns the model objects that are children of this model. For a Feature model, these would be any associated Rule, Background, Scenario, Outline, or Tag models.
107 108 109 110 111 112 |
# File 'lib/cuke_modeler/models/feature.rb', line 107 def children models = rules + 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 Feature model, this will be the name of the feature. If verbose is true, provides default Ruby inspection behavior instead.
152 153 154 155 156 |
# File 'lib/cuke_modeler/models/feature.rb', line 152 def inspect(verbose: false) return super if verbose "#{super.chop} @name: #{name.inspect}>" end |
#outlines ⇒ Array<Outline>
Returns the outline models contained in the feature.
75 76 77 |
# File 'lib/cuke_modeler/models/feature.rb', line 75 def outlines @tests.select { |test| test.is_a? Outline } end |
#scenarios ⇒ Array<Scenario>
Returns the scenario models contained in the feature.
65 66 67 |
# File 'lib/cuke_modeler/models/feature.rb', line 65 def scenarios @tests.select { |test| test.is_a? Scenario } end |
#test_case_count ⇒ Integer
See CHANGELOG
Returns the number of test cases contained in the feature. A test case is a single set of test values, such as an individual scenario or one example row of an outline.
91 92 93 94 95 96 97 |
# File 'lib/cuke_modeler/models/feature.rb', line 91 def test_case_count scenarios.count + outlines.reduce(0) do |outline_sum, outline| outline_sum + outline.examples.reduce(0) do |example_sum, example| example_sum + example.argument_rows.count end end end |
#to_s ⇒ String
Returns a string representation of this model. For a Feature model, this will be Gherkin text that is equivalent to the feature being modeled.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/cuke_modeler/models/feature.rb', line 124 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 << "\n\n#{rules_output_string}" unless rules.empty? text end |