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 :
if [ [ $arg = 1 ] ]
gem 'aruba', '~> 0.14.2'
Scenario: First Run
When I run `bash abc_qa.sh`
Then the output should contain exactly $(date)
Sat Nov 5 15:00:13 IST 2016
This is what I would do :
Feature: MyDateScript abc_qa Scenario: Run with one parameter When I run `bash abc_qa.sh 1` Then the output first word should be an abbreviated day of the week And the output first word should be the current day of the week And the output should be the current time
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.
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(Time.now) end Then(/^the output first word should be an abbreviated day of the week$/) do #NOTE: It assumes that date is launched with LC_ALL=en_US.UTF-8 as locale day_of_week, day, month, hms, zone, year = last_command_started.output.split days_of_week = %w(Mon Tue Wed Thu Fri Sat Sun) expect(days_of_week).to include(day_of_week) end Then(/^the output first word should be the current day of the week$/) do day_of_week, day, month, hms, zone, year = last_command_started.output.split expect(day_of_week).to eq(Time.now.strftime('%a')) end
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
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.