Sha256: cbcd42e5aa51a7c3df9ff997184847546228a4f693ad81e4d2adfa3c0bb904e4

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'gherkin'
require 'gherkin/dialect'

module Cucumber
  module Gherkin
    class StepsParser
      def initialize(builder, language)
        @builder = builder
        @language = language
      end

      def parse(text)
        dialect = ::Gherkin::Dialect.for(@language)
        gherkin_document = nil
        messages = ::Gherkin.from_source('dummy', feature_header(dialect) + text, gherkin_options)

        messages.each do |message|
          gherkin_document = message.gherkin_document.to_hash unless message.gherkin_document.nil?
        end

        @builder.steps(gherkin_document[:feature][:children][0][:scenario][:steps])
      end

      def gherkin_options
        {
          default_dialect: @language,
          include_source: false,
          include_gherkin_document: true,
          include_pickles: false
        }
      end

      def feature_header(dialect)
        %(#{dialect.feature_keywords[0]}:
            #{dialect.scenario_keywords[0]}:
         )
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
cucumber-6.1.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-6.0.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.3.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.2.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.1.3 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.1.2 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.1.1 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.1.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-5.0.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-4.1.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-4.0.1 lib/cucumber/gherkin/steps_parser.rb
cucumber-4.0.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-4.0.0.rc.6 lib/cucumber/gherkin/steps_parser.rb
cucumber-4.0.0.rc.5 lib/cucumber/gherkin/steps_parser.rb
cucumber-4.0.0.rc.4 lib/cucumber/gherkin/steps_parser.rb