Sha256: 141e926e0b3a5189551c7123f7224d965c9bcf9f55fd777231b87d3a6d47fa50

Contents?: true

Size: 1.78 KB

Versions: 13

Compression:

Stored size: 1.78 KB

Contents

module CukeModeler

  # A class modeling a feature's background.
  class Background < Model

    include Parsing
    include Parsed
    include Named
    include Described
    include Stepped
    include Sourceable


    # The background's keyword
    attr_accessor :keyword


    # Creates a new Background object and, if *source_text* is provided, populates
    # the object.
    def initialize(source_text = nil)
      @steps = []

      super(source_text)

      return unless source_text

      parsed_background_data = parse_source(source_text)
      populate_background(self, parsed_background_data)
    end

    # Returns *true* if the two models have equivalent steps and *false* otherwise.
    def ==(other)
      return false unless other.respond_to?(:steps)

      steps == other.steps
    end

    # Returns the model objects that belong to this model.
    def children
      steps
    end

    # Returns a string representation of this model. For a background model,
    # this will be Gherkin text that is equivalent to the background being modeled.
    def to_s
      text = ''

      text << "#{@keyword}:#{name_output_string}"
      text << "\n#{description_output_string}" unless no_description_to_output?
      text << "\n" unless steps.empty? || no_description_to_output?
      text << "\n#{steps_output_string}" unless steps.empty?

      text
    end


    private


    def parse_source(source_text)
      base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n"
      source_text = base_file_string + source_text

      parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_background.feature')

      parsed_file['feature']['elements'].first
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cuke_modeler-3.19.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.18.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.17.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.16.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.15.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.14.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.13.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.12.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.11.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.10.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.9.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.8.0 lib/cuke_modeler/models/background.rb
cuke_modeler-3.7.0 lib/cuke_modeler/models/background.rb