-
Notifications
You must be signed in to change notification settings - Fork 16
/
Guardfile
30 lines (25 loc) · 1.14 KB
/
Guardfile
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
guard 'zeus' do
# When a spec file changes, run it
watch(%r{^spec/.+_spec\.rb$})
# When a file in app/ changes
watch(%r{^app/(.+)\.rb$}) { |m| file_if_exists(m[1]) }
# When a file in lib/ changes
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
# When a file in app/controllers/ changes
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| controller_files(m[1]) }
end
def controller_files(resource)
files = [
"spec/controllers/#{resource}_controller_spec.rb", # appropriate controller spec
"spec/requests/#{resource}/", # all files in director of same name in spec/requests/
"spec/requests/#{resource}_request_spec.rb", # single file of same name in spec/requests/
"spec/acceptance/#{resource}_acceptance_spec.rb" # appropriate acceptance spec
]
existing_files = files.select { |file| file if File.exists?(file) }
puts "Running these files:\n #{existing_files}"
existing_files
end
def file_if_exists(capture)
filename = "spec/#{capture}_spec.rb"
File.exists?(filename) ? filename : nil
end