Class: Lucid::Parser::SpecBuilder

Inherits:
Object
  • Object
show all
Includes:
Gherkin::Rubify
Defined in:
lib/lucid/spec_builder.rb

Overview

The SpecBuilder conforms to the Gherkin event API.

Defined Under Namespace

Classes: BackgroundBuilder, FeatureBuilder, ScenarioBuilder, ScenarioOutlineBuilder, Spec, StepBuilder

Instance Method Summary collapse

Constructor Details

#initialize(path = 'UNKNOWN-FILE') ⇒ SpecBuilder

Returns a new instance of SpecBuilder.



12
13
14
# File 'lib/lucid/spec_builder.rb', line 12

def initialize(path = 'UNKNOWN-FILE')
  @path = path
end

Instance Method Details

#background(node) ⇒ Object

Parameters:

  • node (Object)

    instance of Gherkin::Formatter::Model::Background



35
36
37
38
39
# File 'lib/lucid/spec_builder.rb', line 35

def background(node)
  builder = BackgroundBuilder.new(file, node)
  @feature_builder.background_builder = builder
  @current = builder
end

#eofObject



72
73
# File 'lib/lucid/spec_builder.rb', line 72

def eof
end

#examples(examples) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Object

Parameters:

  • node (Object)

    instance of Gherkin::Formatter::Model::Feature



30
31
32
# File 'lib/lucid/spec_builder.rb', line 30

def feature(node)
  @feature_builder = FeatureBuilder.new(file, node)
end

#language=(language) ⇒ Object



21
22
23
# File 'lib/lucid/spec_builder.rb', line 21

def language=(language)
  @language = language
end

#resultObject



16
17
18
19
# File 'lib/lucid/spec_builder.rb', line 16

def result
  return nil unless @feature_builder
  @feature_builder.result(language)
end

#scenario(node) ⇒ Object

Parameters:

  • node (Object)

    instance of Gherkin::Formatter::Model::Scenario



42
43
44
45
46
# 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) ⇒ Object



48
49
50
51
52
# 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) ⇒ Object

Parameters:

  • node (Object)

    instance of Gherkin::Formatter::Model::Step



67
68
69
70
# 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) ⇒ Object



75
76
77
# 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) ⇒ Object



25
26
27
# File 'lib/lucid/spec_builder.rb', line 25

def uri(uri)
  @path = uri
end