Last active
December 17, 2015 13:38
-
-
Save dsandstrom/5618072 to your computer and use it in GitHub Desktop.
Shell script that runs RSpec Ruby tests in Fuubar format.
This file contains hidden or 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
| #!/bin/bash | |
| # Fuubar format RSpec | |
| # `fuubar` - runs all tests in spec/ | |
| # `fuubar [path/from/spec]` - if the folder or file is found, runs tests in that folder/file | |
| # also guesses where the file is located based on the partial file name | |
| # examples: | |
| # --- | |
| # `fuubar user` - runs spec/models/user_spec.rb | |
| # `fuubar user_controller` - runs spec/controllers/user_controller_spec.rb | |
| # `fuubar user_helper` - runs spec/helpers/user_helper_spec.rb | |
| # `fuubar user_pages` - runs spec/features/user_pages_spec.rb | |
| # `fuubar user_mailer` - runs spec/mailers/user_mailer_spec.rb | |
| # `fuubar user_uploader` - runs spec/uploaders/user_uploader_spec.rb | |
| spec="spec/" | |
| if [ "$#" -eq "0" ] ; then | |
| # echo "spec/" | |
| folder="$spec" | |
| else | |
| # echo "spec/$1" | |
| folder="$spec$1" | |
| fi | |
| if [ ! -d "./$folder" ] && [ ! -f "$folder" ] ; then | |
| # split input into array | |
| IFS='_' read -ra spec_array <<< "$1" | |
| # get last value of array | |
| length=${#spec_array[@]} | |
| if [[ "$length" -eq "1" ]]; then | |
| new_folder="spec/models/$1_spec.rb" | |
| else | |
| spec_type="${spec_array[($length - 1)]}" | |
| if [ "$spec_type" == "pages" ]; then | |
| new_folder="spec/features/$1_spec.rb" | |
| elif [ "$spec_type" == "controller" ]; then | |
| new_folder="spec/controllers/$1_spec.rb" | |
| elif [ "$spec_type" == "helper" ]; then | |
| new_folder="spec/helpers/$1_spec.rb" | |
| elif [ "$spec_type" == "mailer" ]; then | |
| new_folder="spec/mailers/$1_spec.rb" | |
| elif [ "$spec_type" == "uploader" ]; then | |
| new_folder="spec/uploaders/$1_spec.rb" | |
| elif [ "$spec_type" == "rake" ]; then | |
| new_folder="spec/lib/tasks/$1_spec.rb" | |
| fi | |
| fi | |
| if [ ! -f "$new_folder" ] ; then | |
| echo "$new_folder: File does not exist" | |
| exit 1 | |
| else | |
| echo "running tests in $new_folder" | |
| bundle exec rspec --format Fuubar "$new_folder" | |
| exit 0 | |
| fi | |
| else | |
| echo "running tests in $folder" | |
| bundle exec rspec --format Fuubar "$folder" | |
| exit 0 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment