Sha256: f24083cdd1993efd3747957ad6f77946f57945739b8c3c8fe2b8824af39656b5

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

require File.expand_path('../step_definition', __FILE__)
require File.expand_path('../parser', __FILE__)

class StepDefinitionFile

  FILE_COMMENT_END = 'FILE_COMMENT_END'

  attr_accessor :steps

  def initialize(filename)
    @filename = filename
    @code = File.read(filename)
    self.steps = []
    extract_comment
    add_steps
  end

  def to_markdown
    <<-TEXT
### #{ @filename.split('/').last }

#{@comment}

#{ steps.collect(&:to_markdown).join("\n\n") }
    TEXT
  end

  def real_steps
    steps.select do |definition|
      StepManager::STEP_KINDS.include? definition.kind
    end
  end

private

  def extract_comment
    if @code.include?(FILE_COMMENT_END)
      file_comment = @code.split(FILE_COMMENT_END).first
      @comment = Parser.format_comment(file_comment)
    end
  end

  def add_steps
    @code.split("\n\n").each do |block|
      step = StepDefinition.new_from_raw(block)
      steps << step if step
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spreewald-1.6.0 support/step_definition_file.rb