-
Notifications
You must be signed in to change notification settings - Fork 2
/
specs.watchr
48 lines (39 loc) · 1.43 KB
/
specs.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
40
41
42
43
44
45
46
47
48
# Run me with:
# $ watchr specs.watchr
# --------------------------------------------------
# Rules
# --------------------------------------------------
watch( '^spec.*/.*_spec\.rb' ) { |m| ruby m[0] }
watch( '^lib(.*)/(.*?)\.rb' ) { |m| ruby "spec#{m[1]}/#{m[2]}_spec.rb" }
watch( '^spec/spec_helper\.rb' ) { ruby specs }
watch( '^samples/(.*/)?(.*?)\.rb' ) { |m| cuke "features/#{m[2]}.feature" }
watch( '^features/.*\.feature' ) { |m| cuke m[0] }
watch( '^features/support/.*' ) { |m| cuke features }
watch( '^features/step_definitions/.*' ) { |m| cuke features }
# --------------------------------------------------
# Signal Handling
# --------------------------------------------------
Signal.trap('QUIT') { ruby specs; cuke features } # Ctrl-\
Signal.trap('INT' ) { abort("\n") } # Ctrl-C
# --------------------------------------------------
# Helpers
# --------------------------------------------------
def ruby(*paths)
run "ruby #{gem_opt} -I.:lib:spec -e'%w( #{paths.flatten.join(' ')} ).each {|p| require p }'"
end
def cuke(*paths)
run "cucumber --format progress #{paths.flatten.join(' ')}"
end
def specs
Dir['spec/**/*_spec.rb']
end
def features
Dir['features/**/*.feature']
end
def run( cmd )
puts cmd
system cmd
end
def gem_opt
defined?(Gem) ? "-rubygems" : ""
end