class GherkinGenerator::Scenario

Object oriented representation of scenarios. This is designed for internal use by GherkinGenerator.

Public Class Methods

new(scenario, examples) click to toggle source

Takes a single-line scenario and a formatted example table

# File lib/gherkin_generator.rb, line 101
def initialize(scenario, examples)
  @scenario = scenario
  @tag = []
  @examples = if examples.nil?
                ''
              else
                "\n\tExamples:\n\t\t" + examples.strip.gsub("\n", "\n\t\t")
              end
end

Public Instance Methods

add_tag(tag) click to toggle source

Adding a tag - the formatting is applied, you just supply the tag name

# File lib/gherkin_generator.rb, line 113
def add_tag(tag)
  @tag << '@' + tag
end
format_string() click to toggle source

The output of the current scenario, a feature file is made up of a description and multiple scenarios formatted as a string.

# File lib/gherkin_generator.rb, line 120
def format_string
  keywords = %w(Given And When Then)
  steps = @scenario.split(':')[1].strip
  keywords.map do |word|
    steps = steps.split(" #{word}").join("\n\t\t#{word}")
  end
  scenario = @scenario.split(':')[0]
  tag = @tag.empty? ? '' : (@tag.join(' ') + "\n\t")
  type = @examples.empty? ? 'Scenario' : 'Scenario Outline'
  "\n\n\t" + tag + type + ': ' + scenario + "\n\t\t" + steps + @examples
end