class CukeModeler::Feature
A class modeling a feature in a Cucumber suite.
Attributes
The Background
object contained by the Feature
The keyword for the feature
Public Class Methods
Creates a new Feature
object and, if source_text is provided, populates the object.
# File lib/cuke_modeler/models/feature.rb, line 28 def initialize(source_text = nil) @tags = [] @rules = [] @tests = [] super(source_text) return unless source_text parsed_feature_data = parse_source(source_text) populate_feature(self, parsed_feature_data) end
Public Instance Methods
Returns true if the feature contains a background, false otherwise.
# File lib/cuke_modeler/models/feature.rb, line 42 def background? !@background.nil? end
Returns the model objects that belong to this model.
# File lib/cuke_modeler/models/feature.rb, line 72 def children models = rules + tests + tags models << background if background models end
Returns the outline models contained in the feature.
# File lib/cuke_modeler/models/feature.rb, line 54 def outlines @tests.select { |test| test.is_a? Outline } end
Returns the scenario models contained in the feature.
# File lib/cuke_modeler/models/feature.rb, line 49 def scenarios @tests.select { |test| test.is_a? Scenario } end
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.
# File lib/cuke_modeler/models/feature.rb, line 63 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
Returns a string representation of this model. For a feature model, this will be Gherkin text that is equivalent to the feature being modeled.
# File lib/cuke_modeler/models/feature.rb, line 84 def to_s text = '' text << "#{tag_output_string}\n" unless tags.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
Private Instance Methods
# File lib/cuke_modeler/models/feature.rb, line 109 def background_output_string child_element_output_string(background) end
# File lib/cuke_modeler/models/feature.rb, line 121 def child_element_output_string(model) model.to_s.split("\n").collect { |line| line.empty? ? '' : " #{line}" }.join("\n") end
rubocop:enable Metrics/AbcSize
# File lib/cuke_modeler/models/feature.rb, line 103 def parse_source(source_text) parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_feature.feature') parsed_file['feature'] end
# File lib/cuke_modeler/models/feature.rb, line 117 def rules_output_string rules.collect { |rule| child_element_output_string(rule) }.join("\n\n") end
# File lib/cuke_modeler/models/feature.rb, line 113 def tests_output_string tests.collect { |test| child_element_output_string(test) }.join("\n\n") end