-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuardfile
More file actions
executable file
·110 lines (94 loc) · 3.4 KB
/
Copy pathGuardfile
File metadata and controls
executable file
·110 lines (94 loc) · 3.4 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# More info at https://github.com/guard/guard#readme
require 'colorize'
group :specs, halt_on_fail: true do
guard :rspec, cmd: 'bundle exec rspec' do
watch('spec/spec_helper.rb') { 'spec' }
watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)(\.rb|\.rake)$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
end
guard :shell do
watch(%r{.+\.rb$}) do |m|
res = `rubocop #{m[0]}`
if !res.include? 'no offenses detected'
puts `rubocop #{m[0]}`.red if res.include? 'E:'
puts `rubocop #{m[0]}`.yellow if res.include? 'C:'
puts `rubocop #{m[0]}`.yellow if res.include? 'W:'
end
end
end
end
guard :shell do
watch(/assets\/javascripts\/(.*)\.js$/) do
puts `npm test`
end
watch(/spec\/javascripts\/(.*)\.js$/) do
puts `npm test`
end
watch %r{^app/(.+)\.rb$} do |m|
if `ruby -c #{m[0]}|grep 'Syntax OK'`.length == 0
n "#{m[0]} is incorrect", 'Ruby Syntax', :failed
`ruby -c #{m[0]}`
end
end
watch %r{^lib/tasks/(.+)\.rake$} do |m|
if `ruby -c #{m[0]}|grep 'Syntax OK'`.length == 0
n "#{m[0]} is incorrect", 'Ruby Syntax', :failed
`ruby -c #{m[0]}`
end
end
watch %r{^app/(.+)\.rb$} do |m|
if `fgrep "awesome_print" #{m[0]}`.length > 0
n "#{m[0]} includes awesome_print", 'Ruby Syntax', :failed
print "remove awesome_print from #{m[0]}".yellow
end
end
watch %r{^spec/(.+)\.rb$} do |m|
if `fgrep "xit " #{m[0]}`.length > 0
n "#{m[0]} disabled test", 'RSpec', :failed
print "\nfound xit: enable test in #{m[0]}".yellow
end
end
watch %r{^spec/javascripts/(.+)\.js$} do |m|
if `fgrep "xit(" #{m[0]}`.length > 0
n "#{m[0]} disabled test", 'Jasmine', :failed
print "\nfound xit: enable test in #{m[0]}".yellow
end
end
watch %r{^app/(.+)\.rb$} do |m|
if `fgrep "debugger" #{m[0]}`.length > 0
n "#{m[0]} includes debugger", 'Ruby Syntax', :failed
print "remove debugger from #{m[0]}".yellow
end
end
watch(%r{^(.+)\.(orig|LOCAL|REMOTE|BACKUP|BASE)}) do |m|
n "Remove #{m[0]}", 'Git Merge', :failed
print "Remove #{m[0]}".red
end
watch(%r{^app/assets/javascripts/(.+)\.js$}) do |m|
args = '--nomen --plusplus --newcap --vars --indent=2'
if `jslint #{args} #{m[0]}|grep 'is OK.'`.length == 0
n "#{m[0]} is incorrect", 'JavaScript Syntax', :failed
puts `jslint #{args} #{m[0]}`.yellow
end
end
watch(%r{^spec/javascripts/(.*)\.js$}) do |m|
args = '--nomen --plusplus --newcap --vars --indent=2'
if `jslint #{args} #{m[0]}|grep 'is OK.'`.length == 0
n "#{m[0]} is incorrect", 'JavaScript Syntax', :failed
puts `jslint #{args} #{m[0]}`.yellow
end
end
=begin
watch(%r{^app/assets/(.*)\.(.*)css$}) do |m|
if `scss-lint #{m[0]}`.length != 0
n "#{m[0]} is incorrect", 'css Syntax', :failed
`scss-lint #{m[0]}`.yellow
end
end
=end
end