Skip to content

Instantly share code, notes, and snippets.

@andypearson
Last active October 18, 2016 21:49
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 andypearson/703624b136739f330204a452a10ec97c to your computer and use it in GitHub Desktop.
Save andypearson/703624b136739f330204a452a10ec97c to your computer and use it in GitHub Desktop.
Print SimpleCov last run percentage in "good" message
# 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
Copy link

alkesh commented Oct 18, 2016

what does the 32 and 33 do at the end of lines 8 and 13?

@andypearson
Copy link
Author

@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