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

#initialize(feature_file) ⇒ Builder

Returns a new instance of Builder.



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

def initialize(feature_file)
  @feature_file = feature_file
  @features = []
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



101
102
103
# File 'lib/turnip/builder.rb', line 101

def features
  @features
end

Class Method Details

.build(feature_file) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/turnip/builder.rb', line 104

def build(feature_file)
  Turnip::Builder.new(feature_file).tap do |builder|
    formatter = Gherkin::Formatter::TagCountFormatter.new(builder, {})
    parser = Gherkin::Parser::Parser.new(formatter, true, "root", false)
    parser.parse(feature_file.content, nil, 0)
  end
end

Instance Method Details

#background(background) ⇒ Object



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

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

#eofObject



152
153
# File 'lib/turnip/builder.rb', line 152

def eof
end

#examples(examples) ⇒ Object



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

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

#feature(feature) ⇒ Object



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

def feature(feature)
  @current_feature = Feature.new(feature)
  # Automatically add a tag based on the name of the feature to the Feature if configured to
  @current_feature.feature_tag = @feature_file.feature_name if Turnip::Config.autotag_features
  @features << @current_feature
end

#scenario(scenario) ⇒ Object



130
131
132
133
# File 'lib/turnip/builder.rb', line 130

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

#scenario_outline(outline) ⇒ Object



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

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

#step(step) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/turnip/builder.rb', line 143

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