Skip to content

Instantly share code, notes, and snippets.

@johnrees
Created January 5, 2015 16:10
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 johnrees/b0abd440eb1f8bc1b6e9 to your computer and use it in GitHub Desktop.
Save johnrees/b0abd440eb1f8bc1b6e9 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
need_rails=1
if [ $# -gt 0 ]; then # we have args
filename=$1
# remove trailing line number from filename e.g. spec/my_spec.rb:33
grep_filename=`echo $1 | sed 's/:.*$//g'`
(set +e; grep -r 'rails_helper\|spec_helper' $grep_filename) > /dev/null
if [ $? -eq 1 ]; then # no match; we have a standalone spec
need_rails=''
fi
else # we have no args
filename='spec'
fi
command='rspec'
if [ $need_rails ]; then
command="ruby -S bundle exec $command"
fi
echo "RAILS_ENV=test $command $filename"
RAILS_ENV=test $command $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment