-
Notifications
You must be signed in to change notification settings - Fork 18
/
.watchr.rb
41 lines (34 loc) · 1.12 KB
/
.watchr.rb
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
def all_specs
"spec/models/ spec/lib/ spec/integration/"
end
trap 'INT' do
if $interrupted
exit! 0
else
puts "Interrupt a second time to quit"
$interrupted = true
sleep 1.5
$interrupted = false
run_spec(all_specs)
end
end
def run_spec(file)
return unless file.include?(" ") || File.exist?(file)
puts "Running specs..."
system("spec -f nested -c #{file}")
end
def run_test(file)
return unless file.include?(" ") || File.exist?(file)
puts "Running test..."
system("ruby #{file}")
end
watch( '^lib/(.*)\.rb' ) {|md| run_spec("spec/lib/#{md[1]}_spec.rb") }
watch( '^app/models/(.*)\.rb' ) {|md| run_spec("spec/models/#{md[1]}_spec.rb") }
watch( '^app/controllers/(.*)\.rb' ) {|md| run_spec(all_specs) }
watch( '^app/views/(.*)\.erb' ) {|md| run_spec(all_specs) }
watch( '^app/helpers/(.*)\.rb' ) {|md| run_spec(all_specs) }
watch( '^config/.*' ) {|md| run_spec(all_specs) }
watch( '^spec/.*\.rb' ) {|md| run_spec(md[0]) }
watch( '^spec/support/.*' ) { |md| run_spec(all_specs) }
watch( '^spec/spec_helper.rb' ) { |md| run_spec(all_specs) }
watch( '^test/unit/.*_test\.rb' ) {|md| run_test(md[0]) }