首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将解析的小黄瓜保存为特征文件(Ruby)

如何将解析的小黄瓜保存为特征文件(Ruby)
EN

Stack Overflow用户
提问于 2018-02-23 22:30:20
回答 1查看 471关注 0票数 0

我需要以编程方式修改黄瓜的特征文件。我已经使用gherkin的gem 'gherkin/parser‘解析了一个特征文件。

我发现的问题是,在解析之后,我最终得到了一个哈希,其中包含以下数据作为示例:

代码语言:javascript
复制
{:type=>:GherkinDocument, :feature=>{:type=>:Feature, :tags=>[], :location=>{:line=>1, :column=>1}, :language=>"en", :keyword=>"Feature", :name=>"MyFeature", :description=>"  As an user\n  I want to test a feature", :children=>[{:type=>:Scenario, :tags=>[{:type=>:Tag, :location=>{:line=>5, :column=>3}, :name=>"@MyTag"}], :location=>{:line=>6, :column=>3}, :keyword=>"Scenario", :name=>"My scenario", :steps=>[{:type=>:Step, :location=>{:line=>7, :column=>5}, :keyword=>"Given ", :text=>"I start the app"}, {:type=>:Step, :location=>{:line=>8, :column=>5}, :keyword=>"And ", :text=>"I generate a test user"}, {:type=>:Step, :location=>{:line=>9, :column=>5}, :keyword=>"And ", :text=>"I finish the flow"}]}]}, :comments=>[]}

有没有可能将解析器生成的这个GherkinDocument转换为纯文本特征文件来保存它?我应该使用什么方法或gem来获取

EN

回答 1

Stack Overflow用户

发布于 2018-02-24 00:25:55

根据docs的说法,您将使用Ruby Gherkin::Pickles::Compiler

代码语言:javascript
复制
require 'gherkin/parser'
require 'gherkin/pickles/compiler'
parser = Gherkin::Parser.new
gherkin_document = parser.parse("Feature: ...")
# Make changes to gherkin_document
pickles = Gherkin::Pickles::Compiler.new.compile(gherkin_document)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48950102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档