Question

Je suis sûr que c'est une question très stupide, mais je n'arrive pas à comprendre.

J'ai le code Ruby suivant :

sample_test = "Feature: Some terse yet descriptive text of what is desired
Textual description of the business value of this feature
Business rules that govern the scope of the feature
Any additional information that will make the feature easier to understand
Scenario: Some determinable business situation
Given some precondition
  And some other precondition
 When some action by the actor
  And some other action
  And yet another action
 Then some testable outcome is achieved
  And something else we can check happens too"

io = StringIO.new
pretty_formatter    = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
json_formatter      = Gherkin::Formatter::JSONFormatter.new(io)
parser = Gherkin::Parser::Parser.new(json_formatter)
result = parser.parse(sample_test, '', 0)

Cela revient True.Mais je veux obtenir un résultat au format JSON.Que dois-je utiliser pour obtenir la sortie JSON de toutes les étapes ?

Était-ce utile?

La solution

ok, je l'ai trouvé. Cet exemple officiel ça marche plutôt bien :

require 'gherkin/parser/parser'
require 'gherkin/formatter/json_formatter'
require 'stringio'
require 'multi_json'

# This example reads a couple of features and outputs them as JSON.

io = StringIO.new
formatter = Gherkin::Formatter::JSONFormatter.new(io)
parser = Gherkin::Parser::Parser.new(formatter)

sources = ["features/native_lexer.feature", "features/escaped_pipes.feature"]
sources.each do |s|
  path = File.expand_path(File.dirname(__FILE__) + '/../' + s)
  parser.parse(IO.read(path), path, 0)
end

formatter.done
puts MultiJson.dump(MultiJson.load(io.string), :pretty => true)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top