class CucumberAnalytics::TestElement

A class modeling an element that contains steps.

Attributes

steps[RW]

The steps contained by the TestElement

Public Class Methods

new(parsed_test_element = nil) click to toggle source

Creates a new TestElement object and, if parsed_test_element is provided, populates the object.

Calls superclass method CucumberAnalytics::FeatureElement::new
# File lib/cucumber_analytics/test_element.rb, line 16
def initialize(parsed_test_element = nil)
  super

  @steps = []

  build_test_element(parsed_test_element) if parsed_test_element
end

Public Instance Methods

==(other_element) click to toggle source

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

# File lib/cucumber_analytics/test_element.rb, line 25
def ==(other_element)
  return false unless other_element.respond_to?(:steps)

  steps == other_element.steps
end
contains() click to toggle source

Returns the immediate child elements of the element.

# File lib/cucumber_analytics/test_element.rb, line 32
def contains
  @steps
end

Private Instance Methods

build_test_element(parsed_test_element) click to toggle source
# File lib/cucumber_analytics/test_element.rb, line 58
def build_test_element(parsed_test_element)
  populate_test_element_steps(parsed_test_element)
end
indented_step_text(step) click to toggle source
# File lib/cucumber_analytics/test_element.rb, line 74
def indented_step_text(step)
  step.to_s.split("\n").collect { |line| "  #{line}" }.join("\n")
end
parse_test_element(source_text) click to toggle source
# File lib/cucumber_analytics/test_element.rb, line 49
def parse_test_element(source_text)
  base_file_string = "Feature: Fake feature to parse\n"
  source_text = base_file_string + source_text

  parsed_file = Parsing::parse_text(source_text)

  parsed_file.first['elements'].first
end
populate_test_element_steps(parsed_test_element) click to toggle source
# File lib/cucumber_analytics/test_element.rb, line 62
def populate_test_element_steps(parsed_test_element)
  if parsed_test_element['steps']
    parsed_test_element['steps'].each do |step|
      @steps << build_child_element(Step, step)
    end
  end
end
process_source(source) click to toggle source
# File lib/cucumber_analytics/test_element.rb, line 40
def process_source(source)
  case
    when source.is_a?(String)
      parse_test_element(source)
    else
      source
  end
end
steps_output_string() click to toggle source
# File lib/cucumber_analytics/test_element.rb, line 70
def steps_output_string
  steps.collect { |step| indented_step_text(step) }.join("\n")
end