forked from padrino/padrino-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.watchr
69 lines (59 loc) · 1.9 KB
/
test.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
#
# install watchr
# $ sudo gem install watchr
#
# Run With:
# $ watchr test.watchr
#
# --------------------------------------------------
# Helpers
# --------------------------------------------------
def run(path, file)
return unless File.exists?(File.join(path, "test/", file))
cmd = "ruby -I\"lib:test\" test/#{file}"
puts(cmd)
Dir.chdir(path){ system(cmd) }
end
def run_all_tests
system("rake test")
end
def sudo(cmd)
run("sudo #{cmd}")
end
def base_name(file)
File.basename(file,'.rb').gsub(/\-/, '_')
end
# --------------------------------------------------
# Watchr Rules
# --------------------------------------------------
# Padrino-Admin
watch("^padrino-admin/(.*)") do |m|
if m[1] =~ /generators/
run("padrino-admin", "generators/test_#{base_name(m[1])}_generator.rb")
else
run("padrino-admin", "test_admin_application.rb")
end
end
# Padrino-Cache
watch("^padrino-cache.*/(.*)\.rb") { |m| run("padrino-cache", "test_#{base_name(m[1])}.rb")}
# Padrino-Core
watch("^padrino-core.*/(.*)\.rb") { |m| run("padrino-core", "test_#{base_name(m[1])}.rb")}
# Padrino-Gen
watch("^padrino-gen/lib/padrino-gen/generators/cli.rb") { |m| run("padrino-gen", "test_cli.rb") }
watch("^padrino-gen/lib/padrino-gen/generators/(.*)\.rb") { |m| run("padrino-gen", "test_#{base_name(m[1])}_generator.rb")}
# Padrino-Helpers
watch("^padrino-helpers/lib/padrino-helpers/(.*)\.rb") { |m| run("padrino-helpers", "test_#{base_name(m[1])}.rb")}
# Padrino-Mailer
watch("^padrino-mailer/lib/padrino-mailer/(.*)\.rb") { |m| run("padrino-mailer", "test_#{base_name(m[1])}.rb")}
# Any tests in test folder.
watch("^(.*)/test/test_(.*)") { |m| run(m[1], "test_#{m[2]}") }
# --------------------------------------------------
# Signal Handling
# --------------------------------------------------
# Ctrl-\
Signal.trap('QUIT') do
puts " --- Running all tests ---\n\n"
run_all_tests
end
# Ctrl-C
Signal.trap('INT') { abort("\n") }