lib/parallel_tests/cucumber/scenarios.rb in parallel_tests-2.32.0 vs lib/parallel_tests/cucumber/scenarios.rb in parallel_tests-3.0.0

- old
+ new

@@ -1,14 +1,19 @@ require 'cucumber/tag_expressions/parser' -require 'cucumber/core/gherkin/tag_expression' require 'cucumber/runtime' require 'cucumber' require 'parallel_tests/cucumber/scenario_line_logger' require 'parallel_tests/gherkin/listener' -require 'gherkin/errors' require 'shellwords' +begin + gem "cuke_modeler", "~> 3.0" + require 'cuke_modeler' +rescue LoadError + raise 'Grouping by individual cucumber scenarios requires the `cuke_modeler` modeler gem with requirement `~> 3.0`. Add `gem "cuke_modeler", "~> 3.0"` to your `Gemfile`, run `bundle install` and try again.' +end + module ParallelTests module Cucumber class Scenarios class << self def all(files, options={}) @@ -38,35 +43,20 @@ features ||= files.map do |path| # Gather up any line numbers attached to the file path path, *test_lines = path.split(/:(?=\d+)/) test_lines.map!(&:to_i) - # We encode the file and get the content of it - source = ::Cucumber::Runtime::NormalisedEncodingFile.read(path) # We create a Gherkin document, this will be used to decode the details of each scenario - document = ::Cucumber::Core::Gherkin::Document.new(path, source) + document = ::CukeModeler::FeatureFile.new(path) + feature = document.feature - # We create a parser for the gherkin document - parser = ::Gherkin::Parser.new() - scanner = ::Gherkin::TokenScanner.new(document.body) + # We make an attempt to parse the gherkin document, this could be failed if the document is not well formatted + feature_tags = feature.tags.map(&:name) - begin - # We make an attempt to parse the gherkin document, this could be failed if the document is not well formatted - result = parser.parse(scanner) - feature_tags = result[:feature][:tags].map { |tag| tag[:name] } - - # We loop on each children of the feature - result[:feature][:children].each do |feature_element| - # If the type of the child is not a scenario or scenario outline, we continue, we are only interested by the name of the scenario here - next unless /Scenario/.match(feature_element[:type]) - - # It's a scenario, we add it to the scenario_line_logger - scenario_line_logger.visit_feature_element(document.uri, feature_element, feature_tags, line_numbers: test_lines) - end - - rescue StandardError => e - # Exception if the document is no well formated or error in the tags - raise ::Cucumber::Core::Gherkin::ParseError.new("#{document.uri}: #{e.message}") + # We loop on each children of the feature + feature.tests.each do |test| + # It's a scenario, we add it to the scenario_line_logger + scenario_line_logger.visit_feature_element(document.path, test, feature_tags, line_numbers: test_lines) end end scenario_line_logger.scenarios end