forked from lelylan/rest-oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.watchr.rb
62 lines (50 loc) · 1.1 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# --------------
# Running Spec
# --------------
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
run_spec_cmd(file)
end
def run_spec_cmd(cmd)
puts "Running #{cmd}"
system "bundle exec rspec #{cmd}"
end
# --------------
# Autodetection
# --------------
# Spec tests
watch("spec/.*/*_spec\.rb") do |match|
run_spec match[0]
end
# Models tests
watch("app/models/(.*/.*)\.rb") do |match|
run_spec %{spec/models/#{match[1]}_spec.rb}
end
# Acceptance tests for every controller (not the
# best solution, but it works pretty well)
watch("app/controllers/(.*/.*)\.rb") do |match|
exclusions = ["controllers/application_controller"]
unless exclusions.include? match[1]
run_spec %{spec/acceptance/#{match[1]}_spec.rb}
end
end
# ----------------
# Signal Handling
# ----------------
@second_int = false
# Run acceptance tests (Ctrl-\)
Signal.trap('QUIT') do
run_spec "spec/acceptance/"
end
# Run all tests (Ctrl-c)
Signal.trap 'INT' do
check_exit # exit (double Ctrl-c)
#@second_int = true
run_spec "spec/"
end
def check_exit
exit if @second_int
end