I want to test my executable shell script with the help of cucumber/aruba. For that purpose I created one shell script and place it in usr/local/bin/ so it can accessible from anywhere.
shell script :
arg=$1
if [ [ $arg = 1 ] ]
then
echo $(date)
fi
Now I want to test this shell script in cucumber/aruba. For that purpose I created one project structure.
aruba -
.
├── features
│ ├── support
│ │ └── env.rb
│ └── use_aruba_cucumber.feature
├── Gemfile
Gemfile -
source 'https://rubygems.org'
gem 'aruba', '~> 0.14.2'
env.rb -
require 'aruba/cucumber'
use_aruba_cucumber.feature -
Feature: Cucumber
Scenario: First Run
When I run `bash abc_qa.sh`
Then the output should contain exactly $(date)
Shell script code is returning date. Now In this feature file I want to check is that date is correct or not by using simple checking.
example : date is returning like this :
Sat Nov 5 15:00:13 IST 2016
so I just want to check Sat is right or wrong. For that purpose use one label [Mon,Tue,Wed,Thu,Fri,Sat,Sun] like this.
If Sat is available in above label Then make this test case as a pass.
note - I'm saying this label thing for simplicity sakel. If any other option for checking day is correct in seven days of week then this should be appreciated.
Thanks.
This is what I would do :
features/use_my_date_script_with_parameter.feature
:This feature file is both a documentation and specs of your program. It is meant to be written by people who are not necessarily developers. As long as the extension is ".feature" and the structure is here (With Feature, Scenario and Steps), you can write pretty much anything descriptive inside. More info about cucumber here.
You could add a new line (e.g. "And the output should look like A and not B"), and launch cucumber. It won't fail, it will just tell you what you should define in steps file.
and
features/step_definitions/time_steps.rb
:This is the definition of the sentences in feature file that aren't yet known to Cucumber. It is a Ruby file, so you can write any Ruby code inside, mostly in the blocks between
do
andend
. There you can have access to the output of the last command (your bash script in this case) as a String, and write tests with it. For example, split this string and assign every part to a new variable. Once you have the day of the week as a String (e.g. "Sat"), you can test it with expect keyword.The tests are written in order of strength. The second test might not pass around midnight if you're unlucky. I defined other variables (day, month, hms, zone, year) as String if you want to write your own test.