Sha256: 01c557d2dcf68d3bd571cf4a3f05409d750c9ee3013799ce5647e918eb6aff6f

Contents?: true

Size: 1.02 KB

Versions: 19

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_h 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

19 entries across 19 versions & 4 rubygems

Version Path
cucumber-9.2.1 lib/cucumber/gherkin/steps_parser.rb
cucumber-9.2.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-9.1.2 lib/cucumber/gherkin/steps_parser.rb
cucumber-9.1.1 lib/cucumber/gherkin/steps_parser.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/gherkin/steps_parser.rb
cucumber-9.1.0 lib/cucumber/gherkin/steps_parser.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/gherkin/steps_parser.rb
cucumber-9.0.2 lib/cucumber/gherkin/steps_parser.rb
cucumber-9.0.1 lib/cucumber/gherkin/steps_parser.rb
cucumber-9.0.0 lib/cucumber/gherkin/steps_parser.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/gherkin/steps_parser.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/gherkin/steps_parser.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/gherkin/steps_parser.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/gherkin/steps_parser.rb
cucumber-8.0.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-8.0.0.rc.1 lib/cucumber/gherkin/steps_parser.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-7.1.0/lib/cucumber/gherkin/steps_parser.rb
cucumber-7.1.0 lib/cucumber/gherkin/steps_parser.rb
cucumber-7.0.0 lib/cucumber/gherkin/steps_parser.rb