Class: CukeModeler::Feature

Inherits:
Model
  • Object
show all
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

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Taggable

#tags

Attributes included from Described

#description

Attributes included from Named

#name

Attributes included from Parsed

#parsing_data

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Taggable

#all_tags, #applied_tags

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Feature

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

Examples:

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

Parameters:

  • (defaults to: nil)

    The Gherkin text that will be used to populate the model

Raises:

  • If source_text is not a String



39
40
41
42
43
44
45
# File 'lib/cuke_modeler/models/feature.rb', line 39

def initialize(source_text = nil)
  @tags = []
  @rules = []
  @tests = []

  super
end

Instance Attribute Details

#backgroundObject

The Background object contained by the Feature



20
21
22
# File 'lib/cuke_modeler/models/feature.rb', line 20

def background
  @background
end

#keywordObject

The keyword for the feature



17
18
19
# File 'lib/cuke_modeler/models/feature.rb', line 17

def keyword
  @keyword
end

#languageObject

The language for the feature



14
15
16
# File 'lib/cuke_modeler/models/feature.rb', line 14

def language
  @language
end

#rulesObject

The Rule objects contained by the Feature



23
24
25
# File 'lib/cuke_modeler/models/feature.rb', line 23

def rules
  @rules
end

#testsObject

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.

Examples:

feature.background?

Returns:

  • Whether the feature contains a background



53
54
55
# File 'lib/cuke_modeler/models/feature.rb', line 53

def background?
  !@background.nil?
end

#childrenArray<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.

Examples:

feature.children

Returns:

  • A collection of child models



107
108
109
110
111
112
# File 'lib/cuke_modeler/models/feature.rb', line 107

def children
  models = rules + tests + tags
  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.

Examples:

feature.inspect
feature.inspect(verbose: true)

Parameters:

  • (defaults to: false)

    Whether or not to return the full details of the object. Defaults to false.

Returns:

  • A string representation of this model



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

#outlinesArray<Outline>

Returns the outline models contained in the feature.

Examples:

feature.outlines

Returns:

  • Child Outline models



75
76
77
# File 'lib/cuke_modeler/models/feature.rb', line 75

def outlines
  @tests.select { |test| test.is_a? Outline }
end

#scenariosArray<Scenario>

Returns the scenario models contained in the feature.

Examples:

feature.scenarios

Returns:

  • Child Scenario models



65
66
67
# File 'lib/cuke_modeler/models/feature.rb', line 65

def scenarios
  @tests.select { |test| test.is_a? Scenario }
end

#test_case_countInteger

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.

Examples:

feature.test_case_count

Returns:

  • The count of test cases



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_sString

Returns a string representation of this model. For a Feature model, this will be Gherkin text that is equivalent to the feature being modeled.

Examples:

feature.to_s

Returns:

  • A string representation of this model



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 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