Skip to content

Instantly share code, notes, and snippets.

@chmurph2
Created July 31, 2014 17:15
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 chmurph2/a935d44f924f0d8fca78 to your computer and use it in GitHub Desktop.
Save chmurph2/a935d44f924f0d8fca78 to your computer and use it in GitHub Desktop.
Bash function to run targeted Rails tests.
# Use: rt test_file
# Use: rt test_file:test_name_regex
# Finds a file under test/* and runs it with -n /test_name_regex/
function rt {
FILE_HINT=`echo $1 | cut -f1 -d:`
TEST_REGEX=`echo $1 | cut -f2 -d:`
FILE_PATH=`find test/* -maxdepth 3 -name ${FILE_HINT}_test.rb`
if [ -z $FILE_PATH ];
then
echo Couldn\'t find file for $FILE_HINT
return
fi
if [[ $1 =~ ":" ]];
then
echo Running $FILE_PATH -n /$TEST_REGEX/
ruby -Itest $FILE_PATH -n /$TEST_REGEX/
else
echo Running $FILE_PATH
ruby -Itest $FILE_PATH
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment