Class: Cucumber::Gherkin::StepsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/gherkin/steps_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder, language) ⇒ StepsParser

Returns a new instance of StepsParser


11
12
13
14
# File 'lib/cucumber/gherkin/steps_parser.rb', line 11

def initialize(builder, language)
  @builder = builder
  @language = language
end

Instance Method Details

#feature_header(dialect) ⇒ Object


26
27
28
29
30
# File 'lib/cucumber/gherkin/steps_parser.rb', line 26

def feature_header(dialect)
  %(#{dialect.feature_keywords[0]}:
      #{dialect.scenario_keywords[0]}:
   )
end

#parse(text) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/cucumber/gherkin/steps_parser.rb', line 16

def parse(text)
  dialect = ::Gherkin::Dialect.for(@language)
  token_matcher = ::Gherkin::TokenMatcher.new(@language)
  token_scanner = ::Gherkin::TokenScanner.new(feature_header(dialect) + text)
  parser = ::Gherkin::Parser.new
  gherkin_document = parser.parse(token_scanner, token_matcher)

  @builder.steps(gherkin_document[:feature][:children][0][:steps])
end