Skip to content

Instantly share code, notes, and snippets.

@raggi
Created July 6, 2011 18:04
Show Gist options
  • Save raggi/1067898 to your computer and use it in GitHub Desktop.
Save raggi/1067898 to your computer and use it in GitHub Desktop.
My oldish .autotest (it's actually .autotest, but gist is teh lame)
module RaggiGrowl
def self.growl title, msg, img = 'alert.png' , pri=0, stick=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
false
end
def self.dir; Dir.pwd; end
def self.good; "~/Library/autotest/god.png"; end
def self.bad; "~/Library/autotest/dead.png"; end
SpecResults = /(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/m
TestUnitResults = /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/m
def self.setup
Autotest.add_hook :ran_command do |autotest|
next false unless autotest.results.size > 0
failed = case
when results = autotest.results.join("\n")[TestUnitResults]
tests, assertions, failures, errors = $1, $2, $3, $4
(failures.to_i + errors.to_i) > 0
when results = autotest.results.join("\n")[SpecResults]
tests, failures, pending = $1, $2, $3
failures.to_i > 0
else
true
end
growl failed ? "Fail" : "Pass", results, failed ? bad : good
end
Autotest.add_hook :initialize do |att|
growl "autotest", "starting up in #{dir}", good, 10
end
Autotest.add_hook :run do |at|
growl "autotest", "running in #{dir}", good, 10
end
Autotest.add_hook :interrupt do |at|
growl "autotest", "interrupted in #{dir}", bad, 10
end
Autotest.add_hook :quit do |at|
growl "autotest", "quit in #{dir}", bad, 10
end
end
end
RaggiGrowl.setup
general_exceptions = [
/^\.\/log/,
/^\.\/doc/,
/^\.\/script/,
/^\.\/vendor/,
/^\.\/public/,
/^\.\/tmp/,
/\.svn/,
/\.git/
]
Autotest.add_hook :initialize do |att|
att.testlib = 'minitest/autorun'
def att.consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |test, klass|
f = klass.gsub(/[a-z][A-Z]/) { |c| "#{c[0,1]}_#{c[-1,1]}" }
f = f.downcase + '.rb'
test_files = self.find_order.grep(Regexp.new(Regexp.escape(f)))
warn "No mapping found for #{klass}##{test}" if test_files.empty?
test_files.each do |test_file|
filters[test_file] << test
end
end
filters
end
general_exceptions.each do |except|
att.add_exception except
end
att.add_mapping(%r%^test/test\.rb$%) do |filename, _|
att.files_matching(%r%^test/.*test_.*\.rb$%)
end
# att.add_mapping(%r%^(test|spec)/(.*\.rb)$%) do |filename, _|
# fn = _.captures[1]
# dir = File.dirname(fn)
# file = File.basename(fn)
# file.sub!(/(test|spec)_/, '')
# puts "#{filename} => #{att.files_matching(%r%^lib/#{Regexp.escape dir}/#{Regexp.escape file}%)}"
# att.files_matching(%r%^lib/#{Regexp.escape dir}/#{Regexp.escape file}%)
# end
# att.add_mapping(%r%^lib/(.*\.rb)$%) do |filename, m|
# spec = File.basename(m[1], '.rb')
# path = File.dirname(m[1])
# [
# "test/#{path}/test_#{spec}.rb",
# "test/#{path}/spec_#{spec}.rb",
# "spec/#{path}/spec_#{spec}.rb",
# # TODO : decide if the follow 'rspec style' name should be allowed?
# "spec/#{path}/#{spec}_spec.rb",
# "spec/#{path}/#{spec}_test.rb"
# ]
# end
end
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils
def ep(f)
File.expand_path(f)
end
def inst(s, d, o = { :verbose => true })
mkdir_p File.dirname(d)
install s, d, o
end
inst 'autotest.rb', ep('~/.autotest'), :verbose => true
inst 'dead.png', ep('~/Library/autotest/dead.png'), :verbose => true
inst 'god.png', ep('~/Library/autotest/god.png'), :verbose => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment