Skip to content

Instantly share code, notes, and snippets.

@ArturT
Last active June 26, 2021 05:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ArturT/9b2fe6f3f39cd7914711 to your computer and use it in GitHub Desktop.
Save ArturT/9b2fe6f3f39cd7914711 to your computer and use it in GitHub Desktop.
Watch file changes and run rspec for the test file or specified line number test. Use spring with rspec optionally.
# It requries installed nodemon
# $ npm install -g nodemon
#
# Add this in your ~/.bash_profile
#
# How to use it?
#
# Run spec for user_spec.rb when file changed.
# $ wr spec/models/user_spec.rb
#
# Run spec for user_spec.rb:80 (only spec in line 80) when file changed.
# $ wr spec/models/user_spec.rb 80
#
# Use wsr if you want to run spring rspec to speed up. For instance:
# $ wsr spec/models/user_spec.rb 80
function run_after_save {
prefix=$1
file=$2
line=$3
if [ -z "$line" ]; then
nodemon -x "$prefix $file" -w "$file"
else
nodemon -x "$prefix $file:$line" -w "$file"
fi
}
alias wsr='run_after_save "bundle exec spring rspec"'
alias wr='run_after_save "bundle exec rspec"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment