Last active
October 18, 2016 21:49
-
-
Save andypearson/703624b136739f330204a452a10ec97c to your computer and use it in GitHub Desktop.
Print SimpleCov last run percentage in "good" message
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
# Cucumber | |
function c { | |
if [ -f "./bin/docker/cucumber" ]; then | |
echo "Running bin/docker/cucumber..." | |
command bin/docker/cucumber $@ | |
elif [ -f "./bin/cucumber" ]; then | |
echo "Running bin/cucumber..." | |
command bin/cucumber $@ | |
else | |
echo "Running bundle exec cucumber..." | |
command bundle exec cucumber $@ | |
fi | |
} | |
# RSpec | |
function s { | |
if [ -f "./bin/docker/rspec" ]; then | |
echo "Running bin/docker/rspec..." | |
command bin/docker/rspec $@ | |
elif [ -f "./bin/rspec" ]; then | |
echo "Running bin/rspec..." | |
command bin/rspec $@ | |
else | |
echo "Running bundle exec rspec..." | |
command bundle exec rspec $@ | |
fi | |
} | |
# Rubocop | |
function cop { | |
if [ -f "./.rubocop.yml" ]; then | |
echo "Running bundle exec rubocop..." | |
command bundle exec rubocop $@ | |
else | |
echo ".rubocop.yml not found!" | |
fi | |
} | |
function banner { | |
text=`figlet "$1"` | |
colour=$2 || 39 | |
printf "\e[${colour}m\n${text}\n\n\e[0m" | |
} | |
function good_message { | |
local last_run_file="./coverage/.last_run.json" | |
if [[ -f $last_run_file ]]; then | |
covered=$(cat $last_run_file | grep -Eo "\d+.?\d*") | |
if [[ $(echo "${covered} < 100" | bc) -eq 1 ]]; then | |
banner "$covered% GOOD" 33 | |
return | |
fi | |
fi | |
banner "GOOD!" 32 | |
} | |
function good? { | |
(export REPORT_COVERAGE=true; s && c && cop && good_message) || banner "NOT GOOD" "31" | |
} |
@alkesh I've updated the gist to include all of the dependent functions, which is probably enough to explain that:
banner
accepts two arguments, the text and the colour, 31 is red, 32 is green and 33 is yellow.
The traffic lights of code quality :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what does the 32 and 33 do at the end of lines 8 and 13?