如何将Cucumber :: CLI :: Main.execute的输出(STDOUT)转换为变量

时间:2017-02-23 15:43:08

标签: cucumber stdout jruby stdin popen3

在Jruby 9.1.7.0中运行黄瓜脚本。输出转到STDOUT。如何将其保存到本地变量?

require 'cucumber'
require 'stringio'

@output = StringIO.new
features = 'features/first.feature'
args = features.split.concat %w(-f html)

# Run cucumber
begin
# output goes to STDOUT
  Cucumber::Cli::Main.new(args).execute!
rescue SystemExit
  puts "Cucumber calls @kernel.exit(), killing your script unless you rescue"
end

1 个答案:

答案 0 :(得分:0)

如果您输入cmd “cucumber --help”

-o, --out [FILE|DIR]             Write output to a file/directory instead of STDOUT. This option
                                 applies to the previously specified --format, or the
                                 default format if no format is specified. Check the specific
                                 formatter's docs to see whether to pass a file or a dir.

您可以使用

修改代码
args = features.split.concat %w(-f html -o test.html)