Class: Turnip::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/turnip/builder.rb

Defined Under Namespace

Modules: Name, Tags Classes: Background, Feature, Scenario, ScenarioOutline, Step

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



124
125
126
# File 'lib/turnip/builder.rb', line 124

def initialize
  @features = []
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



113
114
115
# File 'lib/turnip/builder.rb', line 113

def features
  @features
end

Class Method Details

.build(feature_file) ⇒ Object



116
117
118
119
120
121
# File 'lib/turnip/builder.rb', line 116

def build(feature_file)
  Turnip::Builder.new.tap do |builder|
    parser = Gherkin::Parser::Parser.new(builder, true)
    parser.parse(File.read(feature_file), feature_file, 0)
  end
end

Instance Method Details

#background(background) ⇒ Object



128
129
130
131
# File 'lib/turnip/builder.rb', line 128

def background(background)
  @current_step_context = Background.new(background)
  @current_feature.backgrounds << @current_step_context
end

#eofObject



164
165
# File 'lib/turnip/builder.rb', line 164

def eof
end

#examples(examples) ⇒ Object



147
148
149
# File 'lib/turnip/builder.rb', line 147

def examples(examples)
  @current_feature.scenarios.push(*@current_step_context.to_scenarios(examples))
end

#feature(feature) ⇒ Object



133
134
135
136
# File 'lib/turnip/builder.rb', line 133

def feature(feature)
  @current_feature = Feature.new(feature)
  @features << @current_feature
end

#scenario(scenario) ⇒ Object



138
139
140
141
# File 'lib/turnip/builder.rb', line 138

def scenario(scenario)
  @current_step_context = Scenario.new(scenario)
  @current_feature.scenarios << @current_step_context
end

#scenario_outline(outline) ⇒ Object



143
144
145
# File 'lib/turnip/builder.rb', line 143

def scenario_outline(outline)
  @current_step_context = ScenarioOutline.new(outline)
end

#step(step) ⇒ Object



151
152
153
154
155
156
157
158
159
# File 'lib/turnip/builder.rb', line 151

def step(step)
  extra_args = []
  if step.doc_string
    extra_args.push step.doc_string.value
  elsif step.rows
    extra_args.push Turnip::Table.new(step.rows.map { |row| row.cells(&:value) })
  end
  @current_step_context.steps << Step.new(step.name, extra_args, step.line)
end

#uriObject



161
162
# File 'lib/turnip/builder.rb', line 161

def uri(*)
end