Files
wpscan/dev/pre-commit-hook.rb
erwanlr dc1c65b418 Tabs replaced by spaces !
The presence of tabs can be checked with 'rubocop --only Tab --format
files'
2013-12-30 11:50:43 +00:00

41 lines
1019 B
Ruby
Executable File

#!/usr/bin/env ruby
# ln -sf /Users/xxx/wpscan/dev/pre-commit-hook.rb /Users/xxx/wpscan/.git/hooks/pre-commit
require 'pty'
html_path = 'rspec_results.html'
begin
PTY.spawn( "rspec spec --format h > #{html_path}" ) do |stdin, stdout, pid|
begin
stdin.each { |line| print line }
rescue Errno::EIO => e
puts "Error: #{e.to.s}"
return 1
end
end
rescue PTY::ChildExited
puts 'Child process exit!'
end
# find out if there were any errors
html = open(html_path).read
examples = html.match(/(\d+) examples/)[0].to_i rescue 0
errors = html.match(/(\d+) errors/)[0].to_i rescue 0
if errors == 0 then
errors = html.match(/(\d+) failure/)[0].to_i rescue 0
end
pending = html.match(/(\d+) pending/)[0].to_i rescue 0
if errors.zero?
puts "0 failed! #{examples} run, #{pending} pending"
sleep 1
exit 0
else
puts "\aCOMMIT FAILED!!"
puts "View your rspec results at #{File.expand_path(html_path)}"
puts
puts "#{errors} failed! #{examples} run, #{pending} pending"
exit 1
end