Created
January 19, 2014 15:16
-
-
Save gaby-mg-snippets/8506192 to your computer and use it in GitHub Desktop.
Ruby: watchr wrapper script for TDD with PHPUnit
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
watch("models/(.*).php") do |match| | |
run_test %{tests/test_#{match[1]}.php} | |
end | |
watch("tests/.*.php") do |match| | |
run_test match[0] | |
end | |
def run_test(file) | |
unless File.exist?(file) | |
puts "#{file} does not exist" | |
return | |
end | |
puts "Running #{file}" | |
result = `vendor/bin/phpunit #{file}` | |
puts result | |
if result.match(/OK/) | |
notify "#{file}", "Tests Passed Successfuly", "/actions/48/dialog-ok.svg", 2000 | |
elsif result.match(/FAILURES\!/) | |
notify_failed file, result | |
end | |
end | |
def notify title, msg, img, show_time | |
images_dir='/usr/share/icons/Humanity' | |
system "notify-send '#{title}' '#{msg}' -i #{images_dir}/#{img} -t #{show_time}" | |
end | |
def notify_failed cmd, result | |
failed_examples = result.scan(/failure:\n\n(.*)\n/) | |
images_dir='' | |
notify "#{cmd}", failed_examples[0], "/status/48/error.svg", 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment