forked from airhorns/rbacanable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specs.watchr
47 lines (39 loc) · 978 Bytes
/
specs.watchr
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
def growl(title, msg, img)
%x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
end
def form_growl_message(str)
results = str.split("\n").last
if results =~ /[1-9]\s(failure|error)s?/
growl "Test Results", "#{results}", "fail"
elsif results != ""
growl "Test Results", "#{results}", "pass"
end
end
def run(cmd)
puts(cmd)
output = ""
IO.popen(cmd) do |com|
com.each_char do |c|
print c
output << c
$stdout.flush
end
end
form_growl_message output
end
def run_test_file(file)
run %Q(ruby -I"lib:test" -rubygems #{file})
end
def run_all_tests
run "rake test"
end
watch('test/helper\.rb') { system('clear'); run_all_tests }
watch('test/test_.*\.rb') { |m| system('clear'); run_test_file(m[0]) }
watch('lib/.*') { |m| system('clear'); run_all_tests }
# Ctrl-\
Signal.trap('QUIT') do
puts " --- Running all tests ---\n\n"
run_all_tests
end
# Ctrl-C
Signal.trap('INT') { abort("\n") }