module CucumberAnalytics::Parsing

A module providing source text parsing functionality.

Public Class Methods

parse_text(source_text) click to toggle source

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

# 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