-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGuardfile
74 lines (64 loc) · 2.01 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
require 'guard/rspec'
module ::Guard
class RSpec < Plugin
# Add `stop` method if not defined
# so that `stop_*` callbacks work.
unless instance_methods.include?(:stop)
def stop; end
end
end
module ServicesGemHelpers
SPEC_SUPPORT_DIR = Pathname.new(File.expand_path('../spec/support', __FILE__))
REDIS_BIN = SPEC_SUPPORT_DIR.join('redis-server')
REDIS_CLI = SPEC_SUPPORT_DIR.join('redis-cli')
REDIS_PIDFILE = SPEC_SUPPORT_DIR.join('redis.pid')
REDIS_LOGFILE = SPEC_SUPPORT_DIR.join('log', 'redis.log')
REDIS_PORT = 6379
def self.options_to_string(options)
options.map { |k, v| "-#{'-' if k.length > 1}#{k} #{v}" }.join(' ')
end
class OnStart
def call(guard_class, event, *args)
options = {
daemonize: 'yes',
dir: SPEC_SUPPORT_DIR,
dbfilename: 'redis.rdb',
logfile: REDIS_LOGFILE,
pidfile: REDIS_PIDFILE,
port: REDIS_PORT
}
system "#{REDIS_BIN} #{ServicesGemHelpers.options_to_string options}"
i = 0
while !File.exist?(REDIS_PIDFILE)
puts 'Waiting for Redis to start...'
sleep 1
i += 1
raise "Redis didn't start in #{i} seconds." if i >= 5
end
end
end
class OnStop
def call(guard_class, event, *args)
options = {
p: REDIS_PORT
}
system "#{REDIS_CLI} #{ServicesGemHelpers.options_to_string options} shutdown"
i = 0
while File.exist?(REDIS_PIDFILE)
puts 'Waiting for Redis to stop...'
sleep 1
i += 1
raise "Redis didn't stop in #{i} seconds." if i >= 5
end
end
end
end
end
guard 'rspec', cmd: 'bundle exec appraisal rspec' do
callback ServicesGemHelpers::OnStart.new, :start_begin
callback ServicesGemHelpers::OnStop.new, :stop_begin
# Specs
watch(%r(^spec/.+_spec\.rb$))
# Files
watch(%r(^lib/(.+)\.rb$)) { "spec/#{_1[1]}_spec.rb" }
end