Module: CukeModeler::Parsing

Included in:
Background, Cell, Comment, DocString, Example, Outline, Row, Scenario, Step, Table, Tag
Defined in:
lib/cuke_modeler/parsing.rb

Overview

A module providing source text parsing functionality.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dialectObject

The dialect that will be used to parse snippets of Gherkin text



105
106
107
# File 'lib/cuke_modeler/parsing.rb', line 105

def dialect
  @dialect || 'en'
end

Class Method Details

.dialectsObject

The dialects currently known by the gherkin gem



110
111
112
113
114
115
116
# File 'lib/cuke_modeler/parsing.rb', line 110

def dialects
  unless @dialects
    @dialects = Gem.loaded_specs['gherkin'].version.version[/^2\./] ? Gherkin::I18n::LANGUAGES : Gherkin::DIALECTS
  end

  @dialects
end

.parse_text(source_text, filename = 'cuke_modeler_fake_file.feature') ⇒ Object

Parses the Cucumber feature given in source_text and returns an array containing the hash representation of its logical structure.

Raises:

  • (ArgumentError)


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/cuke_modeler/parsing.rb', line 120

def parse_text(source_text, filename = 'cuke_modeler_fake_file.feature')
  raise(ArgumentError, "Text to parse must be a String but got #{source_text.class}") unless source_text.is_a?(String)


  begin
    parsed_result = parsing_method(source_text, filename)
  rescue => e
    raise(ArgumentError, "Error encountered while parsing '#{filename}'\n#{e.class} - #{e.message}")
  end

  adapted_result = adapter_class.new.adapt(parsed_result)


  adapted_result
end