Red Green Repeat Adventures of a Spec Driven Junkie

Faster Hello World with Aruba

In my first article about Aruba, it was introducing how to use Aruba to test any program, even Hello World! But…

There is a way to make the Hello World specs run faster than the way introduced in my aruba starter project: remove the sleep(1) command from the spec.

Update source files

In the top of the main source file include the following line at the top of the source file:

  • #!/usr/bin/env ruby for Ruby files
  • #!/usr/bin/env python for Python files
  • and nothing needed for the bash file

Make file executable

On the command line, execute chmod +x <file>, like so:

u@system:~/aruba_starter$ chmod +x src/hello_world.rb src/hello_world.py src/hello_world.sh

Now, the hello_world.rb program can be run like any command by:

u@system:~/aruba_starter$ ./src/hello_world.rb

as well as:

u@system:~/aruba_starter$ ruby src/hello_world.rb

Pretty neat, right?

Update specs

Well, the cooler part is by doing this, sleep(1) can be removed from the spec file and the run command is now:

run('hello_world.rb')

Troubleshooting

If there is an error when running the specs, that says “Aruba::LaunchError” or has the following form:

Aruba::LaunchError:
  Command "... PATH...".

If the file is in the specified path, then the main issue is the file does not have executable permissions. (Double check chmod +x worked.)

To see the changes, please take a look at the file: faster_hello_specs.rb.

Overall

With everything working, the specs will take 0.34171 seconds to run instead of 4.35 seconds. 12x improvement in speed with very little code changes.

Go forth and test (faster!)