Last active
March 30, 2017 18:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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