1

在 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
4

2 回答 2

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)
于 2017-02-23T16:57:13.133 回答
0

您也可以将其写入临时文件并从文件中读取值。

require 'cucumber'
require 'tempfile'
require 'securerandom'

filename = "#{SecureRandom.urlsafe_base64}"
file = Tempfile.new(filename)
filepath = "#{file.path}"
features = "cucumber/ars/features/ars_additional.feature"
args = features.split.concat %w(-f html -o)
args << filepath
Cucumber::Cli::Main.new(args).execute!

@output = file.read
file.close
file.unlink
于 2017-02-23T18:27:36.760 回答