class Lucid::Parser::SpecBuilder

The SpecBuilder conforms to the Gherkin event API.

Public Class Methods

new(path = 'UNKNOWN-FILE') click to toggle source
# File lib/lucid/spec_builder.rb, line 12
def initialize(path = 'UNKNOWN-FILE')
  @path = path
end

Public Instance Methods

background(node) click to toggle source

@param node [Object] instance of Gherkin::Formatter::Model::Background

# File lib/lucid/spec_builder.rb, line 35
def background(node)
  builder = BackgroundBuilder.new(file, node)
  @feature_builder.background_builder = builder
  @current = builder
end
eof() click to toggle source
# File lib/lucid/spec_builder.rb, line 72
def eof
end
examples(examples) click to toggle source
# File lib/lucid/spec_builder.rb, line 54
def examples(examples)
  examples_fields = [
    Lucid::AST::Location.new(file, examples.line),
    Lucid::AST::Comment.new(examples.comments.map{|comment| comment.value}.join("\n")),
    examples.keyword,
    examples.name,
    examples.description,
    matrix(examples.rows)
  ]
  @current.add_examples examples_fields, examples
end
feature(node) click to toggle source

@param node [Object] instance of Gherkin::Formatter::Model::Feature

# File lib/lucid/spec_builder.rb, line 30
def feature(node)
  @feature_builder = FeatureBuilder.new(file, node)
end
language=(language) click to toggle source
# File lib/lucid/spec_builder.rb, line 21
def language=(language)
  @language = language
end
result() click to toggle source
# File lib/lucid/spec_builder.rb, line 16
def result
  return nil unless @feature_builder
  @feature_builder.result(language)
end
scenario(node) click to toggle source

@param node [Object] instance of Gherkin::Formatter::Model::Scenario

# File lib/lucid/spec_builder.rb, line 42
def scenario(node)
  builder = ScenarioBuilder.new(file, node)
  @feature_builder.add_child builder
  @current = builder
end
scenario_outline(node) click to toggle source
# File lib/lucid/spec_builder.rb, line 48
def scenario_outline(node)
  builder = ScenarioOutlineBuilder.new(file, node)
  @feature_builder.add_child builder
  @current = builder
end
step(node) click to toggle source

@param node [Object] instance of Gherkin::Formatter::Model::Step

# File lib/lucid/spec_builder.rb, line 67
def step(node)
  builder = StepBuilder.new(file, node)
  @current.add_child builder
end
syntax_error(state, event, legal_events, line) click to toggle source
# File lib/lucid/spec_builder.rb, line 75
def syntax_error(state, event, legal_events, line)
  # Unsure if I should raise something here.
end
uri(uri) click to toggle source
# File lib/lucid/spec_builder.rb, line 25
def uri(uri)
  @path = uri
end

Private Instance Methods

file() click to toggle source
# File lib/lucid/spec_builder.rb, line 101
def file
  if Lucid::WINDOWS && !ENV['LUCID_FORWARD_SLASH_PATHS']
    @path.gsub(/\//, '\\')
  else
    @path
  end
end
language() click to toggle source
# File lib/lucid/spec_builder.rb, line 97
def language
  @language || raise('Language has not been set.')
end
matrix(gherkin_table) click to toggle source
# File lib/lucid/spec_builder.rb, line 86
def matrix(gherkin_table)
  gherkin_table.map do |gherkin_row|
    row = gherkin_row.cells
    class << row
      attr_accessor :line
    end
    row.line = gherkin_row.line
    row
  end
end