Class: YARD::Parser::Cucumber::FeatureParser

Inherits:
Base
  • Object
show all
Defined in:
lib/yard/parser/cucumber/feature.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, file = '(stdin)') ⇒ FeatureParser

Each found feature found is creates a new FeatureParser

This logic was copied from the logic found in Cucumber to create the builder and then set up the formatter and parser. The difference is really the custom Cucumber::Parser::CityBuilder that is being used to parse the elements of the feature into YARD::CodeObjects.

Parameters:

  • source (<String>)

    containing the string conents of the feauture file

  • file (<String>) (defaults to: '(stdin)')

    the filename that contains the source



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yard/parser/cucumber/feature.rb', line 16

def initialize(source, file = '(stdin)')

  @builder = Cucumber::Parser::CityBuilder.new(file)
  @tag_counts = {}
  @parser = Gherkin::Parser.new(@builder)

  @source = source
  @file = file

  @feature = nil
end

Instance Method Details

#enumeratorObject

The only enumeration that can be done here is returning the feature itself



62
63
64
# File 'lib/yard/parser/cucumber/feature.rb', line 62

def enumerator
  [@feature]
end

#parseObject

When parse is called, the gherkin parser is executed and all the feature elements that are found are sent to the various methods in the Cucumber::Parser::CityBuilder. The result of which is the feature element that contains all the scenarios, steps, etc. associated with that feature.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/yard/parser/cucumber/feature.rb', line 35

def parse
  begin
    @parser.parse(@source)
    @feature = @builder.ast
    return nil if @feature.nil? # Nothing matched
    
    # The parser used the following keywords when parsing the feature
    # @feature.language = @parser.i18n_language.get_code_keywords.map {|word| word }
    
  rescue Gherkin::ParserError => e
    e.message.insert(0, "#{@file}: ")
    warn e
  end
  
  self
end

#tokenizeObject

This is not used as all the work is done in the parse method



55
56
57
# File 'lib/yard/parser/cucumber/feature.rb', line 55

def tokenize
  
end