Autotest.add_hook :initialize do |autotest|
autotest.clear_exceptions
autotest.clear_mappings
autotest.add_exception %r%^\./(?:doc|log|public|script|tmp|vendor)%
%w{.svn .hg .git}.each {|exception| autotest.add_exception(exception)}
helper = AutotestUnitRecord.new(autotest, ENV)
helper.setup_autotest
end
class AutotestUnitRecord
attr_accessor :autotest, :run_mode
def initialize(autotest, environment)
@autotest = autotest
@run_mode = (environment["AUTOTEST"] == "functional") ? :functional : :unit
end
def any_matching_tests(class_file)
autotest.files_matching %r%^test/#{run_mode}/?(models|controllers|helpers)?/?#{class_file}s?(_view|_helper|_controller)?_test\.rb$%
# ["test/#{run_mode}/models/#{class_file}s?_test.rb",
# "test/#{run_mode}/controllers/#{class_file}s?_controller_test.rb",
# "test/#{run_mode}/views/#{class_file}s?_view_test.rb"]
end
def all_tests autotest
autotest.files_matching %r%^test/#{run_mode}/.*_test\.rb$%
end
def setup_autotest
puts "Running autotest for #{run_mode} tests in a unit_record app."
autotest.add_mapping(%r%^test/fixtures/(.*)s.yml%) { |_, m|
any_matching_tests(m[1])
}
autotest.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
impl = File.basename(filename, '.rb')
any_matching_tests(impl)
end
autotest.add_mapping %r%^test/fixtures/(.*)s.yml% do |_, m|
any_matching_tests(m[1])
end
autotest.add_mapping %r%^test/#{run_mode}/.*rb$% do |filename, _|
filename
end
autotest.add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
any_matching_tests(m[1])
end
autotest.add_mapping %r%^app/helpers/application_helper.rb% do
autotest.files_matching %r%^test/#{run_mode}/helpers/.*_test\.rb$%
end
autotest.add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m|
if m[1] == "application" then
autotest.files_matching %r%^test/#{run_mode}/helpers/.*_test\.rb$%
else
autotest.files_matching %r%^test/#{run_mode}/helpers/#{m[1]}_helper_test\.rb$%
end
end
autotest.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
if m[1] == "application" then
autotest.files_matching %r%^test/#{run_mode}/controllers/.*_test\.rb$%
else
autotest.files_matching %r%^test/#{run_mode}/controllers/#{m[1]}_test\.rb$%
end
end
autotest.add_mapping %r%^config/routes.rb$% do # FIX:
autotest.files_matching %r%^test/controllers/.*_test\.rb$%
end
autotest.add_mapping %r%^test/.*test_helper.rb|db/example_data.rb|config/((boot|environment(s/test)?).rb|database.yml)% do
all_tests autotest
end
end
end