kit kit - 9 months ago 50
Bash Question

How to capture shell script program output from cucumber/aruba?

I want to capture output which I'm running from the cucumber feature file.

I created one shell script program and placed it in /usr/local/bin/ so it can be accessible from anywhere in system. -

if [[ $arg = 1 ]]
echo $(date)

project structure of cucumber -

aruba -


├── features

│ ├── support

│ │ └── env.rb

│ └── use_aruba_cucumber.feature

├── Gemfile

Gemfile -

source ''
gem 'aruba', '~> 0.14.2'

env.rb -

require 'aruba/cucumber'

use_aruba_cucumber.feature -

Feature: Cucumber
Scenario: First Run
When I run `bash 1`

I want to capture this program output in the cucumber itself and compare this date is right or wrong by using any kind of simple test and make this test as a pass.

Answer Source

You can use %x(command) to get the stdout of your command.

You can then use Time.parse to convert "Sat Nov 5 12:04:18 CET 2016" to 2016-11-05 12:04:18 +0100 as Time object, and compare it to :

require 'time'
time_from_abc_script = Time.parse(%x(bash 1))
puts ( < 5 # No more than 5s difference between 2 times

You could use this boolean in any test file you want.

For example :

In features/use_aruba_with_cucumber.feature :

Feature: Cucumber
 Scenario: First Run
  When I run `bash 1`
  Then the output should be the current time

and features/step_definitions/time_steps.rb :

require 'time'

Then(/^the output should be the current time$/) do
  time_from_script = Time.parse(last_command_started.output)
  expect(time_from_script).to be_within(5).of(