You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

data_table_parser.rb 1.1 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'gherkin'
  3. require 'gherkin/dialect'
  4. module Cucumber
  5. module Gherkin
  6. class DataTableParser
  7. def initialize(builder)
  8. @builder = builder
  9. end
  10. def parse(text)
  11. gherkin_document = nil
  12. messages = ::Gherkin.from_source('dummy', feature_header + text, gherkin_options)
  13. messages.each do |message|
  14. gherkin_document = message.gherkin_document.to_h unless message.gherkin_document.nil?
  15. end
  16. return if gherkin_document.nil?
  17. gherkin_document[:feature][:children][0][:scenario][:steps][0][:data_table][:rows].each do |row|
  18. @builder.row(row[:cells].map { |cell| cell[:value] })
  19. end
  20. end
  21. def gherkin_options
  22. {
  23. include_source: false,
  24. include_gherkin_document: true,
  25. include_pickles: false
  26. }
  27. end
  28. def feature_header
  29. dialect = ::Gherkin::Dialect.for('en')
  30. %(#{dialect.feature_keywords[0]}:
  31. #{dialect.scenario_keywords[0]}:
  32. #{dialect.given_keywords[0]} x
  33. )
  34. end
  35. end
  36. end
  37. end

No Description

Contributors (1)