ガーキンを JSON に解析する [終了]
質問
これは非常に愚かな質問だと思いますが、理解できません。
次の Ruby コードがあります。
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)
これは戻ります True
。ただし、JSON 形式の結果を取得したいと考えています。すべてのステップの JSON 出力を取得するには何を使用すればよいですか?
解決
よし、見つけた。 この公式の例 かなりうまく機能します:
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)
所属していません StackOverflow