Sha256: af507b537b18a8e4eadf36cda9a889ad2a679cf726b0ee537ec67aa28274f188

Contents?: true

Size: 863 Bytes

Versions: 4

Compression:

Stored size: 863 Bytes

Contents

require 'stringio'
require 'gherkin/formatter/json_formatter'
require 'gherkin'
require 'json'
require 'multi_json'

module CucumberAnalytics

  # A module providing source text parsing functionality.

  module Parsing

    class << self

      # Parses the Cucumber feature given in *source_text* and returns an array
      # containing the hash representation of its logical structure.
      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

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cucumber_analytics-1.6.0 lib/cucumber_analytics/parsing.rb
cucumber_analytics-1.5.2 lib/cucumber_analytics/parsing.rb
cucumber_analytics-1.5.1 lib/cucumber_analytics/parsing.rb
cucumber_analytics-1.5.0 lib/cucumber_analytics/parsing.rb