Sha256: 50982402771e83b4f259e93107c6e1399cfd32f477ebb964eb4e1bf1bff3411b

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

module CukeModeler

  # 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)
      return false unless other_element.respond_to?(:steps)

      steps == other_element.steps
    end

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


    private


    def process_source(source, file_name = nil)
      case
        when source.is_a?(String)
          parse_test_element(source, file_name)
        else
          source
      end
    end

    def parse_test_element(source_text, file_name = nil)
      base_file_string = "Feature: Fake feature to parse\n"
      source_text = base_file_string + source_text

      parsed_file = Parsing::parse_text(source_text, file_name)

      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

4 entries across 4 versions & 1 rubygems

Version Path
cuke_modeler-0.4.1 lib/cuke_modeler/test_element.rb
cuke_modeler-0.4.0 lib/cuke_modeler/test_element.rb
cuke_modeler-0.3.0 lib/cuke_modeler/test_element.rb
cuke_modeler-0.2.0 lib/cuke_modeler/test_element.rb