Skip to content

Instantly share code, notes, and snippets.

@tacomanator
Created May 12, 2012 17:49
Show Gist options
  • Save tacomanator/2667886 to your computer and use it in GitHub Desktop.
Save tacomanator/2667886 to your computer and use it in GitHub Desktop.
Autotest runner for use with Minitest/Spork/Growl/fsevent. Starts Spork if it's not already running.
require 'socket'
require 'timeout'
def is_port_open?(ip, port)
begin
Timeout::timeout(1) do
begin
s = TCPSocket.new(ip, port)
s.close
return false
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
return true
end
end
rescue Timeout::Error
end
return true
end
if is_port_open?('localhost', 8988)
spawn "spork"
puts "waiting for spork to start"
while is_port_open?('localhost', 8988) do sleep 0.1 end
end
require 'autotest/restart'
require 'autotest/growl'
require 'autotest/fsevent'
require 'turn/autorun'
Autotest.add_hook :initialize do |at|
at.testlib = ".minitest"
end
Autotest.add_hook :all_good do |at|
system "rake rcov_info"
end if ENV['RCOV']
class Autotest
# run tests over drb server (spork)
def make_test_cmd files_to_test
if files_to_test.empty?
"" # no tests to run
else
"testdrb #{files_to_test.keys.join(' ')}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment