Module: CucumberAnalytics::Parsing

Defined in:
lib/cucumber_analytics/parsing.rb

Overview

A module providing source text parsing functionality.

Class Method Summary collapse

Class Method Details

.parse_text(source_text) ⇒ Object

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

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cucumber_analytics/parsing.rb', line 17

def parse_text(source_text)
  raise(ArgumentError, "Cannot parse #{source_text.class} objects. Strings only.") unless source_text.is_a?(String)

  io = StringIO.new
  formatter = Gherkin::Formatter::JSONFormatter.new(io)
  parser = Gherkin::Parser::Parser.new(formatter)
  parser.parse(source_text, 'fake_file.txt', 0)
  formatter.done

  MultiJson.load(io.string)
end