Created
November 23, 2009 15:47
-
-
Save jeremy6d/241135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a project specific .autotest file that allows me to run the tests for the Community Engine plugin when I override classes in my main project. This way, I know anytime my social networking site breaks core CE functionality. The PLUGIN_TEST_TO_IGNORE array keeps track of CE features whose tests will break because I've cut off routes to them or disabled them in some way. The goal is to keep CE pristine in the vendor directory, make all changes to the parent app, and use autotest to catch any errors I introduce. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLUGIN_PATH = "vendor/plugins/community_engine/" | |
PLUGIN_TESTS_TO_IGNORE = ["functional/skills_controller_test.rb", | |
"functional/posts_controller_test.rb"].collect { |t| "#{PLUGIN_PATH}test/#{t}"} | |
Autotest.add_hook :initialize do |at| | |
at.clear_exceptions | |
at.clear_mappings | |
%w{.git .svn stories tmtags Rakefile Capfile README spec/spec.opts spec/rcov.opts vendor/gems autotest svn-commit .DS_Store }.each do |exception| | |
at.add_exception(exception) | |
end | |
at.add_exception %r%^\./(?:db|doc|log|public|script|tmp)% | |
at.add_exception %r%^#{PLUGIN_PATH}(?:app|config|db|generators|lang|lib|plugins|public|sample_files|tasks)% | |
at.add_mapping %r%^test/(unit|integration|controllers|views|functional)/.*rb$% do |filename, _| | |
# [filename, File.join(PLUGIN_PATH, filename)] | |
include_plugin_tests_in_array [filename] | |
end | |
at.add_mapping %r%^app/models/(.*)\.rb$% do |_, m| | |
include_plugin_tests_in_array ["test/unit/#{m[1]}_test.rb"] | |
end | |
at.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m| | |
if m[1] == "application" then | |
include_plugin_tests_in_regexps(at, %r%^test/(controllers|views|functional)/.*_test\.rb$%) | |
else | |
include_plugin_tests_in_array ["test/functional/#{m[1]}_test.rb"] | |
end | |
end | |
at.add_mapping %r%^app/helpers/application_helper.rb% do | |
include_plugin_tests_in_regexps(at, %r%^test/(views|functional)/.*_test\.rb$%) | |
end | |
at.add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m| | |
if m[1] == "application" then | |
include_plugin_tests_in_regexps at, %r%^test/(views|functional)/.*_test\.rb$% | |
else | |
include_plugin_tests_in_array ["test/views/#{m[1]}_view_test.rb", | |
"test/functional/#{m[1]}_controller_test.rb"] | |
end | |
end | |
at.add_mapping %r%^app/views/(.*)/% do |_, m| | |
include_plugin_tests_in_array ["test/views/#{m[1]}_view_test.rb", | |
"test/functional/#{m[1]}_controller_test.rb"] | |
end | |
at.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m| | |
if m[1] == "application" then | |
include_plugin_tests_in_regexps at, %r%^test/(controllers|views|functional)/.*_test\.rb$% | |
else | |
include_plugin_tests_in_array [ "test/controllers/#{m[1]}_test.rb", | |
"test/functional/#{m[1]}_test.rb" ] | |
end | |
end | |
at.add_mapping %r%^app/views/layouts/% do | |
include_plugin_tests_in_array ["test/views/layouts_view_test.rb"] | |
end | |
at.add_mapping %r%^config/routes.rb$% do # FIX: | |
include_plugin_tests_in_regexps at, %r%^test/(controllers|views|functional)/.*_test\.rb$% | |
end | |
at.add_mapping %r%^test/test_helper.rb|config/((boot|environment(s/test)?).rb|database.yml)% do | |
include_plugin_tests_in_regexps at, %r%^test/(unit|controllers|views|functional)/.*_test\.rb$% | |
end | |
end | |
def include_plugin_tests_in_regexps(autotest_variable, regexp) | |
results = [] | |
results << autotest_variable.files_matching(regexp) | |
new_regexp = Regexp.new(regexp.to_s.gsub("^", "^#{PLUGIN_PATH}")) | |
results << autotest_variable.files_matching(new_regexp) | |
filter_out_excluded_tests results | |
end | |
def include_plugin_tests_in_array(array) | |
plugin_array = array.collect { |path| File.join(PLUGIN_PATH, path) } | |
filter_out_excluded_tests (array + plugin_array) | |
end | |
def filter_out_excluded_tests(test_paths) | |
test_paths.flatten.uniq.reject { |r| PLUGIN_TESTS_TO_IGNORE.include? r } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment