Skip to content

Instantly share code, notes, and snippets.

@carvalhoviniciusluiz
Created September 6, 2016 12:30
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 carvalhoviniciusluiz/9ce02ffe9078bbe532e6b34d7b21896e to your computer and use it in GitHub Desktop.
Save carvalhoviniciusluiz/9ce02ffe9078bbe532e6b34d7b21896e to your computer and use it in GitHub Desktop.
autotest BDD for PHP with PHO
# see
# https://github.com/danielstjules/pho
# https://gist.github.com/carvalhoviniciusluiz/6950abaebf9148b50ffa11b84eb3cd7b
#
# install
# composer global require danielstjules/pho:dev-master
#
# edit ~/.bash
# export PATH=$HOME/.composer/vendor/bin:$PATH
#
# create specs folder in your project
# mkdir specs
#
# user:
# watchr autotest.spec
watch('specs/.*Spec\.php') { |m| code_changed(m[0]) }
def code_changed(file)
run "pho --reporter spec #{file}"
end
def clear
puts "\e[H\e[2J" #clear console
end
def run(cmd)
clear
notify `#{cmd}` rescue nil
end
def notify(message)
puts message #show console
content = message.split("\n")
if content.find { |e| /FAILED/ =~ e }
last_seven_lines = content.last(7)
title = last_seven_lines.first.gsub /[\("|\e\[0m)]/, ""
message = last_seven_lines.last.gsub /\e\[(0|22)m/, ""
image = "face-crying"
else
title = "PASS"
message = content.last.gsub /\e\[(0|22)m/, ""
image = "face-laugh"
end
`notify-send "#{title}" "#{message}" -i "#{image}"`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment