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

language[RW]

The language 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.

@example

Feature.new
Feature.new("Feature:\nThis is a feature")

@param source_text [String] The Gherkin text that will be used to populate the model @raise [ArgumentError] If source_text is not a String @return [Feature] A new Feature instance

Calls superclass method
# File lib/cuke_modeler/models/feature.rb, line 39
def initialize(source_text = nil)
  @tags = []
  @rules = []
  @tests = []

  super
end

Public Instance Methods

background?() click to toggle source

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

@example

feature.background?

@return [Boolean] Whether the feature contains a background

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

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.

@example

feature.children

@return [Array<Rule, Background, Scenario, Outline, Tag>] A collection of child models

# File lib/cuke_modeler/models/feature.rb, line 107
def children
  models = rules + tests + tags
  models << background if background

  models
end
has_background?()
Alias for: background?
inspect(verbose: false) click to toggle source

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.

@example

feature.inspect
feature.inspect(verbose: true)

@param verbose [Boolean] Whether or not to return the full details of

the object. Defaults to false.

@return [String] A string representation of this model

Calls superclass method
# File lib/cuke_modeler/models/feature.rb, line 152
def inspect(verbose: false)
  return super if verbose

  "#{super.chop} @name: #{name.inspect}>"
end
outlines() click to toggle source

Returns the outline models contained in the feature.

@example

feature.outlines

@return [Array<Outline>] Child Outline models

# File lib/cuke_modeler/models/feature.rb, line 75
def outlines
  @tests.select { |test| test.is_a? Outline }
end
scenarios() click to toggle source

Returns the scenario models contained in the feature.

@example

feature.scenarios

@return [Array<Scenario>] Child Scenario models

# File lib/cuke_modeler/models/feature.rb, line 65
def scenarios
  @tests.select { |test| test.is_a? Scenario }
end
test_case_count() click to toggle source

@deprecated 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.

@example

feature.test_case_count

@return [Integer] The count of test cases

# 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() 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.

@example

feature.to_s

@return [String] A string representation of this model

# File lib/cuke_modeler/models/feature.rb, line 124
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 183
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 195
def child_element_output_string(model)
  model.to_s.split("\n").collect { |line| line.empty? ? '' : "  #{line}" }.join("\n")
end
populate_language(parsed_feature_data) click to toggle source
# File lib/cuke_modeler/models/feature.rb, line 179
def populate_language(parsed_feature_data)
  @language = parsed_feature_data['language']
end
populate_model(parsed_feature_data) click to toggle source
# File lib/cuke_modeler/models/feature.rb, line 168
def populate_model(parsed_feature_data)
  populate_parsing_data(parsed_feature_data)
  populate_source_location(parsed_feature_data)
  populate_language(parsed_feature_data)
  populate_keyword(parsed_feature_data)
  populate_name(parsed_feature_data)
  populate_description(parsed_feature_data)
  populate_tags(parsed_feature_data)
  populate_children(parsed_feature_data)
end
process_source(source_text) click to toggle source
# File lib/cuke_modeler/models/feature.rb, line 162
def process_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 191
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 187
def tests_output_string
  tests.collect { |test| child_element_output_string(test) }.join("\n\n")
end