forked from flyerhzm/rails_best_practices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.watchr.example
65 lines (55 loc) · 1.16 KB
/
.watchr.example
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
65
# vim:set filetype=ruby:
def growl
title = "Watchr Test Results"
image = $?.success? ? "~/.watchr/images/passed.png" : "~/.watchr/images/failed.png"
message = $?.success? ? "success" : "failed"
growlnotify = `which growlnotify`.chomp
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
end
def run(cmd)
puts cmd
system(cmd)
end
def spec(file)
if File.exists?(file)
run("rspec #{file}")
growl
else
puts("Spec: #{file} does not exist.")
end
end
def run_all_specs
run "rake spec"
growl
end
def run_suite
system "clear"
run_all_specs
end
watch("spec/.*/*_spec\.rb") do |match|
puts(match[0])
spec(match[0])
end
watch("lib/(.*/.*)\.rb") do |match|
puts(match[1])
spec("spec/#{match[1]}_spec.rb")
end
# Ctrl-\
Signal.trap 'QUIT' do
puts " --- Running all tests ---\n\n"
run_suite
end
# Ctrl-C
Signal.trap 'INT' do
if @interrupted then
abort("\n")
else
puts "Interrupt a second time to quit"
@interrupted = true
Kernel.sleep 1.5
# raise Interrupt, nil # let the run loop catch it
run_suite
@interrupted = false
end
end