-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.watchr
55 lines (50 loc) · 1.52 KB
/
.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
49
50
51
52
53
54
55
LINUX = RUBY_PLATFORM =~ /linux/i unless defined?(LINUX)
def escape(arg)
arg.gsub(/\e\[..m?/, '') # rid us of ansi escape sequences
.gsub(/["`]/, "'")
.gsub(/\r?\n/, "\\\\\\\\\\n")
end
def notify(pass, heading, body='')
cmd = if LINUX
%(notify-send --hint=int:transient:1 "#{escape heading}" "#{escape body[0..400]}")
else
if pass
icon = ''
else
icon = '-contentImage /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns'
end
%(terminal-notifier -message "#{escape body}" -title "#{escape heading}" #{icon})
end
system(cmd)
end
def run_specs(test, force=false)
if force || File.exist?(test)
puts "-" * 80
rspec_cmd = "rspec --color --tty"
puts "#{rspec_cmd} #{test}"
cmd = IO.popen("#{rspec_cmd} #{test} 2>&1")
result = ''
until cmd.eof?
char = cmd.getc
result << char
$stdout.write(char)
end
if result =~/.*0 failures/
summary = $~.to_s
secs = result.match(/Finished in ([\d\.]+)/)[1]
notify(true, 'Test Success', summary + ' ' + secs)
elsif result =~ /(\d+) failures?/
summary = $~.to_s
notify(false, 'Test Failure', summary)
else
notify(false, 'Test Error', 'One or more tests could not run due to error.')
end
else
puts "#{test} does not exist."
end
end
def run_suite
run_specs('test/*', :force)
end
watch('^spec/(.*)_spec\.rb') { |m| run_specs("spec/#{m[1]}_spec.rb") }
watch('^lib/(.*)\.rb' ) { |m| run_specs("spec/#{m[1]}_spec.rb") }