#!/usr/bin/env ruby puts "Git hook pre-commit: #{__FILE__}" puts "Executing RSpec tests..." html_path = "tmp/spec_results.html" `spec -f h:#{html_path} -f l spec` # run the spec. save html results to html_path # find out how many errors were found html = open(html_path).read examples = html.match(/(d+) example/)[0].to_i rescue 0 failures = html.match(/(d+) failure/)[0].to_i rescue 0 pending = html.match(/(d+) pending/)[0].to_i rescue 0 if failures.zero? puts "#################################################################" puts "No errors were found o/" puts "0 failures! #{examples} run, #{pending} pending" puts "#################################################################" else puts "#################################################################" puts "Commit aborted!" puts "WTF are you doing? Sorry, but some errors were found, dude!" puts "#{failures} failures! #{examples} run, #{pending} pending" puts "View tests results at #{File.expand_path(html_path)}" puts "#################################################################" exit 1 end