-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guardfile
123 lines (92 loc) · 2.78 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
113
114
115
116
117
118
119
120
121
122
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'sprockets'
guard 'yard' do
watch(%r{lib/.+\.rb})
end
# for the grapher
guard 'coffeescript',
:input => 'lib/rrd-grapher/assets/javascripts',
:output => 'lib/rrd-grapher/public/javascripts'
guard 'coffeescript',
:input => 'spec/javascripts/source',
:output => 'spec/javascripts'
guard 'sprockets', :destination => "lib/rrd-grapher/public/javascripts" do
watch (%r{lib/rrd-grapher/assets/javascripts/app.js})
watch (%r{lib/rrd-grapher/assets/javascripts/app-dev.js})
end
guard 'livereload', :apply_js_live => false do
watch(%r{^spec/javascripts/.+\.js$})
watch(%r{^lib/rrd-grapher/public/javascripts/.+\.js$})
watch(%r{^lib/rrd-grapher/views/stylesheets/.+\.scss$})
end
require 'bacon'
require 'guard/guard'
module ::Guard
class Bacon < Guard
def initialize(watchers=[], options={})
super
::Bacon.extend(::Bacon::TestUnitOutput)
end
def start
puts "Guard::Bacon started."
true
end
# Called on Ctrl-C signal (when Guard quits)
def stop
true
end
# Called on Ctrl-Z signal
def reload
true
end
# Called on Ctrl-\ signal
# This method should be principally used for long action like running all specs/tests/...
def run_all
true
end
SPEC_FILE ||= /_spec\.rb$/.freeze
FILE_REG ||= %r{^lib/rrd-grapher/(?:[^/]+/)?(.*)\.rb$}.freeze
def run_spec(path)
if File.exists?(path)
pid = Kernel.fork do
puts " *** Running spec: #{path} ***"
counters = ::Bacon.run_file(path)
# system "bundle exec bacon -o TestUnit #{path}"
# {:installed_summary=>1, :specifications=>19, :depth=>0, :requirements=>30, :failed=>2}
all_specs = counters[:specifications]
failed = counters[:failed]
if counters[:failed] > 0
Notifier.notify("Specs: #{failed} Failures (#{all_specs} specs)",
:image => :failed,
:title => File.basename(path)
)
else
Notifier.notify("Specs: OK (#{all_specs} specs)",
:image => :success,
:title => File.basename(path)
)
end
end
Process.wait(pid)
end
end
def file_changed(path)
case
when path =~ SPEC_FILE then run_spec(path)
when path =~ FILE_REG then run_spec("spec/unit/#{$1}_spec.rb")
end
puts ""
end
# Called on file(s) modifications
def run_on_change(paths)
paths.each do |path|
file_changed(path)
end
end
end
end
guard 'bacon' do
watch(%r{^spec/([^/]/)?.*_spec.rb$})
watch(%r{^lib/rrd-grapher/(?:[^/]+/)?(.*)\.rb$})
end