Class: CukeModeler::Background

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

Overview

A class modeling a feature’s background.

Instance Attribute Summary

Attributes included from Sourceable

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

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Background

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



16
17
18
19
20
21
22
23
24
25
# File 'lib/cuke_modeler/models/background.rb', line 16

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

  super(source_text)

  if source_text
    parsed_background_data = parse_source(source_text)
    populate_background(self, parsed_background_data)
  end
end

Instance Method Details

#==(other_model) ⇒ Object

Returns true if the two models have equivalent steps and false otherwise.



28
29
30
31
32
# File 'lib/cuke_modeler/models/background.rb', line 28

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

  steps == other_model.steps
end

#childrenObject

Returns the model objects that belong to this model.



35
36
37
# File 'lib/cuke_modeler/models/background.rb', line 35

def children
  steps
end

#to_sObject

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



41
42
43
44
45
46
47
48
49
50
# File 'lib/cuke_modeler/models/background.rb', line 41

def to_s
  text = ''

  text << "Background:#{name_output_string}"
  text << "\n" + description_output_string unless (description.nil? || description.empty?)
  text << "\n" unless (steps.empty? || description.nil? || description.empty?)
  text << "\n" + steps_output_string unless steps.empty?

  text
end