-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.autotest
55 lines (43 loc) · 1.53 KB
/
.autotest
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
require 'autotest/restart'
require 'autotest/bundler'
Autotest.add_hook :initialize do |at|
at.testlib = 'test/unit test/autocolor'
# Remove the old test unit mappings
at.clear_mappings
# Don't track other dirs, this just burns cpu.
(File.read('.gitignore').split("\n") + Dir['test/fixtures/**/*']).each do |ignore|
next if ignore.nil? or ignore.empty?
at.add_exception ignore
end
# Test::Unit is normally test_, so autotest doesn't have this mapping. Tests
# want to match themselves, that is, if there's no changes, run them all.
at.add_mapping(%r%^test/.*_test\.rb$%) { |f, _| f }
# Allow for matches of lib files to test files in a flat way
at.add_mapping(%r%^lib/(.*)\.rb$%) do |f, md|
at.files_matching( %r%^test/#{md[1]}_test\.rb$%)
end
# Make sure that we run all tests if the helper changes:
at.add_mapping(%r%^test/helper\.rb$%) do |f, _|
at.files_matching %r%.*_test\.rb%
end
# If bundle did something, run all tests again
at.add_mapping(%r%^Gemfile\.lock$%) do |f, _|
at.files_matching %r%.*_test\.rb%
end
# If update support, run all tests
at.add_mapping(%r%^test/support/.*\.rb$%) do |f, _|
at.files_matching %r%.*_test\.rb%
end
def at.path_to_classname(path)
file = File.basename(path, '.rb')
file.gsub!('test_', '')
file.gsub!('_test', '')
file.capitalize + 'Test'
end
end
# If the Gemfile gets updated, run bundle install
Autotest.add_hook :updated do |at, *args|
if args.flatten.grep(%r%^Gemfile$|^.*\.gemspec$%).any?
system 'bundle'
end
end