Class: CukeModeler::Rule

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

Overview

A class modeling a rule in a Cucumber suite.

Instance Attribute Summary collapse

Attributes included from Sourceable

#source_line

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 Parsing

dialects, parse_text

Methods included from Containing

#each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Rule

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



26
27
28
29
30
31
32
33
34
35
# File 'lib/cuke_modeler/models/rule.rb', line 26

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

  super(source_text)

  if source_text
    parsed_rule_data = parse_source(source_text)
    populate_rule(self, parsed_rule_data)
  end
end

Instance Attribute Details

#backgroundObject

The Background object contained by the Rule



18
19
20
# File 'lib/cuke_modeler/models/rule.rb', line 18

def background
  @background
end

#keywordObject

The keyword for the rule



15
16
17
# File 'lib/cuke_modeler/models/rule.rb', line 15

def keyword
  @keyword
end

#testsObject

The Scenario and Outline objects contained by the Rule



21
22
23
# File 'lib/cuke_modeler/models/rule.rb', line 21

def tests
  @tests
end

Instance Method Details

#childrenObject

Returns the model objects that belong to this model.



53
54
55
56
57
58
# File 'lib/cuke_modeler/models/rule.rb', line 53

def children
  models = tests
  models << background if background

  models
end

#has_background?Boolean

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

Returns:

  • (Boolean)


38
39
40
# File 'lib/cuke_modeler/models/rule.rb', line 38

def has_background?
  !@background.nil?
end

#outlinesObject

Returns the outline models contained in the rule.



48
49
50
# File 'lib/cuke_modeler/models/rule.rb', line 48

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

#scenariosObject

Returns the scenario models contained in the rule.



43
44
45
# File 'lib/cuke_modeler/models/rule.rb', line 43

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

#to_sObject

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



62
63
64
65
66
67
68
69
70
71
# File 'lib/cuke_modeler/models/rule.rb', line 62

def to_s
  text = ''

  text << "#{@keyword}:#{name_output_string}"
  text << "\n" + description_output_string unless (description.nil? || description.empty?)
  text << "\n\n" + background_output_string if background
  text << "\n\n" + tests_output_string unless tests.empty?

  text
end