Module: CucumberAnalytics::Nested

Included in:
Directory, DocString, FeatureElement, FeatureFile, Row, Step, Table, TableRow, Tag
Defined in:
lib/cucumber_analytics/nested.rb

Overview

A mix-in module containing methods used by elements that are nested inside of other elements.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_elementObject

The parent object that contains self



9
10
11
# File 'lib/cucumber_analytics/nested.rb', line 9

def parent_element
  @parent_element
end

Instance Method Details

#get_ancestor(ancestor_type) ⇒ Object

Returns the ancestor of self that matches the given type.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cucumber_analytics/nested.rb', line 13

def get_ancestor(ancestor_type)
  ancestor = self.parent_element
  target_type = {:directory => Directory,
                 :feature_file => FeatureFile,
                 :feature => Feature,
                 :test => TestElement,
                 :step => Step,
                 :table => Table,
                 :example => Example
  }[ancestor_type]

  raise(ArgumentError, "Unknown ancestor type '#{ancestor_type}'.") if target_type.nil?

  until ancestor.is_a?(target_type) || ancestor.nil?
    ancestor = ancestor.parent_element
  end

  ancestor
end