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.
-
#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 ⇒ Object
Returns the model objects that belong to this model.
-
#initialize(source_text = nil) ⇒ Feature
constructor
Creates a new Feature object and, if source_text is provided, populates the object.
-
#outlines ⇒ Object
Returns the outline models contained in the feature.
-
#scenarios ⇒ Object
Returns the scenario models contained in the feature.
-
#test_case_count ⇒ Object
TODO: Remove this method on next major version release DEPRECATED Returns the number of test cases contained in the feature.
-
#to_s ⇒ Object
Returns a string representation of this model.
Methods included from Taggable
Methods included from Containing
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.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cuke_modeler/models/feature.rb', line 29 def initialize(source_text = nil) = [] @rules = [] @tests = [] super(source_text) return unless source_text parsed_feature_data = parse_source(source_text) populate_feature(self, parsed_feature_data) end |
Instance Attribute Details
#background ⇒ Object
The Background object contained by the Feature
18 19 20 |
# File 'lib/cuke_modeler/models/feature.rb', line 18 def background @background end |
#keyword ⇒ Object
The keyword for the feature
15 16 17 |
# File 'lib/cuke_modeler/models/feature.rb', line 15 def keyword @keyword end |
#rules ⇒ Object
The Rule objects contained by the Feature
21 22 23 |
# File 'lib/cuke_modeler/models/feature.rb', line 21 def rules @rules end |
#tests ⇒ Object
The Scenario and Outline objects contained by the Feature
24 25 26 |
# File 'lib/cuke_modeler/models/feature.rb', line 24 def tests @tests end |
Instance Method Details
#background? ⇒ Boolean Also known as: has_background?
Returns true if the feature contains a background, false otherwise.
43 44 45 |
# File 'lib/cuke_modeler/models/feature.rb', line 43 def background? !@background.nil? end |
#children ⇒ Object
Returns the model objects that belong to this model.
73 74 75 76 77 78 |
# File 'lib/cuke_modeler/models/feature.rb', line 73 def children models = rules + tests + models << background if background models end |
#outlines ⇒ Object
Returns the outline models contained in the feature.
55 56 57 |
# File 'lib/cuke_modeler/models/feature.rb', line 55 def outlines @tests.select { |test| test.is_a? Outline } end |
#scenarios ⇒ Object
Returns the scenario models contained in the feature.
50 51 52 |
# File 'lib/cuke_modeler/models/feature.rb', line 50 def scenarios @tests.select { |test| test.is_a? Scenario } end |
#test_case_count ⇒ Object
TODO: Remove this method on next major version release DEPRECATED 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.
64 65 66 67 68 69 70 |
# File 'lib/cuke_modeler/models/feature.rb', line 64 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 ⇒ Object
Returns a string representation of this model. For a feature model, this will be Gherkin text that is equivalent to the feature being modeled.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cuke_modeler/models/feature.rb', line 85 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 |