forked from envylabs/vaulted_billing
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.watchr
69 lines (54 loc) · 1.5 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
ENV['WATCHR'] = '1'
require 'open4'
system 'clear'
def growl(message)
message = message.gsub(/\e\[(\d+)m/, '').split("\n").detect { |l| l =~ /\d+ examples?, \d+ failures?/ } # strip bash color codes
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
passed = message =~ /\b0 failure/
image = passed ? "~/.watchr/images/passed.png" : "~/.watchr/images/failed.png"
severity = passed ? 'Very Low' : 'Emergency'
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}' -p '#{severity}'"
system %(#{growlnotify} #{options} &)
end
def run(cmd)
puts cmd
Open4::popen4(cmd) do |pid, stdin, stdout, stderr|
while line = stdout.gets
$stdout.write line
growl line if line =~ /\b\d+ failure/
end
$stderr.write stderr.read
end
end
def run_spec(file)
system 'clear'
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
run "bundle exec rspec --format documentation #{file}"
end
def run_all_specs
system 'clear'
puts "Running all specs"
run "bundle exec rspec --format documentation spec/"
end
watch("spec/.*_spec\.rb") do |match|
run_spec match[0]
end
watch("lib/(.*)\.rb") do |match|
run_spec %{spec/models/#{match[1]}_spec.rb}
end
watch("lib/vaulted_billing/gateways/(.+)\.rb") do |match|
run_spec %{spec/requests/#{match[1]}_spec.rb}
end
watch("spec/(spec_helper|support/.*)\.rb$") do |match|
run_all_specs
end
# Ctrl-\
Signal.trap 'QUIT' do
puts
run_all_specs
end