Guest User

Untitled

a guest
Jul 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. PLUGIN_PATH = "vendor/plugins/community_engine/"
  2.  
  3. Autotest.add_hook :initialize do |at|
  4. at.clear_exceptions
  5. at.clear_mappings
  6.  
  7. %w{.git .svn stories tmtags Rakefile Capfile README spec/spec.opts spec/rcov.opts vendor/gems autotest svn-commit .DS_Store }.each do |exception|
  8. at.add_exception(exception)
  9. end
  10.  
  11. at.add_exception %r%^\./(?:db|doc|log|public|script|tmp)%
  12. at.add_exception %r%^#{PLUGIN_PATH}(?:app|config|db|generators|lang|lib|plugins|public|sample_files|tasks)%
  13.  
  14. at.add_mapping %r%^test/(unit|integration|controllers|views|functional)/.*rb$% do |filename, _|
  15. [filename, File.join(PLUGIN_PATH, filename)]
  16. end
  17.  
  18. at.add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
  19. ["test/unit/#{m[1]}_test.rb", "#{PLUGIN_PATH}test/unit/#{m[1]}_test.rb"]
  20. end
  21.  
  22. at.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
  23. if m[1] == "application" then
  24. combine_paths(at, %r%^test/(controllers|views|functional)/.*_test\.rb$%)
  25. else
  26. ["test/functional/#{m[1]}_test.rb",
  27. "#{PLUGIN_PATH}test/functional/#{m[1]}_test.rb"]
  28. end
  29. end
  30.  
  31. at.add_mapping %r%^app/helpers/application_helper.rb% do
  32. combine_paths(at, %r%^test/(views|functional)/.*_test\.rb$%)
  33. end
  34.  
  35. at.add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m|
  36. if m[1] == "application" then
  37. combine_paths at, %r%^test/(views|functional)/.*_test\.rb$%
  38. else
  39. ["test/views/#{m[1]}_view_test.rb",
  40. "test/functional/#{m[1]}_controller_test.rb",
  41. "#{PLUGIN_PATH}test/views/#{m[1]}_view_test.rb",
  42. "#{PLUGIN_PATH}test/functional/#{m[1]}_controller_test.rb"]
  43. end
  44. end
  45.  
  46. at.add_mapping %r%^app/views/(.*)/% do |_, m|
  47. ["test/views/#{m[1]}_view_test.rb",
  48. "test/functional/#{m[1]}_controller_test.rb",
  49. "#{PLUGIN_PATH}test/views/#{m[1]}_view_test.rb",
  50. "#{PLUGIN_PATH}test/functional/#{m[1]}_controller_test.rb"]
  51. end
  52.  
  53. at.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
  54. if m[1] == "application" then
  55. combine_paths at, %r%^test/(controllers|views|functional)/.*_test\.rb$%
  56. else
  57. ["test/controllers/#{m[1]}_test.rb",
  58. "test/functional/#{m[1]}_test.rb",
  59. "#{PLUGIN_PATH}test/controllers/#{m[1]}_test.rb",
  60. "#{PLUGIN_PATH}test/functional/#{m[1]}_test.rb"]
  61. end
  62. end
  63.  
  64. at.add_mapping %r%^app/views/layouts/% do
  65. ["test/views/layouts_view_test.rb", "#{PLUGIN_PATH}test/views/layouts_view_test.rb"]
  66. end
  67.  
  68. at.add_mapping %r%^config/routes.rb$% do # FIX:
  69. combine_paths at, %r%^test/(controllers|views|functional)/.*_test\.rb$%
  70. end
  71.  
  72. at.add_mapping %r%^test/test_helper.rb|config/((boot|environment(s/test)?).rb|database.yml)% do
  73. combine_paths at, %r%^test/(unit|controllers|views|functional)/.*_test\.rb$%
  74. end
  75. end
  76.  
  77. def combine_paths(autotest_variable, regexp)
  78. results = []
  79. results << autotest_variable.files_matching(regexp)
  80. new_regexp = Regexp.new(regexp.to_s.gsub("^", "^#{PLUGIN_PATH}"))
  81. results << autotest_variable.files_matching(new_regexp)
  82. results.flatten
  83. end
Add Comment
Please, Sign In to add comment