我需要以编程方式修改黄瓜的特征文件。我已经使用gherkin的gem 'gherkin/parser‘解析了一个特征文件。
我发现的问题是,在解析之后,我最终得到了一个哈希,其中包含以下数据作为示例:
{: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来获取
发布于 2018-02-24 00:25:55
根据docs的说法,您将使用Ruby Gherkin::Pickles::Compiler
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)https://stackoverflow.com/questions/48950102
复制相似问题