1

Running a cucumber script in Jruby 9.1.7.0. The output goes to STDOUT. How can I get it to save it into a local variable ?

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
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88
YourAboutMeIsBlank
  • 1,787
  • 3
  • 18
  • 27

2 Answers2

0

If you type in 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.

You can modify your code with

args = features.split.concat %w(-f html -o test.html)
YourAboutMeIsBlank
  • 1,787
  • 3
  • 18
  • 27
0

You can also write it in a tempfile and read the value from the file.

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
YourAboutMeIsBlank
  • 1,787
  • 3
  • 18
  • 27