Skip to content

Instantly share code, notes, and snippets.

@txus
Created September 12, 2012 08:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save txus/3705372 to your computer and use it in GitHub Desktop.
Save txus/3705372 to your computer and use it in GitHub Desktop.
Minitest Runner

MiniTest Runner

A basic runner for MiniTest as a shell script! Requires bash >= 4.0.

One-liner install

mkdir -p ~/bin && curl https://raw.github.com/gist/3705372/2f591ce427e21dab7685f7c743272827c8e8cf4f/minitest > ~/bin/minitest && chmod +x ~/bin/minitest

Put the ~/bin directory in your PATH.

Usage

Run a single test:

$ minitest path/to/my_test.rb

Run all tests under one directory:

$ minitest test/functional

Run all tests under test:

$ minitest

Who's this

This was made by Josep M. Bach (Txus) under the MIT license. I'm @txustice on twitter (where you should probably follow me!).

#!/bin/bash
set -e
shopt -s globstar
# Public: Resolves files to be run by the test runner.
#
# path - Can be either a test file, or a directory that contains tests at any
# depth.
#
# Returns a glob expression.
resolve_files ()
{
if [[ $1 =~ .rb$ ]] ; then
# if provided a file ending in .rb execute a single test
echo " -r./$1"
elif [[ -n "$1" ]] ; then
# if provided any other argument execute all tests under one folder
for file in $1/**/*_test.rb
do
echo " -r./$file"
done
else
# run all tests by default
for file in test/**/*_test.rb
do
echo " -r./$file"
done
fi
}
# Handle -h argument and show usage banner
while getopts :h o
do
case "$o" in
h) echo "Usage: $0 file_or_path"
exit 1;
esac
done
# Run the tests!
path=$(resolve_files $1)
env ruby -e\"nil\" -Ilib:test -rminitest/autorun $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment