Class: CukeModeler::Scenario

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

Overview

A class modeling an individual scenario of 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) ⇒ Scenario

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

Examples:

Scenario.new
Scenario.new("Scenario:\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



29
30
31
32
33
34
# File 'lib/cuke_modeler/models/scenario.rb', line 29

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

  super
end

Instance Attribute Details

#keywordObject

The scenario’s keyword



16
17
18
# File 'lib/cuke_modeler/models/scenario.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:

scenario_1 == scenario_2

Parameters:

  • other (Object)

    The object to compare this model with

Returns:

  • (Boolean)

    Whether the two objects are equivalent



44
45
46
47
48
# File 'lib/cuke_modeler/models/scenario.rb', line 44

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

  steps == other.steps
end

#childrenArray<Step, Tag>

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

Examples:

scenario.children

Returns:

  • (Array<Step, Tag>)

    A collection of child models



57
58
59
# File 'lib/cuke_modeler/models/scenario.rb', line 57

def children
  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 a Scenario model, this will be the name of the scenario. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

scenario.inspect
scenario.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



98
99
100
101
102
# File 'lib/cuke_modeler/models/scenario.rb', line 98

def inspect(verbose: false)
  return super if verbose

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

#to_sString

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

Examples:

scenario.to_s

Returns:

  • (String)

    A string representation of this model



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cuke_modeler/models/scenario.rb', line 71

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
end