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

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Feature

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cuke_modeler/models/feature.rb', line 23

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

  super(source_text)

  if source_text
    parsed_feature_data = parse_source(source_text)
    populate_feature(self, parsed_feature_data)
  end
end

Instance Attribute Details

#backgroundObject

The Background object contained by the Feature



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

def background
  @background
end

#testsObject

The Scenario and Outline objects contained by the Feature



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

def tests
  @tests
end

Instance Method Details

#childrenObject

Returns the model objects that belong to this model.



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

def children
  models = tests + tags
  models << background if background

  models
end

#has_background?Boolean

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/cuke_modeler/models/feature.rb', line 36

def has_background?
  !@background.nil?
end

#outlinesObject

Returns the outline models contained in the feature.



46
47
48
# File 'lib/cuke_modeler/models/feature.rb', line 46

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

#scenariosObject

Returns the scenario models contained in the feature.



41
42
43
# File 'lib/cuke_modeler/models/feature.rb', line 41

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

#test_case_countObject

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.



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

def test_case_count
  scenarios.count + outlines.reduce(0) { |outline_sum, outline|
    outline_sum += outline.examples.reduce(0) { |example_sum, example|
      example_sum += example.argument_rows.count
    }
  }
end

#to_sObject

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



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

def to_s
  text = ''

  text << tag_output_string + "\n" unless tags.empty?
  text << "Feature:#{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