Sha256: 79db28e2ed6919653412d5aff7f5c23f407bda71bc9c1a2dc7927289bfe3a0c9

Contents?: true

Size: 856 Bytes

Versions: 4

Compression:

Stored size: 856 Bytes

Contents

# frozen_string_literal: true

require 'gherkin/token_scanner'
require 'gherkin/parser'
require 'gherkin/dialect'

module Cucumber
  module Gherkin
    class DataTableParser
      def initialize(builder)
        @builder = builder
      end

      def parse(text)
        token_scanner = ::Gherkin::TokenScanner.new(feature_header + text)
        parser = ::Gherkin::Parser.new
        gherkin_document = parser.parse(token_scanner)

        gherkin_document[:feature][:children][0][:steps][0][:argument][:rows].each do |row|
          @builder.row(row[:cells].map { |cell| cell[:value] })
        end
      end

      def feature_header
        dialect = ::Gherkin::Dialect.for('en')
        %(#{dialect.feature_keywords[0]}:
            #{dialect.scenario_keywords[0]}:
              #{dialect.given_keywords[0]} x
         )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
cucumber-3.2.0 lib/cucumber/gherkin/data_table_parser.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/cucumber-3.1.2/lib/cucumber/gherkin/data_table_parser.rb
cucumber-3.1.2 lib/cucumber/gherkin/data_table_parser.rb
cucumber-3.1.1 lib/cucumber/gherkin/data_table_parser.rb