Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created February 3, 2017 21:22
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 dgmike/176a78f7fe8fde51e02b4fb52357de35 to your computer and use it in GitHub Desktop.
Save dgmike/176a78f7fe8fde51e02b4fb52357de35 to your computer and use it in GitHub Desktop.
Watch some paths and run rspec with defined arguments
# Watch some path and run rspec with defined arguments
#
# usage:
# watch_rspec watch_path1 watch_path2 -- rspec_arguments
#
function watch_rspec
{
local WATCH_FILES
local ARGUMENTS
while [ $# -ne 0 ]; do
if [ "$1" == "--" ]; then
shift
break
fi
WATCH_FILES+="$1 "
shift
done
ARGUMENTS=$*
local NEW=
local OLD=`gfind ${WATCH_FILES} -type f -printf '%T@ %S %M %h/%f\n' | md5`
echo "+ watching ${WATCH_FILES}"
while true; do
NEW=`gfind ${WATCH_FILES} -type f -printf '%T@ %S %M %h/%f\n' | md5`
if [ "$OLD" != "$NEW" ]; then
echo "+ rspec" $ARGUMENTS
rspec $ARGUMENTS
OLD=$NEW
fi
sleep 1
done
}
# vim: set ts=4 sw=4 tw=0 et :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment