-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautotest_watchr.rb
59 lines (47 loc) · 1.34 KB
/
autotest_watchr.rb
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
# gem install watchr
# Command to run this: watchr /path/to/file/autotest_watchr.rb
#####
system %(echo "Running autotest_watchr.rb")
#####
# Watch the classes folder for changes
# If there's a change to a class, look for it's corresponding Test file.
# Ex if Shopper.php changes, it'd run the test on ShopperTest.php in tests folder
watch("classes/(.*).php") do |match|
run_test %{tests/#{match[1]}Test.php}
end
#####
# Also watch for changes to the test files
watch("tests/.*Test.php") do |match|
run_test match[0]
end
def run_test(file)
clear_console
# First, make sure the file exists
unless File.exist?(file)
puts "#{file} does not exist"
return
end
# Now run the PHPUnit test on the file
puts "Running #{file}"
result = `phpunit #{file}`
puts result
if result.match(/OK/)
notify "#{file}", "Tests Passed Successfuly", "dialog-information.png", 4000
elsif result.match(/FAILURES\!/)
notify_failed "#{file}", "#{result}"
end
end
###
def notify_failed cmd, result
failed_examples = result.scan(/failures:\n\n(.*)\n/)
notify "#{cmd}", failed_examples[0], "dialog-error.png", 6000
end
###
def notify title, msg, img, show_time
images_dir='/usr/share/icons/Mint-X/status/48'
system "notify-send '#{title}' '#{msg}' -i #{images_dir}/#{img} -t #{show_time}"
end
#####
def clear_console
puts "\e[H\e[2J"
end