-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuardfile
112 lines (85 loc) · 2.02 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
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
111
112
# -*- encoding : utf-8 -*-
clearing :on
require 'guard/compat/plugin'
# rubocop:disable Style/ClassAndModuleChildren
module ::Guard
class Subledger < Plugin
def initialize _options_ = { }
super
end
def start
run_all
true
end
def stop
true
end
def reload
exec 'bundle exec rake guard'
end
def run_all
throw_on_failed_tests { system 'rake' }
end
def run_on_additions _pathnames_
true
end
def run_on_modifications pathnames
pathnames.each do |pathname|
throw_on_failed_tests do
handle pathname
end
end
true
end
def run_on_removals _pathnames_
run_all
end
private
def throw_on_failed_tests
throw :task_has_failed unless yield
true
end
def spec_prefix_for pathname
pathname
.match(
%r{^(lib/(.+/)?[^/]+)[.](rb|spec)$}
)[1]
end
def spec_pathname_for pathname
return pathname if pathname =~ /[.]spec$/
spec_prefix_for(pathname) + '.spec'
end
def not_applicable? pathname
pathname =~ /spec_helper/
end
def handle pathname
return if not_applicable? pathname
handle_unit_spec_for pathname
handle_integration_spec_for pathname
handle_lint_for pathname
end
def handle_unit_spec_for pathname
spec_pathname = spec_pathname_for pathname
if File.exist? spec_pathname
system "bundle exec rake spec:unit TEST=#{spec_pathname}"
else
puts "#{pathname} is missing spec #{spec_pathname}"
end
end
def handle_integration_spec_for pathname
return unless pathname =~ /^spec/
system 'bundle exec rake spec:integration ' \
"TEST=#{spec_pathname_for pathname}"
end
def handle_lint_for pathname
system "bundle exec rake lint:file TEST=#{pathname}"
end
end
end
guard :subledger do
watch 'Gemfile' do
system 'bundle update'
nil
end
watch %r{(lib|spec)/(.+)[.](rb|spec)$}
end