# Override normal mappings to fit our Merb project. Adapted from Autotest's # Rails mapping. Autotest.add_hook :initialize do |at| at.add_exception %r%^\./(?:doc|log|public|tmp)% at.clear_mappings # Assumes that anything in the base lib directory is for models at.add_mapping %r%^lib\/.*\.rb$% do |filename, _| at.files_matching %r%^spec/models/#{File.basename(filename, '.rb')}_test.rb$% end # Anytime a fixture is changed, check specs for models, controllers, and views at.add_mapping %r%^spec/fixtures/(.*)s.yml% do |_, m| [ "spec/models/#{m[1]}_spec.rb", "spec/controllers/#{m[1]}_controller_spec.rb", "spec/views/#{m[1]}_view_spec.rb", ] end # Run a spec if it changes at.add_mapping %r%^spec/(models|controllers|views)/.*rb$% do |filename, _| filename end # If a model changes, run its spec at.add_mapping %r%^app/models/(.*)\.rb$% do |_, m| "spec/models/#{m[1]}_spec.rb" end # If the global helper changes, run specs for controllers and views at.add_mapping %r%^app/helpers/global_helper.rb% do at.files_matching %r%^spec/(views|controllers)/.*_spec\.rb$% end # If a helper changes, run specs for controllers and helpers at.add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m| if m[1] == "global" then at.files_matching %r%^spec/(views|controllers)/.*_spec\.rb$% else [ "spec/views/#{m[1]}_view_spec.rb", "spec/controllers/#{m[1]}_controller_spec.rb" ] end end # If a view changes, run specs for controllers and views at.add_mapping %r%^app/views/(.*)/% do |_, m| [ "spec/views/#{m[1]}_view_spec.rb", "spec/functional/#{m[1]}_controller_spec.rb" ] end # If the application controller changes, or the exception controller # changes, run all controller and view specs. If any other controller # changes, run its spec. at.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m| if %w[application exceptions].include?(m[1]) then at.files_matching %r%^spec/(controllers|views)/.*_spec\.rb$% else ["spec/controllers/#{m[1]}_spec.rb"] end end # Not really sure what this is for. at.add_mapping %r%^app/views/layouts/% do "spec/views/layouts_view_spec.rb" end # If the route changes, run all specs for controllers and views at.add_mapping %r%^config/router.rb$% do # FIX <-- message from original source at.files_matching %r%^spec/(controllers|views)/.*_spec\.rb$% end # Numerous other things at.add_mapping %r%^spec/spec_helper.rb|config/((init|rack|environment(s/test)?).rb|database.yml)% do at.files_matching %r%^spec/(models|controllers|views)/.*_spec\.rb$% end end