forked from Agilefreaks/Aquarium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rspec.watchr
executable file
·60 lines (52 loc) · 1.28 KB
/
rspec.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env watchr
# Run me with:
#
# $ watchr rspec.watchr
# --------------------------------------------------
# Convenience Methods
# --------------------------------------------------
def all_test_files
Dir['spec/**/*_spec.rb']
end
def run_test_matching(thing_to_match)
matches = all_test_files.grep(/#{thing_to_match}/i)
if matches.empty?
run_all_tests
else
run matches.join(' ')
end
end
def run(files_to_run)
puts("Running: #{files_to_run}")
system("clear;rspec -cfs #{files_to_run}")
no_int_for_you
end
def run_all_tests
run(all_test_files.join(' '))
end
#
# --------------------------------------------------
# Watchr Rules
# --------------------------------------------------
watch('^spec/(.*)_spec\.rb' ) { |m| run_test_matching(m[1]) }
watch('^lib/(.*)\.rb' ) { |m| run_test_matching(m[1]) }
watch('^spec/spec_helper\.rb') { run_all_tests }
# --------------------------------------------------
# Signal Handling
# --------------------------------------------------
def no_int_for_you
@sent_an_int = nil
end
Signal.trap 'INT' do
if @sent_an_int then
puts " Shutting down now."
exit
else
puts " Hit ^C again to exit."
@sent_an_int = true
Kernel.sleep 1.5
run_all_tests
end
end
run_all_tests
# vim:ft=ruby