Sha256: 1b9d328b10a1fe0920f39195b7434bde0a01242e51e7855afc6d615c9c1ac435

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

module CucumberAnalytics

  # A class modeling an element that contains steps.

  class TestElement < FeatureElement

    include Containing


    # The steps contained by the TestElement
    attr_accessor :steps


    # Creates a new TestElement object and, if *parsed_test_element* is provided,
    # populates the object.
    def initialize(parsed_test_element = nil)
      super

      @steps = []

      build_test_element(parsed_test_element) if parsed_test_element
    end

    # Returns true if the two elements have equivalent steps and false otherwise.
    def ==(other_element)
      steps == other_element.steps
    end

    # Returns the immediate child elements of the element.
    def contains
      @steps
    end


    private


    def process_source(source)
      case
        when source.is_a?(String)
          parse_test_element(source)
        else
          source
      end
    end

    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

    def build_test_element(parsed_test_element)
      populate_test_element_steps(parsed_test_element)
    end

    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

    def steps_output_string
      steps.collect { |step| indented_step_text(step) }.join("\n")
    end

    def indented_step_text(step)
      step.to_s.split("\n").collect { |line| "  #{line}" }.join("\n")
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber_analytics-1.5.1 lib/cucumber_analytics/test_element.rb
cucumber_analytics-1.5.0 lib/cucumber_analytics/test_element.rb