Skip to content

Instantly share code, notes, and snippets.

@gaby-mg-snippets
Created January 19, 2014 15:16
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 gaby-mg-snippets/8506192 to your computer and use it in GitHub Desktop.
Save gaby-mg-snippets/8506192 to your computer and use it in GitHub Desktop.
Ruby: watchr wrapper script for TDD with PHPUnit
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