我相信这是一个非常愚蠢的问题,但我无法理解。
我有以下红宝石代码:
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输出?
发布于 2013-11-18 16:57:18
好吧,我找到了。这个官方的例子运行得很好:
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)https://stackoverflow.com/questions/20053004
复制相似问题