Class: CukeModeler::Outline

Inherits:
Model
  • Object
show all
Includes:
Described, Named, Parsed, Parsing, Sourceable, Stepped, Taggable
Defined in:
lib/cuke_modeler/models/outline.rb

Overview

A class modeling an individual outline in a Cucumber suite.

Instance Attribute Summary collapse

Attributes included from Taggable

#tags

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Stepped

#steps

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 Parsing

dialects, parse_text

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Outline

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

Examples:

Outline.new
Outline.new("Scenario Outline:\n  * a step")

Parameters:

  • source_text (String) (defaults to: nil)

    The Gherkin text that will be used to populate the model

Raises:

  • (ArgumentError)

    If source_text is not a String



32
33
34
35
36
37
38
# File 'lib/cuke_modeler/models/outline.rb', line 32

def initialize(source_text = nil)
  @steps = []
  @tags = []
  @examples = []

  super(source_text)
end

Instance Attribute Details

#examplesObject

The Example objects contained by the Outline



19
20
21
# File 'lib/cuke_modeler/models/outline.rb', line 19

def examples
  @examples
end

#keywordObject

The outline’s keyword



16
17
18
# File 'lib/cuke_modeler/models/outline.rb', line 16

def keyword
  @keyword
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this model with another object. Returns true if the two objects have equivalent steps and false otherwise.

Examples:

outline_1 == outline_2

Parameters:

  • other (Object)

    The object to compare this model with

Returns:

  • (Boolean)

    Whether the two objects are equivalent



48
49
50
51
52
# File 'lib/cuke_modeler/models/outline.rb', line 48

def ==(other)
  return false unless other.respond_to?(:steps)

  steps == other.steps
end

#childrenArray<Step, Tag, Example>

Returns the model objects that are children of this model. For an Outline model, these would be any associated Step, Tag, or Example models.

Examples:

outline.children

Returns:



62
63
64
# File 'lib/cuke_modeler/models/outline.rb', line 62

def children
  examples + steps + tags
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 an Outline model, this will be the name of the outline. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

outline.inspect
outline.inspect(verbose: true)

Parameters:

  • verbose (Boolean) (defaults to: false)

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

Returns:

  • (String)

    A string representation of this model



104
105
106
107
108
# File 'lib/cuke_modeler/models/outline.rb', line 104

def inspect(verbose: false)
  return super(verbose: verbose) if verbose

  "#{super.chop} @name: #{name.inspect}>"
end

#to_sString

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

Examples:

outline.to_s

Returns:

  • (String)

    A string representation of this model



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cuke_modeler/models/outline.rb', line 76

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" unless steps.empty? || no_description_to_output?
  text << "\n#{steps_output_string}" unless steps.empty?
  text << "\n\n#{examples_output_string}" unless examples.empty?

  text
end