-
Notifications
You must be signed in to change notification settings - Fork 138
/
tests.watchr
39 lines (32 loc) · 1.07 KB
/
tests.watchr
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
# Run me with:
# $ watchr tests.watchr
# --------------------------------------------------
# Rules (n.b. were simply just running all tests)
# --------------------------------------------------
# if we edit main lib files
watch( '^lib/.*.rb' ) { ruby all_tests }
# if we edit Gemfile or Gemspec.
watch( '^(Gemfile*|resque-retry.gemspec)' ) { ruby all_tests }
# if we edit any test related files.
watch( '^test/(.*).rb' ) { |m| ruby m[0] }
# --------------------------------------------------
# Signal Handling
# --------------------------------------------------
Signal.trap('QUIT') { ruby all_tests } # Ctrl-\
Signal.trap('INT' ) { abort("\n") } # Ctrl-C
# --------------------------------------------------
# Helpers
# --------------------------------------------------
def ruby(*paths)
run "bundle exec ruby #{gem_opt} -I.:lib:test -e'%w( #{paths.flatten.join(' ')} ).each { |p| require p }'"
end
def all_tests
Dir['test/*_test.rb']
end
def run(cmd)
puts cmd
system cmd
end
def gem_opt
defined?(Gem) ? '-rubygems' : ''
end