-
Notifications
You must be signed in to change notification settings - Fork 14
/
.autotest
65 lines (60 loc) · 2.34 KB
/
.autotest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'autotest/restart'
# Initialize autotest with our mapping rules
Autotest.add_hook :initialize do |at|
at.find_directories = ['actors', 'agents', 'lib']
at.clear_mappings
at.add_mapping(/.*\/lib\/.*\.rb$/) do |filename, _|
at.files_matching(/.*\/spec\/.*\/?#{File.basename(filename, '.rb')}_spec.rb$/)
end
end
# Hook for enabling rcov when requested
Autotest.add_hook :all_good do |at|
system "rake rcov_info"
end if ENV['RCOV']
# Hook for notifying user with test results
Autotest.add_hook :ran_command do |autotest|
results = [autotest.results].flatten.join("\n")
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
if output =~ /[1-9]\sfailures?/
notify(output, :failure)
elsif output =~ /[1-9]\spending?/
notify(output, :pending)
else
notify(output, :success)
end
end
# Notify user of results, use platform specific notification mechanism
# (growl on Max OS X, notify-send on Ubuntu)
#
# === Parameters
# msg<String>:: Notification message
# status<Symbol>:: One of :success, :pending or :failure
def self.notify(msg, status)
@has_growl ||= system('which growlnotify')
@has_notify ||= system('which notify-send')
@success_png ||= @has_notify ? 'gtk-dialog-info' : File.join(File.dirname(__FILE__), 'spec', 'autotest', 'success.png')
@pending_png ||= @has_notify ? 'gtk-dialog-info' : File.join(File.dirname(__FILE__), 'spec', 'autotest', 'pending.png')
@failure_png ||= @has_notify ? 'gtk-dialog-error' : File.join(File.dirname(__FILE__), 'spec', 'autotest', 'failure.png')
title = case status
when :success then 'PASS'
when :pending then 'PENDING'
when :failure then 'FAIL'
end
cmd = ''
if @has_growl
cmd = 'growlnotify -n autotest --image '
cmd += case status
when :success then "#{@success_png} -p 0 -m #{msg.inspect} #{title}:"
when :pending then "#{@pending_png} -p 2 -m #{msg.inspect} #{title}:"
when :failure then "#{@failure_png} -p 2 -m #{msg.inspect} #{title}:"
end
elsif @has_notify
cmd = 'notify-send -i '
cmd += case status
when :success then "'#{@success_png}' -u 'low' -t 5000 '#{title}: #{msg}'"
when :pending then "'#{@pending_png}' -u 'normal' -t 5000 '#{title}: #{msg}'"
when :failure then "'#{@failure_png}' -u 'critical' -t 10000 '#{title}: #{msg}'"
end
end
system cmd unless cmd.empty?
end