Skip to content

Instantly share code, notes, and snippets.

@kriskhaira
Last active March 30, 2017 18: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 kriskhaira/9e706af0bddb49b7d0796ceb467fd95e to your computer and use it in GitHub Desktop.
Save kriskhaira/9e706af0bddb49b7d0796ceb467fd95e to your computer and use it in GitHub Desktop.
Run RSpec on all lines of files matching a phrase. Use case: making sure tests are working after refactoring.
# Searches and prints only the filenames with line number, colon-separated
function searchAndOutputNameAndLineOnly {
ag --nogroup $1 $2 | cut -d" " -f1-2 | cut -d":" -f1-2
}
# Searches phrase in path and runs RSpec on the lines
# Usage: searchAndRunSpecs <phrase> <path>
# From https://gist.github.com/kriskhaira/9e706af0bddb49b7d0796ceb467fd95e
function searchAndRunSpecs {
# Gets file list
fileList=`searchAndOutputNameAndLineOnly $1 $2`
# Removes line breaks
singleLine=`echo $fileList | tr "\n" " "`
# Uses zeus. YVMM. Too lazy to make smarter.
zeus rspec `echo $singleLine`
# Shows search matches at the end for convenience
echo '\nSEARCH MATCHES:'
ag --nogroup $1 $2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment