class CukeModeler::Feature

A class modeling a feature in a Cucumber suite.

Attributes

background[RW]

The Background object contained by the Feature

keyword[RW]

The keyword for the feature

rules[RW]

The Rule objects contained by the Feature

tests[RW]

The Scenario and Outline objects contained by the Feature

Public Class Methods

new(source_text = nil) click to toggle source

Creates a new Feature object and, if source_text is provided, populates the object.

Calls superclass method
# 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

background?() click to toggle source

Returns true if the feature contains a background, false otherwise.

# File lib/cuke_modeler/models/feature.rb, line 42
def background?
  !@background.nil?
end
Also aliased as: has_background?
children() click to toggle source

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
has_background?()
Alias for: background?
outlines() click to toggle source

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
scenarios() click to toggle source

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
test_case_count() click to toggle source

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
to_s() click to toggle source

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

background_output_string() click to toggle source
# File lib/cuke_modeler/models/feature.rb, line 109
def background_output_string
  child_element_output_string(background)
end
child_element_output_string(model) click to toggle source
# 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
parse_source(source_text) click to toggle source

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
rules_output_string() click to toggle source
# 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
tests_output_string() click to toggle source
# 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