Class: CucumberAnalytics::Feature

Inherits:
FeatureElement show all
Includes:
Containing, Taggable
Defined in:
lib/cucumber_analytics/feature.rb

Overview

A class modeling a Cucumber Feature.

Instance Attribute Summary collapse

Attributes included from Taggable

#tag_elements, #tags

Attributes inherited from FeatureElement

#description, #description_text, #name

Attributes included from Nested

#parent_element

Attributes included from Raw

#raw_element

Attributes included from Sourceable

#source_line

Instance Method Summary collapse

Methods included from Taggable

#all_tag_elements, #all_tags, #applied_tag_elements, #applied_tags

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source = nil) ⇒ Feature

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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cucumber_analytics/feature.rb', line 20

def initialize(source = nil)
  parsed_feature = process_source(source)

  super(parsed_feature)

  @tags = []
  @tag_elements = []
  @tests = []

  build_feature(parsed_feature) if parsed_feature
end

Instance Attribute Details

#backgroundObject

The Background object contained by the Feature



12
13
14
# File 'lib/cucumber_analytics/feature.rb', line 12

def background
  @background
end

#testsObject

The TestElement objects contained by the Feature



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

def tests
  @tests
end

Instance Method Details

#containsObject

Returns the immediate child elements of the feature (i.e. its Background, Scenario, and Outline objects.



73
74
75
# File 'lib/cucumber_analytics/feature.rb', line 73

def contains
  @background ? [@background] + @tests : @tests
end

#has_background?Boolean

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

Returns:

  • (Boolean)


33
34
35
# File 'lib/cucumber_analytics/feature.rb', line 33

def has_background?
  !@background.nil?
end

#outline_countObject

Returns the number of outlines contained in the feature.



53
54
55
# File 'lib/cucumber_analytics/feature.rb', line 53

def outline_count
  outlines.count
end

#outlinesObject

Returns the outlines contained in the feature.



43
44
45
# File 'lib/cucumber_analytics/feature.rb', line 43

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

#scenario_countObject

Returns the number of scenarios contained in the feature.



48
49
50
# File 'lib/cucumber_analytics/feature.rb', line 48

def scenario_count
  scenarios.count
end

#scenariosObject

Returns the scenarios contained in the feature.



38
39
40
# File 'lib/cucumber_analytics/feature.rb', line 38

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

#test_case_countObject

Returns the number of test cases contained in the feature.



63
64
65
66
67
68
69
# File 'lib/cucumber_analytics/feature.rb', line 63

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

#test_countObject

Returns the number of tests contained in the feature.



58
59
60
# File 'lib/cucumber_analytics/feature.rb', line 58

def test_count
  @tests.count
end

#to_sObject

Returns gherkin representation of the feature.



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cucumber_analytics/feature.rb', line 79

def to_s
  text = ''

  text << tag_output_string + "\n" unless tags.empty?
  text << "Feature:#{name_output_string}"
  text << "\n" + description_output_string unless description_text.empty?
  text << "\n\n" + background_output_string if background
  text << "\n\n" + tests_output_string unless tests.empty?

  text
end