Class: Nukumber::GherkinBuilder

Inherits:
Object
  • Object
show all
Includes:
Gherkin::Rubify
Defined in:
lib/nukumber/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGherkinBuilder

Returns a new instance of GherkinBuilder.



12
13
14
15
16
# File 'lib/nukumber/builder.rb', line 12

def initialize
  @features = []
  @all_longsyms = []
  @all_shortsyms = []
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



10
11
12
# File 'lib/nukumber/builder.rb', line 10

def features
  @features
end

Instance Method Details

#background(gherkin_background) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/nukumber/builder.rb', line 39

def background(gherkin_background)
  @current_feature_element = Nukumber::Model::Background.new(
    gherkin_background.name.strip,
    gherkin_background.line,
    gherkin_background.description.strip,
    @current_feature
  )
  @current_feature.background = @current_feature_element
  check_names
end

#check_namesObject



18
19
20
21
22
23
24
25
26
# File 'lib/nukumber/builder.rb', line 18

def check_names
  if @all_longsyms.include? @current_feature_element.longsym
    raise Nukumber::NameCollisionError, @current_feature_element.longsym
  elsif @all_longsyms.include? @current_feature_element.shortsym or @all_shortsyms.include? @current_feature_element.shortsym
    raise Nukumber::NameCollisionWarning, @current_feature_element.shortsym
  end
  @all_longsyms << @current_feature_element.longsym
  @all_shortsyms << @current_feature_element.shortsym
end

#eofObject



93
94
95
96
# File 'lib/nukumber/builder.rb', line 93

def eof
  @current_feature = nil
  @current_feature_element = nil
end

#examples(gherkin_examples) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/nukumber/builder.rb', line 74

def examples(gherkin_examples)
  @current_feature_element.examples = Nukumber::Model::Examples.new(
    gherkin_examples.name.strip,
    gherkin_examples.line,
    gherkin_examples.keyword,
    Nukumber::Model::Table.new(gherkin_examples.rows)
  )
end

#feature(gherkin_feature) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/nukumber/builder.rb', line 28

def feature(gherkin_feature)
  @current_feature = Nukumber::Model::Feature.new(
    gherkin_feature.name.strip,
    gherkin_feature.line,
    gherkin_feature.description.strip,
    $feature_file_path
  )
  @current_feature.tags = gherkin_feature.tags.map(&:name)
  @features << @current_feature
end

#scenario(gherkin_scenario) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/nukumber/builder.rb', line 50

def scenario(gherkin_scenario)
  @current_feature_element = Nukumber::Model::Scenario.new(
    gherkin_scenario.name.strip,
    gherkin_scenario.line,
    gherkin_scenario.description.strip,
    @current_feature
  )
  @current_feature_element.tags = gherkin_scenario.tags.map(&:name)
  @current_feature.feature_elements << @current_feature_element
  check_names
end

#scenario_outline(gherkin_outline) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/nukumber/builder.rb', line 62

def scenario_outline(gherkin_outline)
  @current_feature_element = Nukumber::Model::ScenarioOutline.new(
    gherkin_outline.name.strip,
    gherkin_outline.line,
    gherkin_outline.description.strip,
    @current_feature
  )
  @current_feature_element.tags = gherkin_outline.tags.map(&:name)
  @current_feature.feature_elements << @current_feature_element
  check_names
end

#step(gherkin_step) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/nukumber/builder.rb', line 83

def step(gherkin_step)
  @current_feature_element.steps << Nukumber::Model::Step.new(
    gherkin_step.name.strip,
    gherkin_step.line,
    gherkin_step.keyword,
    @current_feature_element,
    Nukumber::Model::Table.new(gherkin_step.rows)
  )
end

#syntax_errorObject



98
99
100
# File 'lib/nukumber/builder.rb', line 98

def syntax_error(*)
  raise Nukumber::SyntaxError
end