-
-
Save nathanclark/293012 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
# autotest your engine plugins together with your rails app | |
# put this .autotest file in your rails root | |
# see http://code.whatcould.com/2009/02/09/gentlemen-test-your-engines.html for details | |
# until/unless my changes are pulled into the main streams, | |
# there are a couple requirements: | |
# my autotest fork, http://github.com/whatcould/zentest/tree/master | |
# and for better fixture handling, my engines fork, http://github.com/whatcould/engines/tree/master | |
Autotest.add_hook :initialize do |at| | |
# find all your plugins with an app directory | |
engine_plugins = Dir['vendor/plugins/*'].select{|dir| File.directory?("#{dir}/app")} | |
# this big requires my autotest fork | |
at.extra_test_paths = engine_plugins.map{|p| p + '/test'} | |
# autotest comes with an exception for your vendor; have to get rid of that | |
at.remove_exception(%r%^\./(?:db|doc|log|public|script|tmp|vendor)%) | |
at.add_exception %r%^\./(?:db|doc|log|public|script|tmp)% | |
at.add_exception(/^\.\/vendor\/rails/) | |
at.add_exception(/^\.\/vendor\/gems/) | |
# exceptions for all your non-engine plugins | |
plugin_names = engine_plugins.map{|p| p.sub('vendor/plugins/','')} | |
at.add_exception(%r%vendor/plugins/(?!#{plugin_names.join('|')})%) | |
engine_plugins.each do |plugin_path| | |
at.add_exception("#{plugin_path}/db") | |
# these mirror the mappings in the autotest rails profile | |
# | |
# TODO: these don't account for overriding methods, views, etc in your app | |
# eg, a change in your main app/ doesn't run the corresponding test in the plugin/app | |
at.add_mapping %r%^#{plugin_path}/app/models/(.*)\.rb$% do |_, m| | |
"#{plugin_path}/test/unit/#{m[1]}_test.rb" | |
end | |
at.add_mapping %r%^#{plugin_path}/app/controllers/(.*)\.rb$% do |_, m| | |
["#{plugin_path}/test/controllers/#{m[1]}_test.rb", | |
"#{plugin_path}/test/functional/#{m[1]}_test.rb"] | |
end | |
at.add_mapping %r%^#{plugin_path}/app/helpers/(.*)_helper.rb% do |_, m| | |
["#{plugin_path}/test/views/#{m[1]}_view_test.rb", | |
"#{plugin_path}/test/functional/#{m[1]}_controller_test.rb"] | |
end | |
at.add_mapping %r%^#{plugin_path}/app/views/(.*)/% do |_, m| | |
["#{plugin_path}/test/views/#{m[1]}_view_test.rb", | |
"#{plugin_path}/test/functional/#{m[1]}_controller_test.rb"] | |
end | |
# changes in routes test your app functional tests as well | |
at.add_mapping %r%^#{plugin_path}/config/routes.rb$% do | |
at.files_matching %r%^(#{plugin_path}/)?test/(controllers|views|functional)/.*_test\.rb$% | |
end | |
at.add_mapping %r%^#{plugin_path}/test/(unit|integration|controllers|views|functional)/.*rb$% do |filename, _| | |
filename | |
end | |
end | |
# keeps your fixtures updated in the shared tmp dir. | |
# see rake test:plugins:setup_plugin_fixtures | |
# if you specify your temporary_fixtures_directory for some reason, | |
# you should change tmp_dir below | |
Autotest.add_hook :updated do |at,*args| | |
filenames = args.collect{|arr|arr.first.first}.uniq | |
filenames.each do |filename| | |
if filename =~ /.(yml|csv)$/ | |
require 'tempfile' | |
tmp_dir = FileUtils.mkdir_p(File.join(Dir.tmpdir, "rails_fixtures")) | |
FileUtils.copy(filename,tmp_dir) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment