Skip to content

Instantly share code, notes, and snippets.

@jacklynrose
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacklynrose/e6e9f28e230e243ee75e to your computer and use it in GitHub Desktop.
Save jacklynrose/e6e9f28e230e243ee75e to your computer and use it in GitHub Desktop.
How I run MiniTest tests in 50% of the time of Rake::TestTask

RESULTS

Rake::TestTask

time rake test
real	0m1.111s
user	0m0.962s
sys	0m0.133s

time rake test
real	0m1.074s
user	0m0.944s
sys	0m0.124s

My bash script

time bin/test
real	0m0.504s
user	0m0.437s
sys	0m0.066s

time bin/test
real	0m0.495s
user	0m0.431s
sys	0m0.066s

Run one test by running bin/test.sh test/user_test.rb.

Or run the test for a file in lib bin/test.sh lib/user.rb will run the tests in user_test.rb.

Lastly, run all tests in the tests directory by running bin/test.sh.

Better yet, map this in vim.

map <Leader>tt :!bin/test.sh %<CR> " run test or test for file
map <Leader>ta :!bin/test.sh<CR>   " run all tests
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/**/*_test.rb']
end
#!/bin/bash
set -e
FILENAME="$1"
if [ ! $FILENAME == "" ]; then
if [[ -d $FILENAME ]]; then
TESTS=''
for file in `find $FILENAME | grep _test.rb`; do
TESTS="$TESTS require '`pwd`/$file';"
done
LIBDIR=${FILENAME/test*/lib}
ruby -I$LIBDIR:$FILENAME -e "$TESTS"
else
if [[ ! $FILENAME == *_test.rb ]]; then
FILENAME=${FILENAME/lib/test}
FILENAME=${FILENAME/.rb/_test.rb}
fi
if [ -f $FILENAME ]; then
ruby -Ilib:test $FILENAME
else
echo "File does not exist"
fi
fi
else
TESTS=''
for file in `find test | grep _test.rb`; do
TESTS="$TESTS require '`pwd`/$file';"
done
ruby -Ilib:test -e "$TESTS"
fi
@zenspider
Copy link

I haven't profiled anything, but this looks like it's really just a comparison of (gnu?) find+grep vs Rake's FileList (which I'm not a fan of, for the record).

Is there any chance you can strip out the actual test run and compare those?

I'd also love to see a comparison against my test task in Hoe. It uses plain Dir.glob, not FileTask. (thinking about it... I could probably make it even faster since I already have a manifest).

Prolly just benchmarking the 3 discovery mechanisms would be illuminating.

@zenspider
Copy link

Also: how big is your test suite?

Also: why aren't you just using find instead of find+grep? find test -name \*_test.rb might be even quicker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment